添加 gitalk 评论和 disqus 懒加载;添加文章目录导航

This commit is contained in:
ehlxr 2018-10-11 14:31:20 +08:00
parent b34ba759cc
commit 627b358901
6 changed files with 49 additions and 23 deletions

View File

@ -3,7 +3,7 @@
// ============================== // ==============================
// You can override the variables in _variables.scss to customize the style // You can override the variables in _variables.scss to customize the style
.comments-container { .post-comment {
position: relative; position: relative;
width: 100%; width: 100%;
max-width: 780px; max-width: 780px;

View File

@ -4,7 +4,7 @@
<header class="post-header"> <header class="post-header">
<h1 class="post-title" itemprop="name headline">{{ .Title }}</h1> <h1 class="post-title" itemprop="name headline">{{ .Title }}</h1>
<div class="post-meta"> <div class="post-meta">
Written by <a itemprop="name" href="{{.Site.BaseURL }}" rel="author">{{ if isset .Params "author" }}{{ .Params.author }}{{ else }}{{ .Site.Params.author }}{{ end }}</a> with ♥ Written by <a itemprop="name" href="{{.Site.BaseURL }}" rel="author">{{ if isset .Params "author" }}{{ .Params.author }}{{ else }}{{ .Site.Params.author }}{{ end }}</a> with ♥
<span class="post-time"> <span class="post-time">
on <time datetime={{.Date.Format (.Site.Params.dateFormatToUse | default "2006-01-02") }} itemprop="datePublished">{{ .Date.Format (.Site.Params.dateFormatToUse | default "January 2, 2006") }}</time> on <time datetime={{.Date.Format (.Site.Params.dateFormatToUse | default "2006-01-02") }} itemprop="datePublished">{{ .Date.Format (.Site.Params.dateFormatToUse | default "January 2, 2006") }}</time>
</span> </span>
@ -23,7 +23,7 @@
| |
<a href="#gitalk-container" itemprop="discussionUrl"> <a href="#gitalk-container" itemprop="discussionUrl">
<span class="post-comments-count gitalk-comment-count" itemprop="commentCount"></span> <span class="gitalk-comment-count" itemprop="commentCount"></span>
</a> </a>
{{ .Site.Params.gitalk.countSign }} {{ .Site.Params.gitalk.countSign }}
</div> </div>
@ -44,7 +44,7 @@
<img src="{{ printf "%s%s" $cdn_url $img }}" class="featured_image"> <img src="{{ printf "%s%s" $cdn_url $img }}" class="featured_image">
{{ end }} {{ end }}
<!-- end featured_image--> <!-- end featured_image-->
{{ $reAltIn := "<img src=\"([^\"]+)\" alt=\"([^\"]+)?\" />" }} {{ $reAltIn := "<img src=\"([^\"]+)\" alt=\"([^\"]+)?\" />" }}
{{ $reAltOut := ( printf "<figure><img src=\"/images/ring.svg\" data-sizes=\"auto\" data-src=\"%s$1\" alt=\"$2\" class=\"lazyload\"><figcaption class=\"image-caption\">$2</figcaption></figure>" $cdn_url ) }} {{ $reAltOut := ( printf "<figure><img src=\"/images/ring.svg\" data-sizes=\"auto\" data-src=\"%s$1\" alt=\"$2\" class=\"lazyload\"><figcaption class=\"image-caption\">$2</figcaption></figure>" $cdn_url ) }}
{{ $altContent := .Content | replaceRE $reAltIn $reAltOut | safeHTML }} {{ $altContent := .Content | replaceRE $reAltIn $reAltOut | safeHTML }}
@ -57,31 +57,31 @@
</div> </div>
<div class="post-copyright"> <div class="post-copyright">
{{ with .Site.Params.author }} {{ with .Site.Params.author }}
<p class="copyright-item"> <p class="copyright-item">
<span>Author:</span> <span>Author:</span>
<span>{{ . }} </span> <span>{{ . }} </span>
</p> </p>
{{ end }} {{ end }}
{{ with .Permalink }} {{ with .Permalink }}
<p class="copyright-item"> <p class="copyright-item">
<span>Link:</span> <span>Link:</span>
<a href={{ . }}>{{ . }}</span> <a href={{ . }}>{{ . }}</span>
</p> </p>
{{ end }} {{ end }}
{{ with .Site.Params.license }} {{ with .Site.Params.license }}
<p class="copyright-item lincese"> <p class="copyright-item lincese">
{{ . | safeHTML}} {{ . | safeHTML}}
</p> </p>
{{ end }} {{ end }}
</div> </div>
<div class="post-tags"> <div class="post-tags">
{{ with .Params.tags }} {{ with .Params.tags }}
<section> <section>
<i class="iconfont icon-tag"></i>Tag(s): <i class="iconfont icon-tag"></i>Tag(s):
{{ range . }} {{ range . }}
<span class="tag"><a href="{{ "tags/" | absURL }}{{ . | urlize }}/"> <span class="tag"><a href="{{ "tags/" | absURL }}{{ . | urlize }}/">
#{{.}}</a></span> #{{.}}</a></span>
@ -89,7 +89,7 @@
</section> </section>
{{ end }} {{ end }}
<section> <section>
<a href="javascript:window.history.back();">back</a></span> · <a href="javascript:window.history.back();">back</a></span> ·
<span><a href="{{ .Site.BaseURL }}">home</a></span> <span><a href="{{ .Site.BaseURL }}">home</a></span>
</section> </section>
</div> </div>
@ -97,14 +97,10 @@
<div class="post-nav"> <div class="post-nav">
{{ if .PrevInSection }} {{ if .PrevInSection }}
<a href="{{.PrevInSection.Permalink}}" class="prev" rel="prev" title="{{ .PrevInSection.Title}}"><i class="iconfont icon-left"></i>&nbsp;{{ .PrevInSection.Title}}</a> <a href="{{.PrevInSection.Permalink}}" class="prev" rel="prev" title="{{ .PrevInSection.Title}}"><i class="iconfont icon-left"></i>&nbsp;{{ .PrevInSection.Title}}</a>
{{ end }} {{ end }}
{{ if .NextInSection }} {{ if .NextInSection }}
<a href="{{.NextInSection.Permalink}}" class="next" rel="next" title="{{.NextInSection.Title}}">{{.NextInSection.Title}}&nbsp;<i class="iconfont icon-right"></i></a> <a href="{{.NextInSection.Permalink}}" class="next" rel="next" title="{{.NextInSection.Title}}">{{.NextInSection.Title}}&nbsp;<i class="iconfont icon-right"></i></a>
{{ end }} {{ end }}
</div> </div>
<div class="post-comment">
</div>
</article> </article>
{{- end }} {{- end }}

View File

@ -1,5 +1,5 @@
{{ if and .IsPage (ne .Params.comment false) }} {{ if and .IsPage (ne .Params.comment false) }}
<div class="comments-container"> <div class="post-comment">
{{- if and .Site.Params.disqus.name .Site.Params.disqus.lazy -}} {{- if and .Site.Params.disqus.name .Site.Params.disqus.lazy -}}
<div onclick="showDisqus();" id="disqus_title" class="disqus_title">显示 Disqus 评论</div> <div onclick="showDisqus();" id="disqus_title" class="disqus_title">显示 Disqus 评论</div>
{{- end -}} {{- end -}}
@ -17,7 +17,7 @@
clientSecret: '{{ .Site.Params.gitalk.clientSecret }}', clientSecret: '{{ .Site.Params.gitalk.clientSecret }}',
repo: '{{ .Site.Params.gitalk.repo }}', repo: '{{ .Site.Params.gitalk.repo }}',
owner: '{{ .Site.Params.gitalk.owner }}', owner: '{{ .Site.Params.gitalk.owner }}',
admin: ['{{ .Site.Params.gitalk.owner }}'], admin: ['{{ .Site.Params.gitalk.admin }}'],
body: decodeURI(location.href) body: decodeURI(location.href)
}); });
gitalk.render('gitalk-container'); gitalk.render('gitalk-container');

