From 83f509dd79c381a8bb1254a5de14568c61bb92e2 Mon Sep 17 00:00:00 2001 From: Eltrac Date: Thu, 27 Mar 2025 13:10:06 +0800 Subject: feat: add library section --- assets/css/components/_library.scss | 62 ++++++++++++++++++++++++++++++ assets/css/index.scss | 1 + content/library/_index.md | 3 ++ layouts/_default/single.html | 4 +- layouts/library/section.html | 14 +++++++ layouts/library/single.html | 25 ++++++++++++ layouts/partials/components/comment.html | 66 ++++++++++++++++---------------- layouts/shortcodes/bookcard.html | 27 +++++++++++++ 8 files changed, 167 insertions(+), 35 deletions(-) create mode 100644 assets/css/components/_library.scss create mode 100644 content/library/_index.md create mode 100644 layouts/library/section.html create mode 100644 layouts/library/single.html create mode 100644 layouts/shortcodes/bookcard.html diff --git a/assets/css/components/_library.scss b/assets/css/components/_library.scss new file mode 100644 index 00000000..3b913214 --- /dev/null +++ b/assets/css/components/_library.scss @@ -0,0 +1,62 @@ +#library { + #library-content { + display: flex; + align-items: center; + gap: 1rem; + margin: 1rem 0; + + .book { + width: 25%; + } + } +} + +.book-body { + line-height: 2; + + hr { + clear: both + } + + .book-title { + margin: 0.1rem 0; + a { + color: var(--text-color); + text-decoration: none; + } + } + + .rating { + font-size: 0.9rem; + color: var(--secondary-text-color); + } +} + +.book-cover { + display: block; + img { + display: block; + width: 100%; + } + + #library & { + border: 0.2rem solid #fff; + box-shadow: 0 0.1rem 0.75rem rgba(0,0,0,0.2); + + transition: transform 0.3s ease; + transform: rotate(3deg); + &:hover { + transform: rotate(0) translateY(-0.5rem) scale(1.1) + } + } + + #book-page &, #post-content & { + margin: 0; + @media screen and (min-width: 768px) { + display: inxwline-block; + float: left; + width: 12rem; + margin: 0 2rem 1.2rem 0; + } + } +} diff --git a/assets/css/index.scss b/assets/css/index.scss index 44b1229b..7129ae86 100644 --- a/assets/css/index.scss +++ b/assets/css/index.scss @@ -8,6 +8,7 @@ @import 'components/comment'; @import 'components/shortcodes'; @import 'components/card'; +@import 'components/library'; @import 'components/footer'; @import 'components/animation'; @import 'components/utility'; diff --git a/content/library/_index.md b/content/library/_index.md new file mode 100644 index 00000000..5cd6321a --- /dev/null +++ b/content/library/_index.md @@ -0,0 +1,3 @@ +--- +title: 图书馆 +--- diff --git a/layouts/_default/single.html b/layouts/_default/single.html index 13c56ada..f22f8d6b 100644 --- a/layouts/_default/single.html +++ b/layouts/_default/single.html @@ -57,7 +57,9 @@ {{ end }} - {{ partial "components/comment.html" . }} + {{ if in .Site.Params.mainSections .Type }} + {{ partial "components/comment.html" . }} + {{ end }} - -{{ end }} +
+ {{ with .Params.comments }} +
+

{{ T "postPage.staticCommentsSectionHeader" }}

+ {{ range . }} +
+
+ {{ .name }} + {{ .date }} +
+
+ {{ .content | safeHTML }} +
+ +
+ {{ end }} +
+ {{ end }} +
+

+ {{ T "postPage.commentNotLoaded" }} +

+
+ {{ if eq .Site.Language.Lang "zh" }} +

你也可以加入本站的 Telegram 群组参与讨论

+ {{ end }} + +
diff --git a/layouts/shortcodes/bookcard.html b/layouts/shortcodes/bookcard.html new file mode 100644 index 00000000..fd7f81df --- /dev/null +++ b/layouts/shortcodes/bookcard.html @@ -0,0 +1,27 @@ +{{- $book := .Site.GetPage (printf "library/%s" (.Get 0)) -}} + +{{- if $book }} +
+
+ +
+

+ {{ $book.Title }} +

+ + {{- $rating := $book.Params.rating -}} + {{- $fullStars := math.Floor $rating -}} +
+ 评分: + {{- range seq $fullStars }} + ★ + {{- end -}} +
+ +
+ {{ $book.Content }} +
+
+{{- else }} +

⚠️ 无法找到书评: {{ .Get 0 }}

+{{- end }} -- cgit v1.2.3