diff --git a/README.md b/README.md index 46e3abe1..b7e02ba9 100644 --- a/README.md +++ b/README.md @@ -259,6 +259,7 @@ These options set global values that some pages or all pages in the site use by | showRelatedInSidebar | boolean | no | | footerLogo | string | N/A | | enableSearch | boolean | N/A | +| blogDir | string | no | ### Page Parameters @@ -830,7 +831,18 @@ If you wish use [Utterances](https://github.com/utterance/utterances) comments o Utterances is loaded in the `comments.html` partial by referring to the `utterances.html` partial. Since `single.html` layout loads comments if comments are enabled, you must ensure *both* the `comments` and `utterances` parameters are configured. +#### Giscus Commenting Support +If you wish to use [giscus](https://giscus.app/) comments on your site, you'll need to perform the following: + + * Ensure your repository is [public](https://docs.github.com/en/github/administering-a-repository/managing-repository-settings/setting-repository-visibility#making-a-repository-public), otherwise visitors will not be able to view the discussion. + * The [giscus app](https://github.com/apps/giscus) is installed, otherwise visitors will not be able to comment and react. + * The Discussions feature is turned on by [enabling it for your repository](https://docs.github.com/en/github/administering-a-repository/managing-repository-settings/enabling-or-disabling-github-discussions-for-a-repository). + * Comment out the line for `disqusShortname = ""` in the `/config/_default/config.toml` file. + * Set `comments = true` in the `/config/_default/params.toml` file. + * Configure the giscus parameters in the `/config/_default/params.toml` file. + +Giscus is loaded in the `comments.html` partial by referring to the `giscus.html` partial. Since `single.html` layout loads comments if comments are enabled, you must ensure *both* the `comments` and `giscus` parameters are configured. ### Math notation @@ -849,13 +861,13 @@ mkdir -p layouts/partials && cp themes/clarity/layouts/partials/math.html layout Then add the corresponding line as its [README](https://github.com/KaTeX/KaTeX/tree/master/contrib/mhchem) suggested (without the `+` sign): ```diff - + - + -+ ++ - ``` diff --git a/exampleSite/.gitignore b/exampleSite/.gitignore index 132a0908..e4b8c67d 100644 --- a/exampleSite/.gitignore +++ b/exampleSite/.gitignore @@ -1,2 +1,3 @@ public/ -resources/ \ No newline at end of file +resources/ +.hugo_build.lock \ No newline at end of file diff --git a/exampleSite/config/_default/params.toml b/exampleSite/config/_default/params.toml index 36e13e68..23e045ff 100644 --- a/exampleSite/config/_default/params.toml +++ b/exampleSite/config/_default/params.toml @@ -102,6 +102,9 @@ languageMenuName = "🌐" # Enable or disable comments globally. Default to true. # comments = false +# Activate meta ld+json for blog +blogDir = "post" + # Enable or disable Utterances (https://github.com/utterance/utterances) Github Issue-Based Commenting # utterances = true # Run the utterances script in the single.html layout to load https://utteranc.es comments # utterancesRepo = "GHUsername/Repository.Name" # Utterances is enabled when this param is set @@ -109,6 +112,18 @@ languageMenuName = "🌐" # utterancesTheme = "github-light" # Default: github-dark # utterancesIssueTerm = "pathname" # Default: pathname +# Enable or disable Giscus comments globally. Default to false. +# giscus = true +# giscusRepo = "GHUsername/Repository.Name" # Giscus is enabled when this param is set +# giscusRepoId = "RepositoryID" # Required for Giscus to work +# giscusCategory = "Blog" +# giscusCategoryId = "CategoryID" # Required for Giscus to work +# giscusMapping = "pathname" # Default: pathname +# giscusReactionsEnabled = "1" # Default: 1 = true +# giscusTheme = "dark_protanopia" # Default: dark_dimmed +# giscusLang = "en" # Default: en + + # Maximum number of recent posts. (default: 8) # numberOfRecentPosts = 8 diff --git a/exampleSite/content/post/math-typesetting.md b/exampleSite/content/post/math-typesetting.md index 48fdc79f..242a3721 100644 --- a/exampleSite/content/post/math-typesetting.md +++ b/exampleSite/content/post/math-typesetting.md @@ -11,9 +11,8 @@ Mathematical notation in a Hugo project can be enabled by using third party Java In this example we will be using [KaTeX](https://katex.org/) -- Create a partial under `/layouts/partials/math.html` -- Within this partial reference the [Auto-render Extension](https://katex.org/docs/autorender.html) or host these scripts locally. -- Include the partial in your templates like so: +- Create a partial under `/layouts/partials/hooks/head-end.html` +- Add these lines to the newly created partial: ```bash {{ if or .Params.math .Site.Params.math }} @@ -21,17 +20,17 @@ In this example we will be using [KaTeX](https://katex.org/) {{ end }} ``` -- To enable KaTex globally set the parameter `math` to `true` in a project's configuration -- To enable KaTex on a per page basis include the parameter `math: true` in content files +- To enable KaTeX globally set the parameter `math` to `true` in a project's configuration +- To enable KaTeX on a per page basis include the parameter `math: true` in content files **Note:** Use the online reference of [Supported TeX Functions](https://katex.org/docs/supported.html) {{< math.inline >}} {{ if or .Page.Params.math .Site.Params.math }} - - - + + + {{ end }} {{}} diff --git a/exampleSite/layouts/.gitkeep b/exampleSite/layouts/.gitkeep deleted file mode 100644 index e69de29b..00000000 diff --git a/exampleSite/layouts/partials/hooks/head-end.html b/exampleSite/layouts/partials/hooks/head-end.html new file mode 100644 index 00000000..6af03480 --- /dev/null +++ b/exampleSite/layouts/partials/hooks/head-end.html @@ -0,0 +1,3 @@ +{{ if or .Params.math .Site.Params.math }} +{{ partial "math.html" . }} +{{ end }} \ No newline at end of file diff --git a/layouts/partials/comments.html b/layouts/partials/comments.html index 311788ff..5efcf691 100644 --- a/layouts/partials/comments.html +++ b/layouts/partials/comments.html @@ -5,5 +5,8 @@ {{ if .Site.Params.utterances }} {{ template "partials/utterances.html" . }} {{ end }} + {{ if .Site.Params.giscus }} + {{ template "partials/giscus.html" . }} + {{ end }} diff --git a/layouts/partials/figure.html b/layouts/partials/figure.html index e5b7afc0..28203afb 100644 --- a/layouts/partials/figure.html +++ b/layouts/partials/figure.html @@ -54,10 +54,10 @@ class="{{ $classes }} image_processed" width="{{ .Width }}" height="{{ .Height }}" - src="{{ .RelPermalink }}" + src="{{ .RelPermalink | absURL }}" {{ else }} class="{{ $classes }} image_unprocessed" - src="{{ $fileWeb }}" + src="{{ $fileWeb | absURL }}" {{ end }} {{ with $cap }} title="{{ safeHTML $cap }}" diff --git a/layouts/partials/giscus.html b/layouts/partials/giscus.html new file mode 100644 index 00000000..88089a67 --- /dev/null +++ b/layouts/partials/giscus.html @@ -0,0 +1,18 @@ +{{ if .Site.Params.giscus }} + + {{ end }} \ No newline at end of file diff --git a/layouts/partials/math.html b/layouts/partials/math.html index 999766e8..427d25f8 100644 --- a/layouts/partials/math.html +++ b/layouts/partials/math.html @@ -1,3 +1,3 @@ - - - \ No newline at end of file + + + \ No newline at end of file diff --git a/layouts/partials/opengraph.html b/layouts/partials/opengraph.html index cfc2aca2..b535d1ac 100644 --- a/layouts/partials/opengraph.html +++ b/layouts/partials/opengraph.html @@ -59,20 +59,46 @@ -{{- $keywords := "" }} +{{- $mergedKeywords := slice }} {{- with $s.keywords }} - {{- $keywords = delimit $s.keywords "," }} + {{- range . }} + {{- $mergedKeywords = $mergedKeywords | append . }} + {{- end }} {{- end }} {{- with $p.keywords }} - {{- $keywords = delimit . "," }} + {{- range . }} + {{- $mergedKeywords = $mergedKeywords | append . }} + {{- end }} +{{- end }} +{{- with $s.tags }} + {{- range . }} + {{- $mergedKeywords = $mergedKeywords | append . }} + {{- end }} {{- end }} -{{- with $keywords }} - +{{- with $p.tags }} + {{- range . }} + {{- $mergedKeywords = $mergedKeywords | append . }} + {{- end }} +{{- end }} +{{- $mergedKeywordsString := delimit $mergedKeywords "," }} +{{- with $mergedKeywordsString }} + {{- end }} {{- if eq .Section $s.blogDir -}} {{- $date := ( .Date.Format "2006-02-01") -}} {{- $date := (time .Date) }} {{- $lastMod := (time .Lastmod) }} + {{- $categories := slice }} + {{- with $s.categories }} + {{- range . }} + {{- $categories = $categories | append . }} + {{- end }} + {{- end }} + {{- with $p.categories }} + {{- range . }} + {{- $categories = $categories | append . }} + {{- end }} + {{- end }}