summaryrefslogtreecommitdiffstats
path: root/layouts/_default/list.html
diff options
context:
space:
mode:
Diffstat (limited to 'layouts/_default/list.html')
-rw-r--r--layouts/_default/list.html70
1 files changed, 70 insertions, 0 deletions
diff --git a/layouts/_default/list.html b/layouts/_default/list.html
new file mode 100644
index 0000000..8c1db86
--- /dev/null
+++ b/layouts/_default/list.html
@@ -0,0 +1,70 @@
+{{ define "main" }}
+<content>
+ {{ if .Site.Params.postSearch }}
+ <input
+ id="search-input"
+ type="text"
+ placeholder="Search..."
+ style="margin-top: 16px"
+ />
+ <script>
+ // 等待 DOM 完全加载后执行
+ document.addEventListener('DOMContentLoaded', function () {
+ // 缓存 DOM 元素
+ const searchInput = document.getElementById('search-input');
+ const posts = document.querySelectorAll('.blog-posts li');
+ const years = document.querySelectorAll('.blog-posts h3');
+
+ // 更新搜索结果
+ function updateSearchResults(searchTerm) {
+ let visiblePosts = 0;
+ const displayedYears = new Set();
+ posts.forEach(function (post) {
+ const title = post.querySelector('a').textContent.toLowerCase();
+ const year = post.querySelector('time').getAttribute('datetime').split('-')[0];
+ if (title.includes(searchTerm)) {
+ post.style.display = '';
+ visiblePosts++;
+ displayedYears.add(year);
+ } else {
+ post.style.display = 'none';
+ }
+ });
+
+ {{ if .Site.Params.groupByYear }}
+ years.forEach(function (y) {
+ const year = y.textContent;
+ y.style.display = displayedYears.has(year) ? '' : 'none';
+ });
+ {{ end }}
+ }
+
+ searchInput.addEventListener('input', function () {
+ updateSearchResults(this.value.toLowerCase().trim());
+ });
+ });
+ </script>
+ {{ end }}
+ <ul class="blog-posts">
+ {{ $currentYear := 0 }} {{ range .Pages }} {{ if and (not .Params.hidden)
+ (not (in .Params.categories "往昔")) }}
+
+ <li>
+ <span
+ class="{{ if .Site.Params.groupByYear }} grouped {{ else }} ungrouped {{ end }}"
+ >
+ <i>
+ <time datetime='{{ .Date.Format "2006-01-02" }}' pubdate>
+ {{ .Date.Format (default "2006-01-02" .Site.Params.dateFormat) }}
+ </time>
+ </i>
+ </span>
+ <a href="{{ .Permalink }}">{{ .Title }}</a>
+ </li>
+
+ {{ end }} {{ else }}
+ <li>No posts yet</li>
+ {{ end }}
+ </ul>
+</content>
+{{ end }}