diff --git a/config.toml b/config.toml index cfd52b66fd..693086c05a 100644 --- a/config.toml +++ b/config.toml @@ -2,6 +2,10 @@ [module.hugoVersion] min = "0.95.0" +[mediaTypes] + [mediaTypes."text/javascript"] + suffixes = ["js"] + [outputFormats] [outputFormats.PRINT] name= "PRINT" @@ -10,3 +14,11 @@ mediaType = 'text/html' permalinkable = false noUgly = true + + [outputFormats.SEARCH] + name= "SEARCH" + baseName = "index.search" + isPlainText = true + mediaType = 'text/javascript' + permalinkable = false + noUgly = true diff --git a/exampleSite/config.toml b/exampleSite/config.toml index 2fcc478c81..83a6643529 100644 --- a/exampleSite/config.toml +++ b/exampleSite/config.toml @@ -1,11 +1,16 @@ # this is a required setting for this theme to appear on https://themes.gohugo.io/ # change this to a value appropriate for you baseURL = "https://example.com" + # as the official Hugo documentation recommends, we turn this off for this # showcase; this allows the published site to be served by both http and https -canonifyURLs = false -# required for official documentation served from subfolder -relativeURLs = false +canonifyURLs = false # true -> all relative URLs would instead be canonicalized using baseURL + +# required for this documentation to be served from subfolder +relativeURLs = false # true -> rewrite all relative URLs to be relative to the current content + +# if you set uglyURLs to true, don't forget to set it also in the [params] section +uglyURLs = false # true -> basic/index.html -> basic.html # the directory where Hugo reads the themes from; this is specific to your # installation and most certainly needs be deleted or changed @@ -27,6 +32,7 @@ title = "Hugo Relearn Documentation" # settings specific to this theme's features; choose to your likings and # consult this documentation for explaination [params] + uglyURLs = false # see uglyURLs setting above editURL = "https://github.com/McShelby/hugo-theme-relearn/edit/main/exampleSite/content/" description = "Documentation for Hugo Relearn Theme" author = "Sören Weber" @@ -49,7 +55,7 @@ title = "Hugo Relearn Documentation" # for the search functionality # add PRINT to home, section and page to activate the feature to print whole # chapters - home = ["HTML", "RSS", "PRINT", "JSON"] + home = ["HTML", "RSS", "PRINT", "SEARCH"] section = ["HTML", "RSS", "PRINT"] page = ["HTML", "RSS", "PRINT"] diff --git a/exampleSite/content/basics/configuration/_index.en.md b/exampleSite/content/basics/configuration/_index.en.md index 735a12e3ad..404c85255b 100644 --- a/exampleSite/content/basics/configuration/_index.en.md +++ b/exampleSite/content/basics/configuration/_index.en.md @@ -80,9 +80,11 @@ Note that some of these parameters are explained in details in other sections of collapsibleMenu = false # If a single page can contain content in multiple languages, add those here additionalContentLanguage = [ "en" ] + # Must be set to the same value as the global uglyURLs setting; this adds 'index.html' to all home links if set to true + uglyURLs = false ``` -## A word on running your site in a subfolder +## Serving your page from a subfolder The theme runs best if your site is installed in the root of your webserver. If your site is served from a subfolder, eg. `https://example.com/mysite/`, you have to set the following lines to your `config.toml` @@ -93,19 +95,33 @@ canonifyURLs = true Without `canonifyURLs=true` URLs in sublemental pages (like `sitemap.xml`, `rss.xml`) will be generated falsly while your HTML files will still work. See https://github.com/gohugoio/hugo/issues/5226. +## Serving your page from the filesystem + +If you want your page served from the filesystem by using URLs starting with `file://` you'll need the following configuration in your `config.toml`: + +````toml +relativeURLs = true +uglyURLs = true +[params] + uglyURLs = true +```` + +Because the global `uglyURLs` setting is not queryable in the theme's code, you'll have to set this option also in the `[params]` section of your `config.toml`. + +{{% notice note %}} +If you want to use the search feature with an existing installation make sure to change your outputformat for the homepage from the now deprecated `JSON` to `SEARCH` [as seen below](#activate-search). +{{% /notice %}} + ## Activate search -If not already present, add the follow lines in the same `config.toml` file. +If not already present, add the following lines in the same `config.toml` file. ```toml [outputs] - home = ["HTML", "RSS", "JSON"] + home = ["HTML", "RSS", "SEARCH"] ``` -Relearn theme uses the last improvement available in hugo version 20+ to generate a json index file ready to be consumed by lunr.js javascript search engine. - -> Hugo generate lunrjs index.json at the root of public folder. -> When you build the site with `hugo server`, hugo generates it internally and of course it doesn’t show up in the filesystem +This will generate a search index file at the root of your public folder ready to be consumed by the lunr.js javascript search engine. ## Activate print support @@ -113,7 +129,7 @@ You can activate print support to add the capability to print whole chapters or ```toml [outputs] - home = ["HTML", "RSS", "PRINT", "JSON"] + home = ["HTML", "RSS", "PRINT", "SEARCH"] section = ["HTML", "RSS", "PRINT"] page = ["HTML", "RSS", "PRINT"] ``` diff --git a/exampleSite/content/basics/installation/_index.en.md b/exampleSite/content/basics/installation/_index.en.md index 884b306dfa..16a08f6952 100644 --- a/exampleSite/content/basics/installation/_index.en.md +++ b/exampleSite/content/basics/installation/_index.en.md @@ -31,7 +31,7 @@ theme = "hugo-theme-relearn" # For search functionality [outputs] -home = [ "HTML", "RSS", "JSON"] +home = [ "HTML", "RSS", "SEARCH"] ``` ## Create your first chapter page diff --git a/exampleSite/content/basics/migration/_index.en.md b/exampleSite/content/basics/migration/_index.en.md index 91970e3f36..10afa037f2 100644 --- a/exampleSite/content/basics/migration/_index.en.md +++ b/exampleSite/content/basics/migration/_index.en.md @@ -16,6 +16,10 @@ This document shows you what's new in the latest release. For a detailed list of ## 5.4.0 +- **Change**: [With the proper settings]({{% relref "basics/configuration#serving-your-page-from-the-filesystem" %}}) in your `config.toml` your page is now servable from the local file system using `file://` URLs. + + Please note that the searchbox will only work for this if you reconfigure your outputformat for the homepage in your `config.toml` from `JSON` to `SEARCH`. The now deprecated `JSON` outputformat still works as before, so there is no need to reconfigure your installation if it is only served from `http://` or `https://`. + - **Change**: The [`button` shortcode]({{% relref "shortcodes/button" %}}) has a new parameter `target` to set the destination frame/window for the URL to open. If not given, it defaults to a new window/tab for external URLs or is not set at all for internal URLs. Previously even internal URLs where opened in a new window/tab. - **New**: The [`math` shortcode]({{% relref "shortcodes/math" %}}) and [`mermaid` shortcode]({{% relref "shortcodes/mermaid" %}}) now also support the `align` parameter if codefence syntax is used. diff --git a/layouts/404.html b/layouts/404.html index 42cefa3b66..b23049cbc2 100644 --- a/layouts/404.html +++ b/layouts/404.html @@ -33,7 +33,7 @@

