add post-description post-nav and related-posts

This commit is contained in:
geekifan
2025-04-22 13:46:12 +08:00
parent d24c640ab7
commit b0c293efcd
3 changed files with 148 additions and 0 deletions

View File

@ -0,0 +1,21 @@
{{- /* Get post description or generate it from the post content */ -}}
{{- $max_length := default 200 .Params.max_length -}}
{{- $description := "" -}}
{{- if .Description -}}
{{- $description = .Description -}}
{{- else if .Params.description -}}
{{- $description = .Params.description -}}
{{- else -}}
{{- /* Remove the line number of the code snippet */ -}}
{{- $content := .Content -}}
{{- if findRE `<td class="rouge-gutter gl"><pre class="lineno">` $content -}}
{{- $content = replace $content `<td class="rouge-gutter gl"><pre class="lineno">` `<!-- <td class="rouge-gutter gl"><pre class="lineno">` -}}
{{- $content = replace $content `</td><td class="rouge-code">` `</td> --><td class="rouge-code">` -}}
{{- end -}}
{{- $description = $content | markdownify | plainify | replaceRE `\s+` ` ` -}}
{{- end -}}
{{- (trim $description " ") | truncate $max_length | safeHTML -}}