Skip to content

Commit 433d346

Browse files
authored
Merge pull request #1 from tyza66/feat/giscus-comments
feat: 增加评论区
2 parents dccd57a + f7b25ec commit 433d346

3 files changed

Lines changed: 143 additions & 0 deletions

File tree

hugo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ theme = 'PaperMod'
55

66
[params]
77
author = 'tyza66'
8+
comments = true
89

910
[params.assets]
1011
favicon = "/favicon.ico"

layouts/_default/list.html

Lines changed: 125 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
1+
{{- define "main" }}
2+
3+
{{- if (and site.Params.profileMode.enabled .IsHome) }}
4+
{{- partial "index_profile.html" . }}
5+
{{- else }} {{/* if not profileMode */}}
6+
7+
{{- if not .IsHome | and .Title }}
8+
<header class="page-header">
9+
{{- partial "breadcrumbs.html" . }}
10+
<h1>
11+
{{ .Title }}
12+
{{- if and (or (eq .Kind `term`) (eq .Kind `section`)) (.Param "ShowRssButtonInSectionTermList") }}
13+
{{- with .OutputFormats.Get "rss" }}
14+
<a href="{{ .RelPermalink }}" title="RSS" aria-label="RSS">
15+
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"
16+
stroke-linecap="round" stroke-linejoin="round" height="23">
17+
<path d="M4 11a9 9 0 0 1 9 9" />
18+
<path d="M4 4a16 16 0 0 1 16 16" />
19+
<circle cx="5" cy="19" r="1" />
20+
</svg>
21+
</a>
22+
{{- end }}
23+
{{- end }}
24+
</h1>
25+
{{- if .Description }}
26+
<div class="post-description">
27+
{{ .Description | markdownify }}
28+
</div>
29+
{{- end }}
30+
</header>
31+
{{- end }}
32+
33+
{{- if .Content }}
34+
<div class="post-content">
35+
{{- if not (.Param "disableAnchoredHeadings") }}
36+
{{- partial "anchored_headings.html" .Content -}}
37+
{{- else }}{{ .Content }}{{ end }}
38+
</div>
39+
{{- end }}
40+
41+
{{- $pages := union .RegularPages .Sections }}
42+
43+
{{- if .IsHome }}
44+
{{- $pages = where site.RegularPages "Type" "in" site.Params.mainSections }}
45+
{{- $pages = where $pages "Params.hiddenInHomeList" "!=" "true" }}
46+
{{- end }}
47+
48+
{{- $paginator := .Paginate $pages }}
49+
50+
{{- if and .IsHome site.Params.homeInfoParams (eq $paginator.PageNumber 1) }}
51+
{{- partial "home_info.html" . }}
52+
{{- end }}
53+
54+
{{- $term := .Data.Term }}
55+
{{- range $index, $page := $paginator.Pages }}
56+
57+
{{- $class := "post-entry" }}
58+
59+
{{- $user_preferred := or site.Params.disableSpecial1stPost site.Params.homeInfoParams }}
60+
{{- if (and $.IsHome (eq $paginator.PageNumber 1) (eq $index 0) (not $user_preferred)) }}
61+
{{- $class = "first-entry" }}
62+
{{- else if $term }}
63+
{{- $class = "post-entry tag-entry" }}
64+
{{- end }}
65+
66+
<article class="{{ $class }}">
67+
{{- $isHidden := (.Param "cover.hiddenInList") | default (.Param "cover.hidden") | default false }}
68+
{{- partial "cover.html" (dict "cxt" . "IsSingle" false "isHidden" $isHidden) }}
69+
<header class="entry-header">
70+
<h2 class="entry-hint-parent">
71+
{{- .Title }}
72+
{{- if .Draft }}
73+
<span class="entry-hint" title="Draft">
74+
<svg xmlns="http://www.w3.org/2000/svg" height="20" viewBox="0 -960 960 960" fill="currentColor">
75+
<path
76+
d="M160-410v-60h300v60H160Zm0-165v-60h470v60H160Zm0-165v-60h470v60H160Zm360 580v-123l221-220q9-9 20-13t22-4q12 0 23 4.5t20 13.5l37 37q9 9 13 20t4 22q0 11-4.5 22.5T862.09-380L643-160H520Zm300-263-37-37 37 37ZM580-220h38l121-122-18-19-19-18-122 121v38Zm141-141-19-18 37 37-18-19Z" />
77+
</svg>
78+
</span>
79+
{{- end }}
80+
</h2>
81+
</header>
82+
{{- if (ne (.Param "hideSummary") true) }}
83+
<div class="entry-content">
84+
<p>{{ .Summary | plainify | htmlUnescape }}{{ if .Truncated }}...{{ end }}</p>
85+
</div>
86+
{{- end }}
87+
{{- if not (.Param "hideMeta") }}
88+
<footer class="entry-footer">
89+
{{- partial "post_meta.html" . -}}
90+
</footer>
91+
{{- end }}
92+
<a class="entry-link" aria-label="post link to {{ .Title | plainify }}" href="{{ .Permalink }}"></a>
93+
</article>
94+
{{- end }}
95+
96+
{{- if gt $paginator.TotalPages 1 }}
97+
<footer class="page-footer">
98+
<nav class="pagination">
99+
{{- if $paginator.HasPrev }}
100+
<a class="prev" href="{{ $paginator.Prev.URL | absURL }}">
101+
«&nbsp;{{ i18n "prev_page" }}&nbsp;
102+
{{- if (.Param "ShowPageNums") }}
103+
{{- sub $paginator.PageNumber 1 }}/{{ $paginator.TotalPages }}
104+
{{- end }}
105+
</a>
106+
{{- end }}
107+
{{- if $paginator.HasNext }}
108+
<a class="next" href="{{ $paginator.Next.URL | absURL }}">
109+
{{- i18n "next_page" }}&nbsp;
110+
{{- if (.Param "ShowPageNums") }}
111+
{{- add 1 $paginator.PageNumber }}/{{ $paginator.TotalPages }}
112+
{{- end }}&nbsp;»
113+
</a>
114+
{{- end }}
115+
</nav>
116+
</footer>
117+
{{- end }}
118+
119+
{{- if and (not .IsHome) (ne .Section "about") }}
120+
{{- partial "comments.html" . }}
121+
{{- end }}
122+
123+
{{- end }}{{/* end profileMode */}}
124+
125+
{{- end }}{{- /* end main */ -}}

layouts/partials/comments.html

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<div id="giscus-comments" style="margin-top: 2rem;">
2+
<script src="https://giscus.app/client.js"
3+
data-repo="tyza66/Blog"
4+
data-repo-id="R_kgDOREy3Cw"
5+
data-category="General"
6+
data-category-id="DIC_kwDOREy3C84DC7fE"
7+
data-mapping="pathname"
8+
data-strict="0"
9+
data-reactions-enabled="1"
10+
data-emit-metadata="0"
11+
data-input-position="bottom"
12+
data-theme="preferred_color_scheme"
13+
data-lang="zh-CN"
14+
crossorigin="anonymous"
15+
async>
16+
</script>
17+
</div>

0 commit comments

Comments
 (0)