{{ T "message-404" }}

-

{{ T "Go-to-homepage" }}

+

{{ T "Go-to-homepage" }}

Page not found!

diff --git a/layouts/_default/index.search.js b/layouts/_default/index.search.js new file mode 100644 index 0000000000..216a1a343f --- /dev/null +++ b/layouts/_default/index.search.js @@ -0,0 +1,8 @@ +{{- partial "page-meta.hugo" . }} +{{- $pages := slice }} +{{- range .Site.Pages }} +{{- if and .Title (or (ne (.Scratch.Get "relearnIsHiddenStem") true) (ne .Site.Params.disableSearchHiddenPages true) ) }} +{{- $pages = $pages | append (dict "uri" .RelPermalink "title" .Title "tags" .Params.tags "description" .Description "content" (.Plain | htmlUnescape)) }} +{{- end }} +{{- end -}} +var relearn_search_index = {{ $pages | jsonify (dict "indent" " ") }} diff --git a/layouts/partials/header.html b/layouts/partials/header.html index 8f1f6bb0fa..3a2bfeb104 100644 --- a/layouts/partials/header.html +++ b/layouts/partials/header.html @@ -2,14 +2,15 @@ {{- partial "meta.html" . }} + {{- $page := . }} {{- $link := "" }} {{ if and .Title (not (eq .Title .Site.Title)) }}{{ .Title }} {{ default "::" .Site.Params.titleSeparator }} {{ end}}{{ .Site.Title }} {{- if not (and .Title (or (ne (.Scratch.Get "relearnIsHiddenStem") true) (ne .Site.Params.disableSeoHiddenPages true) ) ) }} {{- else }} {{- range .AlternativeOutputFormats }} - {{- if ne .Name "JSON" }} - {{ (printf $link (.Permalink | relURL) .Rel .MediaType.Type ($.Site.Title | htmlEscape)) | safeHTML }} + {{- if and (ne .Name "JSON") (ne .Name "SEARCH") }} + {{ (printf $link (partial "relLangPrettyUglyURL.hugo" (dict "page" $page "to" .)) .Rel .MediaType.Type ($.Site.Title | htmlEscape)) | safeHTML }} {{- end }} {{- end }} {{- end }} @@ -41,19 +42,19 @@ {{- end }} @@ -91,7 +92,7 @@ {{- $showBreadcrumb := (and (not .Params.disableBreadcrumb) (not .Site.Params.disableBreadcrumb)) }} {{- if $showBreadcrumb }} {{- else }} @@ -112,11 +113,12 @@ {{- define "breadcrumb" }} {{- $breadcrumb := slice }} {{- $page := .page }} - {{- $breadcrumb = $breadcrumb | append $page }} - {{- range seq (len .page.Site.Home.Pages) }} - {{- $page = $page.Parent }} - {{- if $page }} - {{- $breadcrumb = $breadcrumb | append $page }} + {{- $to := .to }} + {{- $breadcrumb = $breadcrumb | append $to }} + {{- range seq (len .to.Site.Home.Pages) }} + {{- $to = $to.Parent }} + {{- if $to }} + {{- $breadcrumb = $breadcrumb | append $to }} {{- else }} {{- break }} {{- end }} @@ -129,12 +131,12 @@ {{- $remaining := $len }} {{- $depth := 0 }} {{- range $i, $e := $breadcrumbReversed }} - {{- $page := $e }} - {{- $ispublished := gt (int (len $page.Permalink)) 0 }} + {{- $to := $e }} + {{- $ispublished := gt (int (len $to.Permalink)) 0 }} {{- $remaining = sub $remaining 1 }} {{- if $ispublished }} {{- $depth = add $depth 1 }} -
  • {{ if $remaining }}{{end}}{{ if $page.Title }}{{ $page.Title }}{{ else }}{{ $page.Site.Title }}{{ end }}{{ if $remaining }}{{ end }}{{ if $remaining }} > {{ end }}
  • +
  • {{ if $remaining }}{{end}}{{ if $to.Title }}{{ $to.Title }}{{ else }}{{ $to.Site.Title }}{{ end }}{{ if $remaining }}{{ end }}{{ if $remaining }} > {{ end }}
  • {{- end }} {{- end }} {{- end }} \ No newline at end of file diff --git a/layouts/partials/logo.html b/layouts/partials/logo.html index 3fbde880ee..ddec0a554e 100644 --- a/layouts/partials/logo.html +++ b/layouts/partials/logo.html @@ -48,7 +48,7 @@ } } - @@ -34,13 +34,20 @@ {{- end }} {{- end }} + {{- $page := . }} {{- $disableShortcutsTitle := .Site.Params.DisableShortcutsTitle }} {{- with .Site.Menus.shortcuts }}
    @@ -62,15 +69,16 @@