mirror of
https://github.com/tiennm99/blog.git
synced 2026-10-11 03:13:10 +00:00
feat: related posts discovery with configurable algorithm
Add related posts sidebar component, configure related: block in Hugo config, enable readers to discover similar content.
This commit is contained in:
1 parent
dab430c133
commit
a665c3aad8
3 files changed
+60
No files matched your search
@@ -29,6 +29,18 @@ markup:
|
||||
startLevel: 2
|
||||
endLevel: 4
|
||||
|
||||
related:
|
||||
threshold: 80
|
||||
includeNewer: true
|
||||
toLower: true
|
||||
indices:
|
||||
- name: tags
|
||||
weight: 100
|
||||
- name: categories
|
||||
weight: 60
|
||||
- name: date
|
||||
weight: 10
|
||||
|
||||
params:
|
||||
description: Example site for the tsuki Hugo theme.
|
||||
|
||||
|
||||
@@ -1,6 +1,21 @@
|
||||
languageCode: vi
|
||||
defaultContentLanguage: vi
|
||||
|
||||
module:
|
||||
mounts:
|
||||
- source: archetypes
|
||||
target: archetypes
|
||||
- source: assets
|
||||
target: assets
|
||||
- source: data
|
||||
target: data
|
||||
- source: i18n
|
||||
target: i18n
|
||||
- source: layouts
|
||||
target: layouts
|
||||
- source: static
|
||||
target: static
|
||||
|
||||
pagination:
|
||||
pagerSize: 10
|
||||
path: page
|
||||
@@ -25,6 +40,18 @@ markup:
|
||||
startLevel: 2
|
||||
endLevel: 4
|
||||
|
||||
related:
|
||||
threshold: 80
|
||||
includeNewer: true
|
||||
toLower: true
|
||||
indices:
|
||||
- name: tags
|
||||
weight: 100
|
||||
- name: categories
|
||||
weight: 60
|
||||
- name: date
|
||||
weight: 10
|
||||
|
||||
params:
|
||||
search:
|
||||
enable: true
|
||||
@@ -34,3 +61,4 @@ params:
|
||||
toc:
|
||||
enable: true
|
||||
minWordCount: 400
|
||||
relatedPostsCount: 3
|
||||
@@ -0,0 +1,20 @@
|
||||
{{- /*
|
||||
Related posts for single pages. Uses Hugo's built-in `Related` keyword index.
|
||||
Requires `related:` config in site hugo.yaml — see docs/config.md.
|
||||
Silently no-op when no relations are found.
|
||||
*/ -}}
|
||||
{{- $count := site.Params.relatedPostsCount | default 3 -}}
|
||||
{{- $related := slice -}}
|
||||
{{- if gt $count 0 -}}
|
||||
{{- $related = first $count (site.RegularPages.Related .) -}}
|
||||
{{- end -}}
|
||||
{{- with $related -}}
|
||||
<aside class="related-posts" aria-labelledby="related-heading">
|
||||
<h2 id="related-heading" class="related-heading">{{ i18n "relatedPosts" | default "Bài viết liên quan" }}</h2>
|
||||
<ul class="related-list">
|
||||
{{- range . }}
|
||||
<li>{{ partial "post-card.html" . }}</li>
|
||||
{{- end }}
|
||||
</ul>
|
||||
</aside>
|
||||
{{- end -}}
|
||||
Reference in new issue
Block a user