From ed14432f77771bda10c677b64bb41b6e7b0d81f5 Mon Sep 17 00:00:00 2001 From: Xin Date: Mon, 14 Aug 2023 21:56:26 +0100 Subject: [PATCH] refactor: use "sidebar-tree" for entire rendering chore: update example site content chore: add configuration for footer chore: allow disable footer completely chore: navbar highlights if contains current page chore: styling update for partial templates chore: update steps to use markdown delimiter --- exampleSite/content/blog/test.md | 5 - exampleSite/content/docs/_index.ja.md | 9 ++ exampleSite/content/docs/_index.md | 7 +- .../content/docs/components/_index.ja.md | 13 ++ exampleSite/content/docs/components/steps.md | 10 +- exampleSite/content/docs/introduction.ja.md | 1 + exampleSite/hugo.yaml | 5 + layouts/_default/baseof.html | 2 +- layouts/partials/footer.html | 20 +-- layouts/partials/language-switch.html | 2 +- layouts/partials/navbar.html | 19 +-- layouts/partials/scripts.html | 48 +++---- layouts/partials/sidebar.html | 125 +++++++++--------- layouts/partials/toc.html | 50 ++++--- layouts/shortcodes/steps.html | 2 +- 15 files changed, 178 insertions(+), 140 deletions(-) delete mode 100644 exampleSite/content/blog/test.md create mode 100644 exampleSite/content/docs/_index.ja.md create mode 100644 exampleSite/content/docs/components/_index.ja.md diff --git a/exampleSite/content/blog/test.md b/exampleSite/content/blog/test.md deleted file mode 100644 index c79ebc1..0000000 --- a/exampleSite/content/blog/test.md +++ /dev/null @@ -1,5 +0,0 @@ ---- -title: Test very long title to see how it looks ---- - -Hello world! diff --git a/exampleSite/content/docs/_index.ja.md b/exampleSite/content/docs/_index.ja.md new file mode 100644 index 0000000..a8676b3 --- /dev/null +++ b/exampleSite/content/docs/_index.ja.md @@ -0,0 +1,9 @@ +--- +linkTitle: "ドキュメンテーション" +title: Hextraへようこそ +--- + +**Hextra**は、[Tailwind CSS](https://tailwindcss.com/)で構築された、モダンでレスポンシブでパワフルな[Hugo](https://gohugo.io/)テーマです。 +[Next.js](https://nextjs.org/)テーマの[Nextra](https://github.com/shuding/nextra)にインスパイアされています。 + +## クイックスタート diff --git a/exampleSite/content/docs/_index.md b/exampleSite/content/docs/_index.md index e819f84..8afbc5e 100644 --- a/exampleSite/content/docs/_index.md +++ b/exampleSite/content/docs/_index.md @@ -1,4 +1,9 @@ --- linkTitle: "Documentation" -title: Welcome to Hextra +title: Introduction --- + +**Hextra** is a modern, responsive, and powerful [Hugo](https://gohugo.io/) theme built with [Tailwind CSS](https://tailwindcss.com/). +It is inspired by Next.js theme [Nextra](https://github.com/shuding/nextra). + +Hextra is designed for building websites for documentation, blogs, and landing pages. It is elegant and easy to use out of the box, but also highly customizable to fit your needs. diff --git a/exampleSite/content/docs/components/_index.ja.md b/exampleSite/content/docs/components/_index.ja.md new file mode 100644 index 0000000..0c70a09 --- /dev/null +++ b/exampleSite/content/docs/components/_index.ja.md @@ -0,0 +1,13 @@ +--- +title: コンポーネント +weight: 2 +--- + +Hextraは、[Hugo Shortcodes](https://gohugo.io/content-management/shortcodes/)に基づいたさまざまな組み込みコンポーネントを提供しています。 + + +{{< cards >}} + {{< card link="callouts" title="Callouts" icon="warning" >}} + {{< card link="cards" title="Cards" icon="cards" >}} + {{< card link="steps" title="Steps" icon="one" >}} +{{< /cards >}} diff --git a/exampleSite/content/docs/components/steps.md b/exampleSite/content/docs/components/steps.md index e8835a1..f97b0b1 100644 --- a/exampleSite/content/docs/components/steps.md +++ b/exampleSite/content/docs/components/steps.md @@ -6,7 +6,7 @@ A built-in component to display a series of steps. ## Example -{{< steps >}} +{{% steps %}} ### Step 1 @@ -20,15 +20,15 @@ This is the second step. This is the third step. -{{< /steps >}} +{{% /steps %}} ## Usage Put Markdown h3 header within `steps` shortcode. -```markdown -{{}} +``` +{{%/* steps */%}} ### Step 1 This is the first step. @@ -36,5 +36,5 @@ This is the first step. ### Step 2 This is the second step. -{{}} +{{%/* /steps */%}} ``` diff --git a/exampleSite/content/docs/introduction.ja.md b/exampleSite/content/docs/introduction.ja.md index bc46e20..a0ac203 100644 --- a/exampleSite/content/docs/introduction.ja.md +++ b/exampleSite/content/docs/introduction.ja.md @@ -1,5 +1,6 @@ --- title: はじめに +weight: 1 --- プロジェクトの紹介。 diff --git a/exampleSite/hugo.yaml b/exampleSite/hugo.yaml index 4582c2e..32b9d4a 100644 --- a/exampleSite/hugo.yaml +++ b/exampleSite/hugo.yaml @@ -70,6 +70,11 @@ menu: weight: 2 params: + footer: + disabled: false + displayCopyright: true + displayPoweredBy: true + displayUpdatedDate: true dateFormat: "January 2, 2006" diff --git a/layouts/_default/baseof.html b/layouts/_default/baseof.html index bd81e37..1d0ca1b 100644 --- a/layouts/_default/baseof.html +++ b/layouts/_default/baseof.html @@ -4,7 +4,7 @@ {{- partial "navbar.html" . -}} {{- block "main" . }}{{ end -}} - {{- partial "footer.html" . -}} + {{- if not .Site.Params.footer.disabled }}{{ partial "footer.html" . }}{{ end }} {{ partial "scripts.html" . }} diff --git a/layouts/partials/footer.html b/layouts/partials/footer.html index e44ba63..4786207 100644 --- a/layouts/partials/footer.html +++ b/layouts/partials/footer.html @@ -4,20 +4,22 @@ + +{{- define "theme-credit" -}} + + Powered by Hextra + {{- partial "utils/icon.html" (dict "name" "hextra" "attributes" "height=1em") -}} + +{{- end -}} diff --git a/layouts/partials/language-switch.html b/layouts/partials/language-switch.html index d1a4104..cade927 100644 --- a/layouts/partials/language-switch.html +++ b/layouts/partials/language-switch.html @@ -15,7 +15,7 @@ {{ range site.Languages }} {{ $link := partial "utils/lang-link" (dict "lang" .Lang "context" $page) }}
  • - + {{- .LanguageName -}} {{- if eq .LanguageName site.Language.LanguageName -}} diff --git a/layouts/partials/navbar.html b/layouts/partials/navbar.html index c27c40d..ecdaaec 100644 --- a/layouts/partials/navbar.html +++ b/layouts/partials/navbar.html @@ -5,36 +5,39 @@ {{ partial "utils/icon.html" (dict "name" "hextra" "attributes" "height=20") }} {{- $currentPage := . -}} {{- range .Site.Menus.main -}} {{- if eq .Params.type "search" -}} - {{ partial "search.html" (dict "params" .Params) }} + {{- partial "search.html" (dict "params" .Params) -}} {{- else -}} - {{ $external := strings.HasPrefix .URL "http" }} + {{- $external := strings.HasPrefix .URL "http" -}} + {{/* Display icon menu item */}} {{- if .Params.icon -}} - {{ partial "utils/icon.html" (dict "name" .Params.icon "attributes" "height=24") }} + {{- partial "utils/icon.html" (dict "name" .Params.icon "attributes" "height=24") -}} {{ .Name }} {{- else -}} + {{- $active := or ($currentPage.HasMenuCurrent "main" .) ($currentPage.IsMenuCurrent "main" .) -}} + {{- $activeClass := cond $active "font-medium" "text-gray-600 hover:text-gray-800 dark:text-gray-400 dark:hover:text-gray-200" -}} {{- end -}} - {{ end }} - {{ end }} + {{- end -}} + {{- end -}} diff --git a/layouts/partials/scripts.html b/layouts/partials/scripts.html index e3fea38..f4dd0e4 100644 --- a/layouts/partials/scripts.html +++ b/layouts/partials/scripts.html @@ -1,30 +1,30 @@ -{{ $jsTheme := resources.Get "js/theme.js" }} -{{ $jsMenu := resources.Get "js/menu.js" }} -{{ $jsCodeCopy := resources.Get "js/code-copy.js" }} -{{ $jsTabs := resources.Get "js/tabs.js" }} -{{ $jsLang := resources.Get "js/lang.js" }} +{{- $jsTheme := resources.Get "js/theme.js" -}} +{{- $jsMenu := resources.Get "js/menu.js" -}} +{{- $jsCodeCopy := resources.Get "js/code-copy.js" -}} +{{- $jsTabs := resources.Get "js/tabs.js" -}} +{{- $jsLang := resources.Get "js/lang.js" -}} -{{ $scripts := slice $jsTheme $jsMenu $jsCodeCopy $jsTabs $jsLang | resources.Concat "js/main.js" }} -{{ if hugo.IsProduction }} - {{ $scripts = $scripts | minify | fingerprint }} -{{ end }} +{{- $scripts := slice $jsTheme $jsMenu $jsCodeCopy $jsTabs $jsLang | resources.Concat "js/main.js" -}} +{{- if hugo.IsProduction -}} + {{- $scripts = $scripts | minify | fingerprint -}} +{{- end -}} {{/* FlexSearch */}} {{- if not site.Params.search.disabled -}} - {{ $jsSearchScript := printf "%s.search.js" .Language.Lang }} - {{ $jsSearch := resources.Get "js/flexsearch.js" | resources.ExecuteAsTemplate $jsSearchScript . }} - {{ if hugo.IsProduction }} - {{ $jsSearch = $jsSearch | minify | fingerprint }} - {{ end }} - {{ $flexSearchJS := resources.Get "vendor/flexsearch/flexsearch.bundle.min.js" | fingerprint }} + {{- $jsSearchScript := printf "%s.search.js" .Language.Lang -}} + {{- $jsSearch := resources.Get "js/flexsearch.js" | resources.ExecuteAsTemplate $jsSearchScript . -}} + {{- if hugo.IsProduction -}} + {{- $jsSearch = $jsSearch | minify | fingerprint -}} + {{- end -}} + {{- $flexSearchJS := resources.Get "vendor/flexsearch/flexsearch.bundle.min.js" | fingerprint -}} {{- end -}} {{/* Mermaid */}} -{{ if .Page.Store.Get "hasMermaid" -}} - {{ $mermaidJS := resources.Get "vendor/mermaid/mermaid.min.js" | fingerprint }} +{{- if .Page.Store.Get "hasMermaid" -}} + {{- $mermaidJS := resources.Get "vendor/mermaid/mermaid.min.js" | fingerprint -}} -{{ end }} +{{- end -}} {{/* KaTex */}} -{{ if and (not site.Params.math.disabled) .Page.Params.math }} - {{ $katexCSS := resources.Get "vendor/katex/katex.min.css" | fingerprint }} - {{ $katexJS := resources.Get "vendor/katex/katex.min.js" | fingerprint }} - {{ $katexAutoRenderJS := resources.Get "vendor/katex/auto-render.min.js" | fingerprint }} +{{- if and (not site.Params.math.disabled) .Page.Params.math -}} + {{- $katexCSS := resources.Get "vendor/katex/katex.min.css" | fingerprint -}} + {{- $katexJS := resources.Get "vendor/katex/katex.min.js" | fingerprint -}} + {{- $katexAutoRenderJS := resources.Get "vendor/katex/auto-render.min.js" | fingerprint -}} {{ $katexFonts := resources.Match "vendor/katex/fonts/*" }} - {{ range $katexFonts }} + {{- range $katexFonts -}} {{ .Publish }} - {{ end }} + {{- end -}}