fix giscus and multilingual mode
This commit is contained in:
parent
0784b32a41
commit
1105d5e939
16 changed files with 424 additions and 211 deletions
|
@ -14,8 +14,9 @@
|
|||
</div>
|
||||
{{ if .Params.tags }}
|
||||
<div>
|
||||
{{ range .Params.tags }}
|
||||
<a class="ml-1" href="/tags/{{ . }}">#{{ . }}</a>
|
||||
{{ range $tag := .Params.tags }}
|
||||
{{ $url := printf "tags/%s" $tag | relLangURL }}
|
||||
<a class="ml-1" href="{{ $url }}">#{{ . }}</a>
|
||||
{{ end }}
|
||||
</div>
|
||||
{{ end }}
|
||||
|
@ -26,32 +27,6 @@
|
|||
{{ .Content }}
|
||||
</article>
|
||||
</main>
|
||||
{{ if or .Params.math .Site.Params.math }}
|
||||
{{ partial "math.html" . }}
|
||||
{{ end }}
|
||||
|
||||
{{ if or .Params.mermaid .Site.Params.mermaid }}
|
||||
{{ partial "mermaid.html" . }}
|
||||
{{ end }}
|
||||
|
||||
{{ if or .Params.comment (and .Site.Params.commentOnAllPosts (ne .Params.comment false)) }}
|
||||
|
||||
{{ if eq .Site.Params.comment "disqus"}}
|
||||
{{ partial "disqus.html" . }}
|
||||
{{ end }}
|
||||
|
||||
{{ if eq .Site.Params.comment "utterances"}}
|
||||
{{ partial "utterances.html" . }}
|
||||
{{ end }}
|
||||
|
||||
{{ if eq .Site.Params.comment "giscus" }}
|
||||
{{ partial "giscus.html" }}
|
||||
{{ end }}
|
||||
|
||||
{{ if eq .Site.Params.comment "ovo"}}
|
||||
{{ partial "ovo.html" . }}
|
||||
{{ end }}
|
||||
|
||||
{{ end }}
|
||||
{{ partial "plugin.html" . }}
|
||||
</div>
|
||||
{{ end }}
|
|
@ -5,7 +5,7 @@
|
|||
{{ $data := .Data }}
|
||||
{{ range $key, $value := .Data.Terms.ByCount }}
|
||||
<div class="mb-5 flex justify-between">
|
||||
<a class="self-start" href="{{ $data.Plural | absLangURL }}/{{ $value.Name }}">
|
||||
<a class="self-start" href="{{ $data.Plural | relLangURL }}/{{ $value.Name }}">
|
||||
{{ $value.Name }}
|
||||
</a>
|
||||
<span class="">{{ $value.Count }}</span>
|
||||
|
|
|
@ -1,28 +1,18 @@
|
|||
<script>
|
||||
const repo = '{{ .Site.Params.giscus.repo }}'
|
||||
const repoId = '{{ .Site.Params.giscus.repoId }}'
|
||||
const category = '{{ .Site.Params.giscus.category }}'
|
||||
const categoryId = '{{ .Site.Params.giscus.categoryId }}'
|
||||
const mapping = '{{ .Site.Params.giscus.mapping }}'
|
||||
const inputPosition = '{{ .Site.Params.giscus.inputPosition }}'
|
||||
const theme = localStorage.theme || 'preferred-color-scheme';
|
||||
|
||||
const s = document.createElement('script')
|
||||
s.src = 'https://giscus.app/client.js'
|
||||
s.async = true
|
||||
s.crossOrigin = 'anonymous'
|
||||
s.setAttribute('data-repo', repo)
|
||||
s.setAttribute('data-repo-id', repoId)
|
||||
s.setAttribute('data-category', category)
|
||||
s.setAttribute('data-category-id', categoryId)
|
||||
s.setAttribute('data-mapping', mapping)
|
||||
s.setAttribute('data-strict', "0")
|
||||
s.setAttribute('data-reactions-enabled', "1")
|
||||
s.setAttribute('data-emit-metadata', "0")
|
||||
s.setAttribute('data-input-position', inputPosition)
|
||||
s.setAttribute('data-theme', theme)
|
||||
s.setAttribute('data-loading', "lazy")
|
||||
s.setAttribute('data-lang', "en")
|
||||
|
||||
document.querySelector('main').appendChild(s)
|
||||
</script>
|
||||
{{ $giscus := .Site.Params.comment.giscus }}
|
||||
<script
|
||||
src="https://giscus.app/client.js"
|
||||
data-repo="{{ $giscus.repo }}"
|
||||
data-repo-id="{{ $giscus.repoId }}"
|
||||
data-category="{{ $giscus.category }}"
|
||||
data-category-id="{{ $giscus.categoryId }}"
|
||||
data-mapping="{{ $giscus.mapping }}"
|
||||
data-strict="0"
|
||||
data-reactions-enabled="{{ cond $giscus.reactions 1 0 }}"
|
||||
data-emit-metadata="{{ cond $giscus.metadata 1 0 }}"
|
||||
data-input-position="{{ $giscus.inputPosition }}"
|
||||
data-theme="preferred_color_scheme"
|
||||
data-lang="en"
|
||||
data-loading="lazy"
|
||||
crossorigin="anonymous"
|
||||
async>
|
||||
</script>
|
||||
|
|
|
@ -29,23 +29,12 @@
|
|||
{{ end }}
|
||||
</head>
|
||||
<script>
|
||||
// We will default to system theme color if no choice was made.
|
||||
let theme_2b_used = window.matchMedia('(prefers-color-scheme: dark)').matches ? 'dark' : 'light';
|
||||
// default to system color scheme.
|
||||
let systemColorScheme = window.matchMedia('(prefers-color-scheme: dark)').matches ? 'dark' : 'light';
|
||||
|
||||
try {
|
||||
if (!('theme' in localStorage)) {
|
||||
const default_theme = '{{ .Site.Params.defaultTheme }}';
|
||||
|
||||
// For the first time entering this site, use the theme specified in the configuration.
|
||||
if (default_theme === 'dark' || default_theme === 'light') {
|
||||
theme_2b_used = default_theme;
|
||||
}
|
||||
|
||||
// Remember the choice.
|
||||
localStorage.theme = theme_2b_used;
|
||||
}
|
||||
|
||||
document.querySelector('html').classList.add(localStorage.theme);
|
||||
document.querySelector('html').classList.add(systemColorScheme);
|
||||
localStorage.setItem('theme', systemColorScheme);
|
||||
} catch (e) {
|
||||
console.error(e);
|
||||
}
|
||||
|
|
|
@ -5,12 +5,12 @@
|
|||
{{ if .Site.Params.brand }}
|
||||
<div class="mr-3 text-3xl"><a href="/">{{ .Site.Params.brand }}</a></div>
|
||||
{{ end }}
|
||||
<div id="theme-switcher" class="text-3xl cursor-pointer">{{ index .Site.Params.switch 1 }}</div>
|
||||
<div id="theme-switch" class="text-3xl cursor-pointer">{{ index .Site.Params.switch 1 }}</div>
|
||||
</div>
|
||||
<ul class="flex items-center font-medium
|
||||
whitespace-nowrap overflow-x-auto overflow-y-hidden">
|
||||
{{ range .Site.Menus.main }}
|
||||
<li class="ml-1 mr-1"><a href="{{ .URL | absLangURL }}">{{ T .Identifier | default .Name }}</a></li>
|
||||
<li class="ml-1 mr-1"><a href="{{ .Identifier | relLangURL }}">{{ T .Identifier | default .Name }}</a></li>
|
||||
{{ end }}
|
||||
</ul>
|
||||
<ul class="flex item-center text-sm font-bold">
|
||||
|
|
|
@ -1,4 +1,7 @@
|
|||
<script src="https://cdn.jsdelivr.net/npm/mermaid/dist/mermaid.min.js"></script>
|
||||
<script
|
||||
src="https://cdn.jsdelivr.net/npm/mermaid/dist/mermaid.min.js"
|
||||
crossorigin="anonymous">
|
||||
</script>
|
||||
<script>
|
||||
mermaid.initialize({ startOnLoad: true });
|
||||
mermaid.init({theme: 'dark'}, 'code.language-mermaid')
|
||||
</script>
|
|
@ -1,29 +0,0 @@
|
|||
<div id="ovo_thread" class="mt-4 mb-4">
|
||||
<div class="flex flex-col items-center">评论插件加载中 OvO</div>
|
||||
</div>
|
||||
<link rel="stylesheet" href="//unpkg.com/@ovojs/ovo/dist/style.css">
|
||||
<script type="text/javascript">
|
||||
(function () {
|
||||
if (window.location.hostname == "localhost")
|
||||
return;
|
||||
|
||||
const script = document.createElement('script');
|
||||
script.type = 'text/javascript';
|
||||
script.src = '//unpkg.com/@ovojs/ovo';
|
||||
(document.getElementsByTagName('head')[0] ||
|
||||
document.getElementsByTagName('body')[0])
|
||||
.appendChild(script);
|
||||
|
||||
script.addEventListener('load', function () {
|
||||
const target = document.getElementById('ovo_thread');
|
||||
target.innerHTML = '';
|
||||
new OvO({
|
||||
target,
|
||||
props: {
|
||||
server: "{{ .Site.Params.ovo.server }}",
|
||||
placeholder: "{{ .Site.Params.ovo.placeholder }}"
|
||||
}
|
||||
})
|
||||
})
|
||||
})();
|
||||
</script>
|
23
layouts/partials/plugin.html
Normal file
23
layouts/partials/plugin.html
Normal file
|
@ -0,0 +1,23 @@
|
|||
{{ if or .Params.math .Site.Params.math }}
|
||||
{{ partial "math.html" . }}
|
||||
{{ end }}
|
||||
|
||||
{{ if or .Params.mermaid .Site.Params.mermaid }}
|
||||
{{ partial "mermaid.html" . }}
|
||||
{{ end }}
|
||||
|
||||
{{ if or .Params.comment (and .Site.Params.commentOnAllPosts (ne .Params.comment false)) }}
|
||||
|
||||
{{ if eq .Site.Params.comment.provider "disqus"}}
|
||||
{{ partial "disqus.html" . }}
|
||||
{{ end }}
|
||||
|
||||
{{ if eq .Site.Params.comment.provider "giscus" }}
|
||||
{{ partial "giscus.html" . }}
|
||||
{{ end }}
|
||||
|
||||
{{ if eq .Site.Params.comment.provider "utterances"}}
|
||||
{{ partial "utterances.html" . }}
|
||||
{{ end }}
|
||||
|
||||
{{ end }}
|
|
@ -1,18 +1,8 @@
|
|||
<script>
|
||||
const repo = '{{ .Site.Params.utterances.repo }}'
|
||||
const issueTerm = '{{ .Site.Params.utterances.issueTerm }}'
|
||||
const theme = localStorage.theme ? `github-${localStorage.theme}` : 'preferred-color-scheme';
|
||||
const label = '{{ .Site.Params.utterances.label }}'
|
||||
|
||||
const script = document.createElement('script')
|
||||
script.src = 'https://utteranc.es/client.js'
|
||||
script.async = true
|
||||
script.crossOrigin = 'anonymous'
|
||||
|
||||
script.setAttribute('repo', repo)
|
||||
script.setAttribute('issue-term', issueTerm)
|
||||
script.setAttribute('theme', theme)
|
||||
script.setAttribute('label', label ? label : 'comment')
|
||||
|
||||
document.querySelector('main').appendChild(script)
|
||||
<script src="https://utteranc.es/client.js"
|
||||
repo="{{ .Site.Params.utterances.repo }}"
|
||||
issue-term="{{ .Site.Params.utterances.issueTerm }}"
|
||||
label="{{ .Site.Params.utterances.label }}"
|
||||
theme="preferred-color-scheme"
|
||||
crossorigin="anonymous"
|
||||
async>
|
||||
</script>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue