Skip to content

Commit

Permalink
Add pinning featured posts option
Browse files Browse the repository at this point in the history
Signed-off-by: Luke Hong <luke0724@hotmail.com>
  • Loading branch information
LukeHong committed Jul 27, 2022
1 parent 6d90564 commit e1d52af
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 4 deletions.
12 changes: 10 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,8 @@ These options set global values that some pages or all pages in the site use by
| comments | boolean | yes |
| numberOfRecentPosts | integer | no |
| numberOfFeaturedPosts | integer | no |
| pinFeatured | boolean | no |
| numberOfPinnedPosts | integer | no |
| dateFormat | string | no |
| enableMathNotation | boolean | yes |
| customFonts | boolean | no |
Expand Down Expand Up @@ -798,13 +800,13 @@ You can override these setting from each post individually. For example, you may

If you wish use [Utterances](https://github.com/utterance/utterances) comments on your site, you'll need to perform the following:

* Ensure you have a GitHub public repository, which you've granted permissions to the [Utterances GitHub App](https://github.com/apps/utterances).
* Ensure you have a GitHub public repository, which you've granted permissions to the [Utterances GitHub App](https://github.com/apps/utterances).
* Comment out the line for `disqusShortname = ""` in the `/config/_default/config.toml` file.
* Set `comments = true` in the `/config/_default/params.toml` file.
* Configure the utterances parameters in the `/config/_default/params.toml` file.

Utterances is loaded in the `comments.html` partial by referring to the `utterances.html` partial. Since `single.html` layout loads comments if comments are enabled, you must ensure *both* the `comments` and `utterances` parameters are configured.




Expand Down Expand Up @@ -925,3 +927,9 @@ __Search Scope__
- Searching outside a section will search the entire site.

For example, with the above setup, searching from the homepage will produce results from the entire site.

### Pinning Featured Posts

This allows you to show the featured posts at the top of the post list.

Using the site configuration option `pinFeatured` to enable/disable it, and the option `numberOfPinnedPosts` to control how many posts to be pinned.
10 changes: 8 additions & 2 deletions exampleSite/config/_default/params.toml
Original file line number Diff line number Diff line change
Expand Up @@ -105,12 +105,18 @@ languageMenuName = "🌐"
# utterancesTheme = "github-light" # Default: github-dark
# utterancesIssueTerm = "pathname" # Default: pathname

# Maximum number of recent posts.
# Maximum number of recent posts. (default: 8)
# numberOfRecentPosts = 8

# Maximum number of featured posts.
# Maximum number of featured posts. (default: 8)
# numberOfFeaturedPosts = 8

# Pin featured posts in list.
# pinFeatured = true

# Maximum number of pinned featured posts. (default: 8)
# numberOfPinnedPosts = 8

# Date format. Checkout https://gohugo.io/functions/format/#hugo-date-and-time-templating-reference for details.
# dateFormat = "2006-01-02" # Default to "Jan 2, 2006".
# customFonts = false # toggle to true if you want to use custom fonts only.
Expand Down
7 changes: 7 additions & 0 deletions layouts/partials/archive.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,13 @@
{{ if .IsHome }}
{{ $pages = where site.RegularPages "Type" "in" site.Params.mainSections }}
{{ end }}

{{ if eq site.Params.pinFeatured true }}
{{ $featured := default 8 site.Params.numberOfPinnedPosts }}
{{ $featuredPosts := first $featured (where $pages "Params.featured" true)}}
{{ $normalPosts := $pages | symdiff $featuredPosts }}
{{ $pages = $featuredPosts | append $normalPosts }}
{{ end }}
<div class="grid-inverse wrap content">
<div>
<ul class="posts" id="posts">
Expand Down

0 comments on commit e1d52af

Please sign in to comment.