forked from go-sonic/default-theme-anatole
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjournals.tmpl
156 lines (142 loc) · 8.33 KB
/
journals.tmpl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
{{- define "caicai_anatole/journals" -}}
<!DOCTYPE html>
<html lang="zh">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
<title>日志 {{.blog_title}}</title>
<meta name="apple-mobile-web-app-capable" content="yes"/>
<meta name="apple-mobile-web-app-status-bar-style" content="black"/>
<meta name="format-detection" content="telephone=no"/>
<meta name="renderer" content="webkit"/>
<meta name="author" content="{{ .user.Nickname}}"/>
<meta name="keywords" content="{{ .meta_keywords}}"/>
<meta name="description" content="{{ .meta_description}}"/>
<link rel="alternate" type="application/rss+xml" title="atom 1.0" href="{{ .atom_url}}"/>
{{template "global.head" .}}
{{template "caicai_anatole/module/styles" .}}
{{template "caicai_anatole/module/highlightjs/libs-import" . }}
{{template "caicai_anatole/module/lightgallery/libs-import" .}}
{{template "caicai_anatole/module/katex/libs-import" .}}
<script src="https://cdn.jsdelivr.net/npm/vue@2"></script>
<script src="{{or .options.comment_internal_plugin_js "https://cdn.jsdelivr.net/npm/halo-comment@latest/dist/halo-comment.min.js"}}"></script>
</head>
<body x-data="{ postSearchVisible: false }">
{{template "caicai_anatole/module/sidebar" .}}
<div class="main">
{{template "caicai_anatole/module/page-top" .}}
<div class="content">
{{template "caicai_anatole/module/page-heading" (dict "title" "日志" "subtitle" (printf "%d 篇" .journals.Total)) }}
<div class="post-page">
<div class="post animated fadeInDown">
<ul role="list" class="divide-y divide-gray-100" x-data="journals">
{{ range $journal :=.journals.Content}}
<li class="py-5 flex items-start gap-2" x-data="{comment:false}">
<img class="h-12 w-12 rounded-full" src="{{$.user.Avatar}}" alt="{{$.user.Nickname}}">
<div class="ml-5 flex-1">
<div class="markdown-body !text-sm !text-gray-500">
{{noescape $journal.Content}}
</div>
<div class="flex items-center gap-4 mt-3">
<div class="journal-likes inline-flex items-center cursor-pointer text-gray-400 hover:text-red-700 text-sm transition-all"
x-bind:class="{'text-red-700': liked({{$journal.ID}})}"
x-on:click="handleLike({{$journal.ID}})">
<i x-show="liked({{$journal.ID}})" class="iconify w-3.5 h-3.5"
data-icon="mdi:heart"></i>
<i x-show="!liked({{$journal.ID}})" class="iconify w-3.5 h-3.5"
data-icon="mdi:heart-outline"></i>
<span class="ml-1" data-journal-id-likes="{{$journal.ID}}">
{{$journal.Likes}}
</span>
</div>
<div class="inline-flex items-center cursor-pointer text-gray-400 hover:text-black text-sm transition-all"
x-on:click="comment = !comment">
<i class="iconify w-3.5 h-3.5" data-icon="mdi:comment-outline"></i>
<span class="ml-1">
{{$journal.CommentCount}}
</span>
</div>
<div class="sm:hidden inline-flex items-center cursor-pointer text-gray-400 hover:text-black text-sm transition-all">
<i class="iconify w-3.5 h-3.5" data-icon="mdi:calendar-month-outline"></i>
<span class="ml-1">{{unix_milli_time_format "2006-01-02 03:04" $journal.CreateTime}}</span>
</div>
</div>
<template x-if="comment">
<div class="mt-2">
{{template "global.comment" (dict "target" $journal "type" "journal" "options" $.options)}}
</div>
</template>
</div>
<div class="hidden sm:flex">
<time class="text-gray-400 text-sm">{{unix_milli_time_format "2006-01-02 03:04" $journal.CreateTime}}</time>
</div>
</li>
{{end}}
</ul>
</div>
</div>
{{if (gt .journals.Pages 1)}}
{{$pagination:=(journalsPagination .journals.PageNum .journals.Pages 3)}}
<div class="pagination flex justify-between items-center">
{{if $pagination.HasPrev}}
<a class="btn" role="navigation" href="{{$pagination.PrevPageFullPath}}">上一页</a>
{{end}}
<span class="text-sm">{{add .journals.PageNum 1}}/{{ .journals.Pages}}</span>
{{if $pagination.HasNext}}
<a class="btn" role="navigation" href="{{$pagination.NextPageFullPath}}">下一页</a>
{{end}}
</div>
{{end}}
</div>
</div>
{{template "caicai_anatole/module/highlightjs/scripts" .}}
<script type="text/javascript">
const markdownBodyNodes = document.getElementsByClassName('markdown-body');
if (markdownBodyNodes) {
for (let i = 0; i < markdownBodyNodes.length; i++) {
const markdownBodyNode = markdownBodyNodes[i];
const imageNodes = markdownBodyNode.querySelectorAll("img")
imageNodes.forEach(function (node) {
if (node) {
node.dataset.src = node.src;
}
})
lightGallery(markdownBodyNode, {
selector: 'img',
})
}
}
document.addEventListener("alpine:init", () => {
Alpine.data("journals", () => ({
likedIds: [],
init() {
this.likedIds = JSON.parse(localStorage.getItem("anatole.likes.journal.ids") || "[]");
},
liked(id) {
return this.likedIds.includes(id);
},
async handleLike(journalId) {
if (this.liked(journalId)) {
return
}
const xhr = new XMLHttpRequest();
xhr.open('POST', "/api/content/journals/" + journalId + "/likes");
xhr.onload = () => {
this.likedIds = [...this.likedIds, journalId];
localStorage.setItem('anatole.likes.journal.ids', JSON.stringify(this.likedIds));
const likesNode = document.querySelector("[data-journal-id-likes=\"" + journalId + "\"]");
const likes = parseInt(likesNode.innerText);
likesNode.innerText = likes + 1;
}
xhr.onerror = function () {
alert("网络请求失败,请稍后再试");
};
xhr.send();
}
}))
})
</script>
{{template "caicai_anatole/module/post-search-modal" .}}
</body>
</html>
{{end}}