From eb6c6292f75ff276d925aa94a98a564b3ce483e5 Mon Sep 17 00:00:00 2001 From: Razon Yang Date: Wed, 5 Jun 2024 00:10:42 +0800 Subject: [PATCH] perf: cache page summaries (#873) --- .../partials/hb/modules/blog/post/card.html | 21 ++----------------- .../hb/modules/blog/post/summary.html | 19 +++++++++++++++++ 2 files changed, 21 insertions(+), 19 deletions(-) create mode 100644 layouts/partials/hb/modules/blog/post/summary.html diff --git a/layouts/partials/hb/modules/blog/post/card.html b/layouts/partials/hb/modules/blog/post/card.html index c61f8d56..f1286b4b 100644 --- a/layouts/partials/hb/modules/blog/post/card.html +++ b/layouts/partials/hb/modules/blog/post/card.html @@ -65,25 +65,8 @@ {{- end }} {{- if $showSummary }} - {{- $summary := $page.Summary }} - {{- $truncated := $page.Truncated }} - {{- with $page.Description }} - {{- $summary = . }} - {{- $truncated := true }} - {{- end }} -
- {{- $summary -}} -
- {{- if and $readMore $truncated }} -
- - {{- i18n "read_more_about" $page.Title -}} - -
- {{- end }} + {{- $summaryCtx := dict "Page" $page "ReadMore" $readMore "External" $external "URL" $url }} + {{ partialCached "hb/modules/blog/post/summary" $summaryCtx $summaryCtx }} {{- end }} {{- if and $thumbnail (ne $thumbnailPos "top") }} diff --git a/layouts/partials/hb/modules/blog/post/summary.html b/layouts/partials/hb/modules/blog/post/summary.html new file mode 100644 index 00000000..95bdcd7c --- /dev/null +++ b/layouts/partials/hb/modules/blog/post/summary.html @@ -0,0 +1,19 @@ +{{- $summary := .Page.Summary }} +{{- $truncated := .Page.Truncated }} +{{- with .Page.Description }} + {{- $summary = . }} + {{- $truncated := true }} +{{- end }} +
+ {{- $summary -}} +
+{{- if and .ReadMore $truncated }} +
+ + {{- i18n "read_more_about" .Page.Title -}} + +
+{{- end }}