mirror of
https://github.com/imfing/hextra.git
synced 2025-07-01 23:17:23 -04:00
Compare commits
5 Commits
Author | SHA1 | Date | |
---|---|---|---|
2df3c563bf | |||
ec02eb34fe | |||
46dea718e6 | |||
adf5a113fc | |||
6a19ac31c0 |
@ -1,5 +1,16 @@
|
|||||||
// Search functionality using FlexSearch.
|
// Search functionality using FlexSearch.
|
||||||
|
|
||||||
|
// Change shortcut key to cmd+k on Mac, iPad or iPhone.
|
||||||
|
document.addEventListener("DOMContentLoaded", function () {
|
||||||
|
if (/iPad|iPhone|Macintosh/.test(navigator.userAgent)) {
|
||||||
|
// select the kbd element under the .search-wrapper class
|
||||||
|
const keys = document.querySelectorAll(".search-wrapper kbd");
|
||||||
|
keys.forEach(key => {
|
||||||
|
key.innerHTML = '<span class="text-xs">⌘</span>K';
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
// Render the search data as JSON.
|
// Render the search data as JSON.
|
||||||
// {{ $searchDataFile := printf "%s.search-data.json" .Language.Lang }}
|
// {{ $searchDataFile := printf "%s.search-data.json" .Language.Lang }}
|
||||||
// {{ $searchData := resources.Get "json/search-data.json" | resources.ExecuteAsTemplate $searchDataFile . }}
|
// {{ $searchData := resources.Get "json/search-data.json" | resources.ExecuteAsTemplate $searchDataFile . }}
|
||||||
|
@ -12,4 +12,5 @@ This section covers some advanced topics of the theme.
|
|||||||
{{< cards >}}
|
{{< cards >}}
|
||||||
{{< card link="multi-language" title="Multi-language" icon="translate" >}}
|
{{< card link="multi-language" title="Multi-language" icon="translate" >}}
|
||||||
{{< card link="customization" title="Customization" icon="pencil" >}}
|
{{< card link="customization" title="Customization" icon="pencil" >}}
|
||||||
|
{{< card link="comments" title="Comments System" icon="chat-alt" >}}
|
||||||
{{< /cards >}}
|
{{< /cards >}}
|
||||||
|
39
exampleSite/content/docs/advanced/comments.md
Normal file
39
exampleSite/content/docs/advanced/comments.md
Normal file
@ -0,0 +1,39 @@
|
|||||||
|
---
|
||||||
|
title: Comments System
|
||||||
|
linkTitle: Comments
|
||||||
|
---
|
||||||
|
|
||||||
|
Hextra supports adding comments system to your site.
|
||||||
|
Currently [giscus](https://giscus.app/) is supported.
|
||||||
|
|
||||||
|
<!--more-->
|
||||||
|
|
||||||
|
## giscus
|
||||||
|
|
||||||
|
[giscus](https://giscus.app/) is a comments system powered by [GitHub Discussions](https://docs.github.com/en/discussions). It is free and open source.
|
||||||
|
|
||||||
|
To enable giscus, you need to add the following to the site configuration file:
|
||||||
|
|
||||||
|
```yaml {filename="hugo.yaml"}
|
||||||
|
params:
|
||||||
|
comments:
|
||||||
|
enable: false
|
||||||
|
type: giscus
|
||||||
|
|
||||||
|
giscus:
|
||||||
|
repo: <repository>
|
||||||
|
repoId: <repository ID>
|
||||||
|
category: <category>
|
||||||
|
categoryId: <category ID>
|
||||||
|
```
|
||||||
|
|
||||||
|
The giscus configurations can be constructed from the [giscus.app](https://giscus.app/) website. More details can also be found there.
|
||||||
|
|
||||||
|
Comments can be enabled or disabled for a specific page in the page front matter:
|
||||||
|
|
||||||
|
```yaml {filename="content/docs/about.md"}
|
||||||
|
---
|
||||||
|
title: About
|
||||||
|
comments: true
|
||||||
|
---
|
||||||
|
```
|
@ -26,6 +26,7 @@ languages:
|
|||||||
title: "Hextra テーマ"
|
title: "Hextra テーマ"
|
||||||
zh-cn:
|
zh-cn:
|
||||||
languageName: 简体中文
|
languageName: 简体中文
|
||||||
|
languageCode: zh-CN
|
||||||
weight: 3
|
weight: 3
|
||||||
title: Hextra
|
title: Hextra
|
||||||
|
|
||||||
@ -122,3 +123,20 @@ params:
|
|||||||
editURL:
|
editURL:
|
||||||
enable: true
|
enable: true
|
||||||
base: "https://github.com/imfing/hextra/edit/main/exampleSite/content"
|
base: "https://github.com/imfing/hextra/edit/main/exampleSite/content"
|
||||||
|
|
||||||
|
comments:
|
||||||
|
enable: false
|
||||||
|
type: giscus
|
||||||
|
|
||||||
|
# https://giscus.app/
|
||||||
|
giscus:
|
||||||
|
repo: imfing/hextra
|
||||||
|
repoId: R_kgDOJ9fJag
|
||||||
|
category: General
|
||||||
|
categoryId: DIC_kwDOJ9fJas4CY7gW
|
||||||
|
# mapping: pathname
|
||||||
|
# strict: 0
|
||||||
|
# reactionsEnabled: 1
|
||||||
|
# emitMetadata: 0
|
||||||
|
# inputPosition: top
|
||||||
|
# lang: en
|
||||||
|
@ -10,6 +10,7 @@
|
|||||||
</div>
|
</div>
|
||||||
<div class="mt-16"></div>
|
<div class="mt-16"></div>
|
||||||
{{ partial "components/last-updated.html" . }}
|
{{ partial "components/last-updated.html" . }}
|
||||||
|
{{ partial "components/comments.html" . }}
|
||||||
</main>
|
</main>
|
||||||
</article>
|
</article>
|
||||||
</div>
|
</div>
|
||||||
|
@ -10,6 +10,8 @@
|
|||||||
<div class="content">
|
<div class="content">
|
||||||
{{ .Content }}
|
{{ .Content }}
|
||||||
</div>
|
</div>
|
||||||
|
<div class="mt-16"></div>
|
||||||
|
{{ partial "components/comments.html" . }}
|
||||||
</main>
|
</main>
|
||||||
</article>
|
</article>
|
||||||
</div>
|
</div>
|
||||||
|
@ -28,6 +28,7 @@
|
|||||||
{{ partial "components/last-updated.html" . }}
|
{{ partial "components/last-updated.html" . }}
|
||||||
{{ .Scratch.Set "reversePagination" true }}
|
{{ .Scratch.Set "reversePagination" true }}
|
||||||
{{ partial "components/pager.html" . }}
|
{{ partial "components/pager.html" . }}
|
||||||
|
{{ partial "components/comments.html" . }}
|
||||||
</main>
|
</main>
|
||||||
</article>
|
</article>
|
||||||
</div>
|
</div>
|
||||||
|
@ -9,9 +9,9 @@
|
|||||||
<h1>{{ .Title }}</h1>
|
<h1>{{ .Title }}</h1>
|
||||||
{{ .Content }}
|
{{ .Content }}
|
||||||
</div>
|
</div>
|
||||||
<div class="mt-16"></div>
|
|
||||||
{{ partial "components/last-updated.html" . }}
|
{{ partial "components/last-updated.html" . }}
|
||||||
{{ partial "components/pager.html" . }}
|
{{ partial "components/pager.html" . }}
|
||||||
|
{{ partial "components/comments.html" . }}
|
||||||
</main>
|
</main>
|
||||||
</article>
|
</article>
|
||||||
</div>
|
</div>
|
||||||
|
@ -11,6 +11,7 @@
|
|||||||
</div>
|
</div>
|
||||||
{{ partial "components/last-updated.html" . }}
|
{{ partial "components/last-updated.html" . }}
|
||||||
{{ partial "components/pager.html" . }}
|
{{ partial "components/pager.html" . }}
|
||||||
|
{{ partial "components/comments.html" . }}
|
||||||
</main>
|
</main>
|
||||||
</article>
|
</article>
|
||||||
</div>
|
</div>
|
||||||
|
11
layouts/partials/components/comments.html
Normal file
11
layouts/partials/components/comments.html
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
{{- $enableComments := site.Params.comments.enable | default false -}}
|
||||||
|
|
||||||
|
{{ if not (eq .Params.comments nil) }}
|
||||||
|
{{ $enableComments = .Params.comments }}
|
||||||
|
{{ end }}
|
||||||
|
|
||||||
|
{{- if $enableComments -}}
|
||||||
|
{{- if eq site.Params.comments.type "giscus" -}}
|
||||||
|
{{ partial "components/giscus.html" . }}
|
||||||
|
{{- end -}}
|
||||||
|
{{- end -}}
|
62
layouts/partials/components/giscus.html
Normal file
62
layouts/partials/components/giscus.html
Normal file
@ -0,0 +1,62 @@
|
|||||||
|
{{- $lang := site.Language.LanguageCode | default `en` -}}
|
||||||
|
|
||||||
|
{{- with site.Params.comments.giscus -}}
|
||||||
|
<script>
|
||||||
|
/*
|
||||||
|
* "preferred color scheme" theme in giscus works using "prefers-color-scheme" in media query.
|
||||||
|
* but, hugo's theme switch function works by using "color-theme" in local storage.
|
||||||
|
* This solution was created with reference to:
|
||||||
|
* https://github.com/giscus/giscus/issues/336#issuecomment-1214366281
|
||||||
|
*/
|
||||||
|
function getGiscusTheme() {
|
||||||
|
return localStorage.getItem("color-theme");
|
||||||
|
}
|
||||||
|
|
||||||
|
function setGiscusTheme() {
|
||||||
|
function sendMessage(message) {
|
||||||
|
const iframe = document.querySelector('iframe.giscus-frame');
|
||||||
|
if (!iframe) return;
|
||||||
|
iframe.contentWindow.postMessage({ giscus: message }, 'https://giscus.app');
|
||||||
|
}
|
||||||
|
sendMessage({
|
||||||
|
setConfig: {
|
||||||
|
theme: getGiscusTheme(),
|
||||||
|
},
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
document.addEventListener('DOMContentLoaded', function () {
|
||||||
|
const giscusAttributes = {
|
||||||
|
"src": "https://giscus.app/client.js",
|
||||||
|
"data-repo": "{{ .repo }}",
|
||||||
|
"data-repo-id": "{{ .repoId }}",
|
||||||
|
"data-category": "{{ .category }}",
|
||||||
|
"data-category-id": "{{ .categoryId }}",
|
||||||
|
"data-mapping": "{{ .mapping | default `pathname` }}",
|
||||||
|
"data-strict": "{{ (string .strict) | default 0 }}",
|
||||||
|
"data-reactions-enabled": "{{ (string .reactionsEnabled) | default 1 }}",
|
||||||
|
"data-emit-metadata": "{{ (string .emitMetadata) | default 0 }}",
|
||||||
|
"data-input-position": "{{ .inputPosition | default `top` }}",
|
||||||
|
"data-theme": getGiscusTheme(),
|
||||||
|
"data-lang": "{{ .lang | default $lang }}",
|
||||||
|
"crossorigin": "anonymous",
|
||||||
|
"async": "",
|
||||||
|
};
|
||||||
|
|
||||||
|
// Dynamically create script tag
|
||||||
|
const giscusScript = document.createElement("script");
|
||||||
|
Object.entries(giscusAttributes).forEach(([key, value]) => giscusScript.setAttribute(key, value));
|
||||||
|
document.getElementById('giscus').appendChild(giscusScript);
|
||||||
|
|
||||||
|
// Update giscus theme when theme switcher is clicked
|
||||||
|
const toggles = document.querySelectorAll(".theme-toggle");
|
||||||
|
if (toggles) {
|
||||||
|
toggles.forEach(toggle => toggle.addEventListener('click', setGiscusTheme));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<div id="giscus"></div>
|
||||||
|
{{- else -}}
|
||||||
|
{{ warnf "giscus is not configured" }}
|
||||||
|
{{- end -}}
|
@ -24,7 +24,7 @@
|
|||||||
>
|
>
|
||||||
<div class="flex w-full flex-col items-center sm:items-start">
|
<div class="flex w-full flex-col items-center sm:items-start">
|
||||||
{{- if (.Site.Params.footer.displayPoweredBy | default true) }}<div class="font-semibold">{{ template "theme-credit" . }}</div>{{ end }}
|
{{- if (.Site.Params.footer.displayPoweredBy | default true) }}<div class="font-semibold">{{ template "theme-credit" . }}</div>{{ end }}
|
||||||
{{- if .Site.Params.footer.displayCopyright }}<p class="mt-6 text-xs">{{ $copyright | markdownify }}</p>{{ end }}
|
{{- if .Site.Params.footer.displayCopyright }}<div class="mt-6 text-xs">{{ $copyright | markdownify }}</div>{{ end }}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</footer>
|
</footer>
|
||||||
|
@ -13,7 +13,7 @@
|
|||||||
<kbd
|
<kbd
|
||||||
class="absolute my-1.5 select-none ltr:right-1.5 rtl:left-1.5 h-5 rounded bg-white px-1.5 font-mono text-[10px] font-medium text-gray-500 border dark:border-gray-100/20 dark:bg-dark/50 contrast-more:border-current contrast-more:text-current contrast-more:dark:border-current items-center gap-1 transition-opacity pointer-events-none hidden sm:flex"
|
class="absolute my-1.5 select-none ltr:right-1.5 rtl:left-1.5 h-5 rounded bg-white px-1.5 font-mono text-[10px] font-medium text-gray-500 border dark:border-gray-100/20 dark:bg-dark/50 contrast-more:border-current contrast-more:text-current contrast-more:dark:border-current items-center gap-1 transition-opacity pointer-events-none hidden sm:flex"
|
||||||
>
|
>
|
||||||
<span class="text-xs">⌘</span>K
|
CTRL K
|
||||||
</kbd>
|
</kbd>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user