feat: improve configuration (#245)

* feat: improve configuration

* fix: fix partials/footer.html error
This commit is contained in:
Dillon
2020-04-21 22:55:06 +08:00
committed by GitHub
parent 8a0e61085c
commit f14301c395
62 changed files with 1548 additions and 1669 deletions

View File

@@ -1,112 +1,106 @@
{{- $scratch := .Scratch.Get "scratch" -}}
{{- $CDN := $scratch.Get "CDN" -}}
{{- $fingerprint := $scratch.Get "fingerprint" -}}
{{- $cdn := .Scratch.Get "cdn" | default dict -}}
{{- $fingerprint := .Scratch.Get "fingerprint" -}}
{{- $comment := (.Scratch.Get "params").comment | default dict -}}
{{- $commentConfig := dict -}}
{{- if eq hugo.Environment "production" | and (ne .Site.Params.comment.enable false) | and (ne .Params.comment false) -}}
{{- if $comment.enable -}}
<div id="comments">
{{- /* Disqus Comment System */ -}}
{{- if .Site.Params.comment.disqus.enable -}}
{{- if $comment.disqus.enable -}}
<div id="disqus_thread" class="comment"></div>
{{- $source := printf "https://%s.disqus.com/embed.js" .Site.Params.comment.disqus.shortname -}}
{{- dict "source" $source "defer" true "crossorigin" true | slice | $scratch.Add "script" -}}
{{- $source := printf "https://%s.disqus.com/embed.js" $comment.disqus.shortname -}}
{{- dict "source" $source "defer" true "crossorigin" true | dict "scratch" $.Scratch "data" | partial "scratch/script.html" -}}
<noscript>
Please enable JavaScript to view the comments powered by <a href="https://disqus.com/?ref_noscript">Disqus</a>.
</noscript>
{{- end -}}
{{- /* Gitalk Comment System */ -}}
{{- if .Site.Params.comment.gitalk.enable -}}
{{- $gitalk := .Site.Params.comment.gitalk -}}
{{- if $comment.gitalk.enable -}}
<div id="gitalk" class="comment"></div>
{{- with $CDN.gitalkCSS -}}
{{- dict "source" . "crossorigin" true | slice | $scratch.Add "stylesheet" -}}
{{- with $cdn.gitalkCSS -}}
{{- dict "source" . "crossorigin" true | dict "scratch" $.Scratch "data" | partial "scratch/stylesheet.html" -}}
{{- else -}}
{{- dict "source" "lib/gitalk/gitalk.css" "minify" true "fingerprint" $fingerprint | slice | $scratch.Add "stylesheet" -}}
{{- dict "source" "lib/gitalk/gitalk.css" "minify" true "fingerprint" $fingerprint | dict "scratch" $.Scratch "data" | partial "scratch/stylesheet.html" -}}
{{- end -}}
{{- with $CDN.gitalkJS -}}
{{- dict "source" . "crossorigin" true | slice | $scratch.Add "script" -}}
{{- with $cdn.gitalkJS -}}
{{- dict "source" . "crossorigin" true | dict "scratch" $.Scratch "data" | partial "scratch/script.html" -}}
{{- else -}}
{{- dict "source" "lib/gitalk/gitalk.min.js" "fingerprint" $fingerprint | slice | $scratch.Add "script" -}}
{{- dict "source" "lib/gitalk/gitalk.min.js" "fingerprint" $fingerprint | dict "scratch" $.Scratch "data" | partial "scratch/script.html" -}}
{{- end -}}
{{- $gitalkConfig := dict "id" .Date "title" .Title "clientID" $gitalk.clientId "clientSecret" $gitalk.clientSecret "repo" $gitalk.repo "owner" $gitalk.owner "admin" (slice $gitalk.owner) -}}
{{- $scratch.SetInMap "comment" "gitalk" $gitalkConfig -}}
{{- $commentConfig = dict "id" .Date "title" .Title "clientID" $comment.gitalk.clientId "clientSecret" $comment.gitalk.clientSecret "repo" $comment.gitalk.repo "owner" $comment.gitalk.owner "admin" (slice $comment.gitalk.owner) | dict "gitalk" | merge $commentConfig -}}
<noscript>
Please enable JavaScript to view the comments powered by <a href="https://github.com/gitalk/gitalk"></a>Gitalk</a>.
</noscript>
{{- end -}}
{{- /* Valine Comment System */ -}}
{{- if .Site.Params.comment.valine.enable -}}
{{- $valine := .Site.Params.comment.valine -}}
{{- if $comment.valine.enable -}}
<div id="valine" class="comment"></div>
{{- $options := dict "targetPath" "lib/valine/valine.min.css" -}}
{{- dict "source" "lib/valine/valine.scss" "toCSS" $options | slice | $scratch.Add "stylesheet" -}}
{{- with $CDN.valineJS -}}
{{- dict "source" . "crossorigin" true | slice | $scratch.Add "script" -}}
{{- dict "source" "lib/valine/valine.scss" "toCSS" $options | dict "scratch" $.Scratch "data" | partial "scratch/stylesheet.html" -}}
{{- with $cdn.valineJS -}}
{{- dict "source" . "crossorigin" true | dict "scratch" $.Scratch "data" | partial "scratch/script.html" -}}
{{- else -}}
{{- dict "source" "lib/valine/Valine.min.js" "fingerprint" $fingerprint | slice | $scratch.Add "script" -}}
{{- dict "source" "lib/valine/Valine.min.js" "fingerprint" $fingerprint | dict "scratch" $.Scratch "data" | partial "scratch/script.html" -}}
{{- end -}}
{{- $valineConfig := dict "el" "#valine" "appId" $valine.appId "appKey" $valine.appKey "lang" ($valine.lang | default "en") "notify" $valine.notify "verify" $valine.verify "visitor" $valine.visitor "recordIP" $valine.recordIP -}}
{{- with $valine.placeholder -}}
{{- $valineConfig = dict "placeholder" . | merge $valineConfig -}}
{{- $commentConfig = dict "el" "#valine" "appId" $comment.valine.appId "appKey" $comment.valine.appKey "lang" ($comment.valine.lang | default (T "valineLang")) "notify" $comment.valine.notify "verify" $comment.valine.verify "visitor" $comment.valine.visitor "recordIP" $comment.valine.recordIP "placeholder" ($comment.valine.placeholder | default (T "valinePlaceholder")) | dict "valine" | merge $commentConfig -}}
{{- with $comment.valine.avatar -}}
{{- $commentConfig = dict "avatar" . | dict "valine" | merge $commentConfig -}}
{{- end -}}
{{- with $valine.avatar -}}
{{- $valineConfig = dict "avatar" . | merge $valineConfig -}}
{{- with $comment.valine.meta -}}
{{- $commentConfig = dict "meta" . | dict "valine" | merge $commentConfig -}}
{{- end -}}
{{- with $valine.meta -}}
{{- $valineConfig = dict "meta" . | merge $valineConfig -}}
{{- with $comment.valine.pageSize -}}
{{- $commentConfig = dict "pageSize" . | dict "valine" | merge $commentConfig -}}
{{- end -}}
{{- with $valine.pageSize -}}
{{- $valineConfig = dict "pageSize" . | merge $valineConfig -}}
{{- end -}}
{{- $scratch.SetInMap "comment" "valine" $valineConfig -}}
<noscript>
Please enable JavaScript to view the comments powered by <a href="https://valine.js.org/">Valine</a>.
</noscript>
{{- end -}}
{{- /* Facebook Comment System */ -}}
{{- if .Site.Params.comment.facebook.enable -}}
{{- $facebook := .Site.Params.comment.facebook -}}
{{- if $comment.facebook.enable -}}
<div id="fb-root" class="comment"></div>
<div
class="fb-comments"
data-href="{{ .Site.Params.baseURL }}{{ .Permalink | absURL }}"
data-width="{{ $facebook.width }}"
data-numposts="{{ $facebook.numPosts }}"
data-href="{{ .Permalink | absURL }}"
data-width="{{ $comment.facebook.width }}"
data-numposts="{{ $comment.facebook.numPosts }}"
></div>
{{- $source := printf "https://connect.facebook.net/%s/sdk.js#xfbml=1&version=v5.0&appId=%s&autoLogAppEvents=1" $facebook.languageCode $facebook.appId -}}
{{- dict "source" $source "defer" true "crossorigin" true | slice | $scratch.Add "script" -}}
{{- $source := printf "https://connect.facebook.net/%s/sdk.js#xfbml=1&version=v5.0&appId=%s&autoLogAppEvents=1" ($comment.facebook.languageCode | default (T "facebookLanguageCode")) $comment.facebook.appId -}}
{{- dict "source" $source "defer" true "crossorigin" true | dict "scratch" $.Scratch "data" | partial "scratch/script.html" -}}
<noscript>
Please enable JavaScript to view the comments powered by <a href="https://developers.facebook.com/docs/plugins/comments/"></a>Facebook</a>.
</noscript>
{{- end -}}
{{- /* Telegram Comments System */ -}}
{{- if .Site.Params.comment.telegram.enable -}}
{{- $telegram := .Site.Params.comment.telegram -}}
{{- if $comment.telegram.enable -}}
<div id="telegram-comments" class="comment"></div>
{{- $attr := printf `data-comments-app-website="%s"` $telegram.siteID -}}
{{- $attr = printf `%s data-limit="%s"` $attr ($telegram.limit | default 5) -}}
{{- with $telegram.height -}}
{{- $attr := printf `data-comments-app-website="%s"` $comment.telegram.siteID -}}
{{- $attr = printf `%s data-limit="%s"` $attr ($comment.telegram.limit | default 5) -}}
{{- with $comment.telegram.height -}}
{{- $attr = printf `%s data-height="%s"` $attr . -}}
{{- end -}}
{{- with $telegram.color -}}
{{- with $comment.telegram.color -}}
{{- $attr = printf `%s data-color="%s"` $attr . -}}
{{- end -}}
{{- if $telegram.colorful -}}
{{- if $comment.telegram.colorful -}}
{{- $attr = printf `%s data-colorful="1"` $attr -}}
{{- end -}}
{{- if $telegram.dislikes -}}
{{- if $comment.telegram.dislikes -}}
{{- $attr = printf `%s data-dislikes="1"` $attr -}}
{{- end -}}
{{- if $telegram.outlined -}}
{{- if $comment.telegram.outlined -}}
{{- $attr = printf `%s data-outlined="1"` $attr -}}
{{- end -}}
{{- dict "source" "https://comments.app/js/widget.js?2" "defer" true "crossorigin" true "attr" $attr | slice | $scratch.Add "script" -}}
{{- dict "source" "https://comments.app/js/widget.js?2" "defer" true "crossorigin" true "attr" $attr | dict "scratch" $.Scratch "data" | partial "scratch/script.html" -}}
<noscript>
Please enable JavaScript to view the comments powered by <a href="https://comments.app/">Telegram Comments</a>.
</noscript>
{{- end -}}
</div>
{{- end -}}
{{- dict "comment" $commentConfig | dict "config" | merge (.Scratch.Get "this") | .Scratch.Set "this" -}}