View File

@ -5,16 +5,16 @@
<span itemprop="copyrightYear">{{.}} - {{ now.Year }}</span> <span itemprop="copyrightYear">{{.}} - {{ now.Year }}</span>
{{ end }} {{ end }}
<span class="with-love"> <span class="with-love">
<i class="iconfont icon-love"></i> <i class="iconfont icon-love"></i>
</span> </span>
{{ if .Site.Params.author }} {{ if .Site.Params.author }}
<span class="author" itemprop="copyrightHolder"><a href="{{ .Site.BaseURL }}">{{ .Site.Params.author }}</a> | </span> <span class="author" itemprop="copyrightHolder"><a href="{{ .Site.BaseURL }}">{{ .Site.Params.author }}</a> | </span>
{{ end }} {{ end }}
{{ with .Site.Params.beian }} {{ with .Site.Params.beian }}
<a href="http://www.miibeian.gov.cn/" target="_blank" rel="external nofollow">{{ . }} </a> | <a href="http://www.miibeian.gov.cn/" target="_blank" rel="external nofollow">{{ . }} </a> |
{{ end }} {{ end }}
<span>Powered by <a href="https://gohugo.io/" target="_blank" rel="external nofollow">Hugo</a> & <a href="https://github.com/liuzc/leaveit" target="_blank" rel="external nofollow">LeaveIt</a></span> <span>Powered by <a href="https://gohugo.io/" target="_blank" rel="external nofollow">Hugo</a> & <a href="https://github.com/liuzc/leaveit" target="_blank" rel="external nofollow">LeaveIt</a></span>
</div> </div>
</footer> </footer>

