Skip to content

Commit

Permalink
feat: add the post.readMoreFromContent parameter
Browse files Browse the repository at this point in the history
Read more from content after clicking the read more button if enabled
  • Loading branch information
razonyang committed Sep 7, 2022
1 parent 13a9124 commit 5b6ee76
Show file tree
Hide file tree
Showing 8 changed files with 19 additions and 7 deletions.
3 changes: 3 additions & 0 deletions exampleSite/config/_default/params.toml
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,9 @@ viewer = true # Image Viewer
imageTitleAsCaption = true
# panel = false # Disable the post panel.
# nav = false # Disable post navigations.
# The page position after clicking the read more button, read more from content if true. Default to the beginning of page.
# It supports only of the manual summaries spliting via <!--more-->.
# readMoreFromContent = true

[archive]
# basePath = "/archiv" # The base path of archive pages.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ The site parameters are located in `config/_default/params.toml` by default.
| `post.imageTitleAsCaption` | Boolean | `false` | Use image title as caption.
| `post.panel` | Boolean | `true` | Turn on/off the post panel.
| `post.nav` | Boolean | `true` | Turn on/off the navigations.
| `post.readMoreFromContent` | Boolean | `false` | The page position after clicking the read more button, read more from content if true. Default to the beginning of page. It supports only of the manual summaries spliting via `<!--more-->`.
| `viewer` | Boolean | true | [Image Viewer]({{< ref "docs/image-viewer" >}})
| `pwa` | Object | - | [Progressive Web Apps]({{< ref "/docs/pwa" >}})
| **Sidebar**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ authors = ["RazonYang"]
| `post.imageTitleAsCaption` | Boolean | `false` | 将图片标题作为 caption。
| `post.panel` | Boolean | `true` | 是否显示 post panel。
| `post.nav` | Boolean | `true` | 是否顯示上一篇和下一篇。
| `post.readMoreFromContent` | Boolean | `false` | The page position after clicking the read more button, read more from content if true. Default to the beginning of page. It supports only of the manual summaries spliting via `<!--more-->`.
| `viewer` | Boolean | true | [图片查看器]({{< ref "docs/image-viewer" >}})
| `pwa` | Object | - | [渐进式 web 应用]({{< ref "/docs/pwa" >}})
| **Sidebar**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ authors = ["RazonYang"]
| `post.imageTitleAsCaption` | Boolean | `false` | 将图片标题作为 caption。
| `post.panel` | Boolean | `true` | 是否顯示 post panel。
| `post.nav` | Boolean | `true` | 是否顯示上一篇和下一篇。
| `post.readMoreFromContent` | Boolean | `false` | The page position after clicking the read more button, read more from content if true. Default to the beginning of page. It supports only of the manual summaries spliting via `<!--more-->`.
| `viewer` | Boolean | true | [圖片查看器]({{< ref "docs/image-viewer" >}})
| `pwa` | Object | - | [漸進式 web 應用]({{< ref "/docs/pwa" >}})
| **Sidebar**
Expand Down
4 changes: 1 addition & 3 deletions layouts/partials/docs/post.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,7 @@ <h1 class="card-title post-title my-2">{{ partial "helpers/title" . }}</h1>
{{- partial "post/featured-image" . -}}
{{- partial "hooks/content-begin" . -}}
{{- partial "post/toc-wrapper" . -}}
<div class="post-content mb-3" data-bs-spy="scroll" data-bs-target="#TableOfContents" tabindex="0">
{{- .Content -}}
</div>
{{- partial "post/content" . -}}
{{- partial "post/reward" . -}}
{{- partial "hooks/content-end" . -}}
</div>
Expand Down
4 changes: 1 addition & 3 deletions layouts/partials/post.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,7 @@ <h1 class="card-title post-title my-2">{{ partial "helpers/title" . }}</h1>
{{- partial "post/toc-wrapper" . -}}
{{- end -}}
{{- partial "post/share" . -}}
<div class="post-content mb-3" data-bs-spy="scroll" data-bs-target="#TableOfContents" tabindex="0">
{{- .Content -}}
</div>
{{- partial "post/content" . -}}
{{- partial "post/reward" . -}}
{{- partial "hooks/content-end" . -}}
</div>
Expand Down
8 changes: 8 additions & 0 deletions layouts/partials/post/content.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<div class="post-content mb-3" data-bs-spy="scroll" data-bs-target="#TableOfContents" tabindex="0">
{{- if default false $.Site.Params.post.readMoreFromContent }}
{{- with .Summary }}<div id="post-summary">{{ . }}</div>{{ end }}
<div id="post-content-body">{{- strings.TrimPrefix .Summary .Content | safeHTML -}}</div>
{{- else }}
<div id="post-content-body">{{ .Content }}</div>
{{- end }}
</div>
4 changes: 3 additions & 1 deletion layouts/partials/post/excerpt.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
{{- $key := $.Site.Params.post.excerpt }}
{{- $useDescription := and (eq $key "description") .Description }}
{{- $readMoreButton := printf "<div><a class=\"btn btn-sm btn-outline-primary btn-read-more\" href=\"%s\">%s</a></div>" .Permalink (i18n "read_more") | safeHTML }}
{{- $anchor := "" }}
{{- if default false $.Site.Params.post.readMoreFromContent }}{{ $anchor = "#post-content-body" }}{{ end }}
{{- $readMoreButton := printf "<div><a class=\"btn btn-sm btn-outline-primary btn-read-more\" href=\"%s%s\">%s</a></div>" .Permalink $anchor (i18n "read_more") | safeHTML }}
{{- $content := "" }}
{{- $readMore := true }}
{{- if $useDescription }}
Expand Down

0 comments on commit 5b6ee76

Please sign in to comment.