Browse Source

Add anchor points to post list page

Track3 6 years ago
parent
commit
a5ddfd159e
3 changed files with 13 additions and 2 deletions
  1. 7 1
      assets/js/main.js
  2. 5 0
      assets/scss/style.scss
  3. 1 1
      layouts/_default/list.html

+ 7 - 1
assets/js/main.js

@@ -118,7 +118,7 @@ let comments = document.getElementById('comments');
 let commentsLoader = document.getElementById('comments-loader');
 
 const avJsUrl = '//cdn.jsdelivr.net/npm/leancloud-storage@3.11.1/dist/av-min.js';
-const valineJsUrl = 'https://cdn.jsdelivr.net/npm/valine@1.3.4/dist/Valine.min.js';
+const valineJsUrl = 'https://cdn.jsdelivr.net/npm/valine@1.3.6/dist/Valine.min.js';
 
 const loadComments = () => {
   loadScript(avJsUrl).then(() => {
@@ -152,6 +152,12 @@ if (header !== null) {
     commentsLoaded = true;
   }
 
+  document.querySelectorAll('.post-year').forEach((ele) => {
+    ele.addEventListener('click', () => {
+      window.location.hash = '#' + ele.id;
+    });
+  });
+
   window.addEventListener('scroll', throttle(() => {
     autoHideHeader();
     if (mobileMenuVisible == true) {

+ 5 - 0
assets/scss/style.scss

@@ -363,6 +363,11 @@ p.img-404 {
     margin-right: 1.8em;
     font-size: 1.6em;
     @include dimmed;
+
+    &:hover {
+      text-decoration: underline;
+      cursor: pointer;
+    }
   }
 
   .posts-list {

+ 1 - 1
layouts/_default/list.html

@@ -12,7 +12,7 @@
 		{{- end }}
 		{{- range .Data.Pages.GroupByDate "2006" }}
 		<div class="posts-group">
-			<div class="post-year">{{ .Key }}</div>
+			<div class="post-year" id="{{ .Key }}">{{ .Key }}</div>
 			<ul class="posts-list">
 				{{- range .Pages }}
 				<li class="post-item">