View File

@ -39,6 +39,6 @@
{{ if eq ( getenv "HUGO_ENV" ) "production" }} {{ if eq ( getenv "HUGO_ENV" ) "production" }}
{{ with .Site.Params.cdn_url }} {{ with .Site.Params.cdn_url }}
{{ $cdn_url = .}} {{ $cdn_url = .}}
{{ end }} {{ end }}
{{ end }} {{ end }}
{{ .Scratch.Set "cdn_url" $cdn_url }} {{ .Scratch.Set "cdn_url" $cdn_url }}

View File

@ -1,4 +1,3 @@
<div class="post-toc" id="post-toc"> <div class="post-toc" id="post-toc">
<h2 class="post-toc-title">{{ T "toc" }}</h2> <h2 class="post-toc-title">{{ T "toc" }}</h2>
{{ $globalAutoCollapseToc := .Site.Params.autoCollapseToc | default false }} {{ $globalAutoCollapseToc := .Site.Params.autoCollapseToc | default false }}
@ -6,3 +5,34 @@
{{.TableOfContents}} {{.TableOfContents}}
</div> </div>
</div> </div>
<script type="text/javascript">
window.onload = function () {
var fix = $('.post-toc');
var end = $('.post-comment');
var fixTop = fix.offset().top, fixHeight = fix.height();
var endTop, miss;
var offsetTop = fix[0].offsetTop;
$(window).scroll(function () {
var docTop = Math.max(document.body.scrollTop, document.documentElement.scrollTop);
if (end.length > 0) {
endTop = end.offset().top;
miss = endTop - docTop - fixHeight;
}
if (fixTop < docTop) {
fix.css({ 'position': 'fixed' });
if ((end.length > 0) && (endTop < (docTop + fixHeight))) {
fix.css({ top: miss });
} else {
fix.css({ top: 0 });
}
} else {
fix.css({ 'position': 'absolute' });
fix.css({ top: offsetTop });
}
})
}
</script>