mirror of
https://github.com/McShelby/hugo-theme-relearn.git
synced 2024-11-23 07:47:54 +00:00
theme: allow to be served by file:// protocol #349
This commit is contained in:
parent
b692bf44c6
commit
01cfcfe67b
15 changed files with 171 additions and 69 deletions
12
config.toml
12
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
|
||||
|
|
|
@ -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"]
|
||||
|
||||
|
|
|
@ -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"]
|
||||
```
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -33,7 +33,7 @@
|
|||
<p></p>
|
||||
<p>{{ T "message-404" }}</p>
|
||||
<p></p>
|
||||
<p><a href="{{ "" | relLangURL }}">{{ T "Go-to-homepage" }}</a></p>
|
||||
<p><a href="{{ partial "relLangPrettyUglyURL.hugo" (dict "page" . "to" .Site.Home) }}">{{ T "Go-to-homepage" }}</a></p>
|
||||
<p><img src="{{ "images/gopher-404.jpg" | relURL }}" style="width:50%" alt="Page not found!"></p>
|
||||
</article>
|
||||
</div>
|
||||
|
|
8
layouts/_default/index.search.js
Normal file
8
layouts/_default/index.search.js
Normal file
|
@ -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" " ") }}
|
|
@ -2,14 +2,15 @@
|
|||
<html lang="{{ .Page.Language | default "en" }}" dir="ltr">
|
||||
<head>
|
||||
{{- partial "meta.html" . }}
|
||||
{{- $page := . }}
|
||||
{{- $link := "<link href=\"%s\" rel=\"%s\" type=\"%s\" title=\"%s\">" }}
|
||||
<title>{{ if and .Title (not (eq .Title .Site.Title)) }}{{ .Title }} {{ default "::" .Site.Params.titleSeparator }} {{ end}}{{ .Site.Title }}</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 @@
|
|||
<div class="navigation">
|
||||
{{- if and $ispublished ($.Scratch.Get "relearnNextPage") }}
|
||||
{{- with ($.Scratch.Get "relearnNextPage") }}
|
||||
<a class="nav nav-next" href="{{.RelPermalink}}" title="{{.Title}} (🡒)"><i class="fas fa-chevron-right fa-fw"></i></a>
|
||||
<a class="nav nav-next" href="{{ partial "relLangPrettyUglyURL.hugo" (dict "page" $page "to" .) }}" title="{{.Title}} (🡒)"><i class="fas fa-chevron-right fa-fw"></i></a>
|
||||
{{- end }}
|
||||
{{- else }}
|
||||
<span class="nav nav-next"><i class="fa fa-chevron-right fa-fw"></i></span>
|
||||
<span class="nav nav-next"><i class="fa fa-chevron-right fa-fw"></i></span>
|
||||
{{- end }}
|
||||
</div>
|
||||
<div class="navigation">
|
||||
{{- if and $ispublished ($.Scratch.Get "relearnPrevPage") }}
|
||||
{{- with ($.Scratch.Get "relearnPrevPage") }}
|
||||
<a class="nav nav-prev" href="{{.RelPermalink}}" title="{{.Title}} (🡐)"><i class="fas fa-chevron-left fa-fw"></i></a>
|
||||
<a class="nav nav-prev" href="{{ partial "relLangPrettyUglyURL.hugo" (dict "page" $page "to" .) }}" title="{{.Title}} (🡐)"><i class="fas fa-chevron-left fa-fw"></i></a>
|
||||
{{- end}}
|
||||
{{- else }}
|
||||
<span class="nav nav-prev"><i class="fa fa-chevron-left fa-fw"></i></span>
|
||||
<span class="nav nav-prev"><i class="fa fa-chevron-left fa-fw"></i></span>
|
||||
{{- end}}
|
||||
</div>
|
||||
{{- end }}
|
||||
|
@ -91,7 +92,7 @@
|
|||
{{- $showBreadcrumb := (and (not .Params.disableBreadcrumb) (not .Site.Params.disableBreadcrumb)) }}
|
||||
{{- if $showBreadcrumb }}
|
||||
<ol class="links" itemscope itemtype="http://schema.org/BreadcrumbList">
|
||||
{{- template "breadcrumb" dict "page" . }}
|
||||
{{- template "breadcrumb" dict "page" . "to" . }}
|
||||
</ol>
|
||||
{{- else }}
|
||||
<span class="links">
|
||||
|
@ -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 }}
|
||||
<li itemscope itemtype="https://schema.org/ListItem" itemprop="itemListElement">{{ if $remaining }}<a itemprop="item" href="{{ $page.RelPermalink }}">{{end}}<span itemprop="name">{{ if $page.Title }}{{ $page.Title }}{{ else }}{{ $page.Site.Title }}{{ end }}</span>{{ if $remaining }}</a>{{ end }}<meta itemprop="position" content="{{ $depth }}">{{ if $remaining }} > {{ end }}</li>
|
||||
<li itemscope itemtype="https://schema.org/ListItem" itemprop="itemListElement">{{ if $remaining }}<a itemprop="item" href="{{ partial "relLangPrettyUglyURL.hugo" (dict "page" $page "to" $to) }}">{{end}}<span itemprop="name">{{ if $to.Title }}{{ $to.Title }}{{ else }}{{ $to.Site.Title }}{{ end }}</span>{{ if $remaining }}</a>{{ end }}<meta itemprop="position" content="{{ $depth }}">{{ if $remaining }} > {{ end }}</li>
|
||||
{{- end }}
|
||||
{{- end }}
|
||||
{{- end }}
|
|
@ -48,7 +48,7 @@
|
|||
}
|
||||
}
|
||||
</style>
|
||||
<a id="logo" href="{{ .Site.Home.RelPermalink | default ("/" | relLangURL) }}">
|
||||
<a id="logo" href="{{ partial "relLangPrettyUglyURL.hugo" (dict "page" . "to" .Site.Home) }}">
|
||||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 64.044 64.044">
|
||||
<path d="M46.103 136.34c-.642-.394-1.222-2.242-1.98-2.358-.76-.117-1.353.506-1.618 1.519-.266 1.012-.446 4.188.173 5.538.213.435.482.787 1.03.845.547.057.967-.504 1.45-1.027.482-.523.437-.9 1.142-.612.705.289 1.051.4 1.586 1.229.535.828 1.085 4.043.868 5.598-.241 1.458-.531 2.8-.59 4.088.26.075.517.148.772.217 2.68.724 5.373 1.037 7.873.02.001-.028.01-.105.008-.11-.048-.165-.18-.41-.36-.698-.18-.29-.414-.645-.586-1.114a3.212 3.212 0 0 1-.125-1.735c.056-.21.153-.342.249-.475 1.237-1.193 2.932-1.373 4.244-1.384.557-.004 1.389.016 2.198.255.809.239 1.706.724 2.068 1.843.187.578.114 1.17-.043 1.623-.153.438-.369.783-.545 1.091-.178.31-.329.6-.401.821-.007.02-.003.071-.005.094 2.256 1.008 4.716.91 7.189.398.55-.114 1.11-.247 1.673-.377.344-1.085.678-2.145.852-3.208.124-.752.158-2.311-.078-3.538-.118-.613-.306-1.15-.52-1.489-.221-.349-.413-.501-.747-.538-.243-.027-.51.013-.796.098-.67.223-1.33.606-1.966.76l-.008.002-.109.032c-.556.152-1.233.158-1.797-.36-.556-.51-.89-1.367-1.117-2.596-.283-1.528-.075-3.279.89-4.518l.071-.09h.07c.65-.71 1.485-.802 2.16-.599.706.213 1.333.629 1.772.84.736.354 1.185.319 1.475.171.291-.148.5-.439.668-.955.332-1.017.301-2.819.022-4.106-.148-.684-.13-1.292-.13-1.883-1.558-.463-3.067-.982-4.574-1.208-1.128-.169-2.263-.173-3.298.164-.13.046-.256.095-.38.15-.373.164-.633.342-.805.52-.077.098-.081.105-.087.21-.004.068.031.289.13.571.1.282.256.634.467 1.03.279.524.448 1.063.431 1.618a2.12 2.12 0 0 1-.499 1.309 1.757 1.757 0 0 1-.62.51h-.002c-.515.291-1.107.404-1.723.464-.86.083-1.787.026-2.598-.097-.806-.123-1.47-.28-1.948-.555-.444-.256-.79-.547-1.037-.925a2.273 2.273 0 0 1-.356-1.301c.029-.837.403-1.437.625-1.897.111-.23.191-.433.236-.583.045-.15.044-.25.046-.24-.005-.029-.127-.355-1.015-.741-1.138-.495-2.322-.673-3.533-.668h-.015a9.711 9.711 0 0 0-.521.016h-.002c-1.163.057-2.35.308-3.541.569.383 1.531.79 2.753.818 4.502-.096 1.297.158 2.114-1.03 2.935-.85.588-1.508.729-2.15.335" style="fill:#282828;fill-opacity:1;stroke:none;stroke-width:1.03763;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1" transform="translate(-40.698 -95.175)"/>
|
||||
<path d="M61.472 101.34v.002c-.3-.003-.603.01-.894.04-.544.055-1.39.165-1.778.306-1.238.364.13 2.344.41 2.913.28.569.285 2.03.14 2.134-.144.103-.375.261-.934.345-.56.084.03-.037-1.589.086-1.62.122-5.506.29-8.265.248-.022.26-.036.521-.097.808-.309 1.442-.63 3.163-.494 4.074.071.473.168.65.414.8.23.14.737.235 1.62-.004.834-.227 1.3-.442 1.887-.456.595-.016 1.555.472 1.965.717.411.245-.03-.008.002 0s.128.05.176.102c.049.053-.276-.523.104.199.379.721.72 3.256.002 4.68-.46.913-1.01 1.49-1.64 1.711-.63.22-1.229.067-1.734-.135-.881-.353-1.584-.7-2.205-.647-1.199 1.94-1.186 4.17-.6 6.602.097.397.212.814.327 1.23 2.68-.556 5.542-1.016 8.337.132 1.064.437 1.73 1.015 1.902 1.857.169.831-.193 1.508-.438 1.986-.122.238-.23.46-.307.642-.07.164-.096.28-.104.324.069.429.309.723.686.945.385.227.89.355 1.35.423.723.104 1.567.152 2.287.086.693-.064 1.032-.338 1.241-.544a2.447 2.447 0 0 0 .303-.437.175.175 0 0 0 .013-.035c-.004-.066-.037-.246-.195-.527-.46-.816-.87-1.595-.817-2.51.028-.476.218-.938.529-1.288.304-.343.698-.586 1.186-.79 1.442-.606 2.96-.609 4.372-.409 1.525.216 2.963.679 4.378 1.083.226-2.09.784-3.9.592-5.77-.058-.565-.287-1.333-.598-1.827-.32-.508-.59-.717-1.036-.642-.648.11-1.472.935-2.707 1.078-.791.092-1.494-.267-1.95-.86-.45-.583-.678-1.335-.78-2.101-.202-1.525.031-3.229.89-4.27.615-.747 1.45-.887 2.15-.74.687.145 1.307.492 1.857.745v-.002c.546.252 1.033.388 1.281.344a.547.547 0 0 0 .353-.188c.113-.124.242-.35.384-.75.604-1.712.206-3.68-.303-5.654-.667.145-1.336.293-2.018.413-1.341.236-2.73.392-4.136.273-.656-.055-1.695-.085-2.58-.476-.442-.195-.903-.514-1.157-1.093-.259-.591-.205-1.313.08-2.014.223-.64 1.082-2.178.692-2.585-.391-.407-1.651-.56-2.554-.571z" style="fill:#282828;fill-opacity:1;stroke:none;stroke-width:.992837;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1" transform="translate(-40.698 -95.175)"/>
|
||||
|
|
|
@ -14,7 +14,7 @@
|
|||
<div id="homelinks" class="default-animation">
|
||||
<ul>
|
||||
<li>
|
||||
<a class="padding" href="{{ .Site.Home.RelPermalink | default ("/" | relLangURL) }}">{{ .Site.Params.landingPageName | default `<i class="fas fa-home"></i> Home` | safeHTML }}</a>
|
||||
<a class="padding" href="{{ partial "relLangPrettyUglyURL.hugo" (dict "page" . "to" .Site.Home) }}">{{ .Site.Params.landingPageName | default `<i class="fas fa-home"></i> Home` | safeHTML }}</a>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
|
@ -34,13 +34,20 @@
|
|||
{{- end }}
|
||||
{{- end }}
|
||||
</ul>
|
||||
{{- $page := . }}
|
||||
{{- $disableShortcutsTitle := .Site.Params.DisableShortcutsTitle }}
|
||||
{{- with .Site.Menus.shortcuts }}
|
||||
<div id="shortcuts">
|
||||
<div class="nav-title">{{ if not $disableShortcutsTitle }}{{ T "Shortcuts-Title" }}{{ end }}</div>
|
||||
<ul>
|
||||
{{- range sort . "Weight" }}
|
||||
<li>{{ .Pre }}<a class="padding" href="{{ .URL | relLangURL }}">{{ safeHTML .Name }}</a>{{ .Post }}</li>
|
||||
{{- $shortcut := . }}
|
||||
{{- with $page.Site.GetPage (printf "%s" $shortcut.URL ) }}
|
||||
{{- $to := . }}
|
||||
<li>{{ $shortcut.Pre }}<a class="padding" href="{{ partial "relLangPrettyUglyURL.hugo" (dict "page" $page "to" $to) }}">{{ safeHTML $shortcut.Name }}</a>{{ $shortcut.Post }}</li>
|
||||
{{- else }}
|
||||
<li>{{ $shortcut.Pre }}<a class="padding" href="{{ $shortcut.URL | relLangURL }}">{{ safeHTML $shortcut.Name }}</a>{{ $shortcut.Post }}</li>
|
||||
{{- end }}
|
||||
{{- end }}
|
||||
</ul>
|
||||
</div>
|
||||
|
@ -62,15 +69,16 @@
|
|||
<div class="select-style">
|
||||
<label class="a11y-only" for="select-language">{{ T "Language" }}</label>
|
||||
<select id="select-language" onchange="location = baseUri + this.value;">
|
||||
{{- $page := .Page }}
|
||||
{{- $pageLang := .Page.Lang }}
|
||||
{{- range .Page.AllTranslations }}
|
||||
{{- $translation := . }}
|
||||
{{- range $siteLanguages }}
|
||||
{{- if eq $translation.Lang .Lang }}
|
||||
{{- if eq $pageLang .Lang }}
|
||||
<option lang="{{ $translation.Lang }}" id="{{ $translation.Lang }}" value="{{ $translation.RelPermalink }}" selected>{{ .LanguageName }}</option>
|
||||
<option lang="{{ $translation.Lang }}" id="{{ $translation.Lang }}" value="{{ partial "relLangPrettyUglyURL.hugo" (dict "page" $page "to" $translation "isTranslation" true) }}" selected>{{ .LanguageName }}</option>
|
||||
{{- else }}
|
||||
<option lang="{{ $translation.Lang }}" id="{{ $translation.Lang }}" value="{{ $translation.RelPermalink }}">{{ .LanguageName }}</option>
|
||||
<option lang="{{ $translation.Lang }}" id="{{ $translation.Lang }}" value="{{ partial "relLangPrettyUglyURL.hugo" (dict "page" $page "to" $translation "isTranslation" true) }}">{{ .LanguageName }}</option>
|
||||
{{- end }}
|
||||
{{- end }}
|
||||
{{- end }}
|
||||
|
|
|
@ -4,11 +4,11 @@
|
|||
{{- $currentNode := . }}
|
||||
{{- $isActive := .IsHome }}
|
||||
{{- $isShortcut := false }}
|
||||
{{- $r_url := .RelPermalink }}
|
||||
{{- with .Site.Menus.shortcuts }}
|
||||
{{- range sort . "Weight" }}
|
||||
{{- $s_url := .URL | relLangURL }}
|
||||
{{- if (eq $s_url $r_url) }}
|
||||
{{- $shortcut := . }}
|
||||
{{- $shortcutPage := $page.Site.GetPage (printf "%s" $shortcut.URL ) }}
|
||||
{{- if and $shortcutPage (eq $shortcutPage.RelPermalink $page.RelPermalink) }}
|
||||
{{- $isShortcut = true }}
|
||||
{{- end }}
|
||||
{{- end }}
|
||||
|
|
10
layouts/partials/relLangPrettyUglyURL.hugo
Normal file
10
layouts/partials/relLangPrettyUglyURL.hugo
Normal file
|
@ -0,0 +1,10 @@
|
|||
{{- $page := .page }}
|
||||
{{- $to := .to }}
|
||||
{{- $link := $to.RelPermalink }}
|
||||
{{- if not .isTranslation }}
|
||||
{{- $link = $link | relLangURL }}
|
||||
{{- end }}
|
||||
{{- if and .page.Site.Params.uglyURLs (eq (substr $link -1) "/") }}
|
||||
{{- $link = printf "%sindex.html" $link }}
|
||||
{{- end }}
|
||||
{{- $link }}
|
|
@ -21,7 +21,12 @@
|
|||
<script>
|
||||
{{ "// hack to let hugo tell us how to get to the root when using relativeURLs, it needs to be called *url= for it to do its magic:" | safeJS }}
|
||||
{{ "// https://github.com/gohugoio/hugo/blob/145b3fcce35fbac25c7033c91c1b7ae6d1179da8/transform/urlreplacers/absurlreplacer.go#L72" | safeJS }}
|
||||
var index_url={{ "index.json" | relLangURL }};
|
||||
{{- with .Site.Home.OutputFormats.Get "JSON" }}
|
||||
window.index_json_url={{ "index.json" | relLangURL }};
|
||||
{{- end }}
|
||||
{{- with .Site.Home.OutputFormats.Get "SEARCH" }}
|
||||
window.index_js_url={{ "index.search.js" | relLangURL }};
|
||||
{{- end }}
|
||||
var root_url="/";
|
||||
var baseUri=root_url.replace(/\/$/, '');
|
||||
{{ "// translations" | safeJS }}
|
||||
|
|
|
@ -1,8 +1,13 @@
|
|||
|
||||
{{- $page := . }}
|
||||
{{- if .Params.tags }}
|
||||
<div class="tags" dir="{{ T "Reading-direction" | default "ltr" }}">
|
||||
{{- range sort .Params.tags }}
|
||||
<a class="tag-link" href="{{ "/tags/" | relLangURL }}{{ . | urlize }}">{{ . }}</a>
|
||||
{{- $tag := . }}
|
||||
{{- with $page.Site.GetPage (printf "%s%s" ("/tags/" | relURL ) ( $tag | urlize ) ) }}
|
||||
{{- $to := . }}
|
||||
<a class="tag-link" href="{{ partial "relLangPrettyUglyURL.hugo" (dict "page" $page "to" $to) }}">{{ $tag }}</a>
|
||||
{{- end }}
|
||||
{{- end }}
|
||||
</div>
|
||||
{{- end }}
|
|
@ -1,40 +1,65 @@
|
|||
var lunrIndex, pagesIndex;
|
||||
|
||||
// Initialize lunrjs using our generated index file
|
||||
function initLunr() {
|
||||
// First retrieve the index file
|
||||
$.getJSON(index_url)
|
||||
function initLunrIndex( index ){
|
||||
pagesIndex = index;
|
||||
// Set up lunrjs by declaring the fields we use
|
||||
// Also provide their boost level for the ranking
|
||||
lunrIndex = lunr(function() {
|
||||
this.use(lunr.multiLanguage.apply(null, contentLangs));
|
||||
this.ref('index');
|
||||
this.field('title', {
|
||||
boost: 15
|
||||
});
|
||||
this.field('tags', {
|
||||
boost: 10
|
||||
});
|
||||
this.field('content', {
|
||||
boost: 5
|
||||
});
|
||||
|
||||
this.pipeline.remove(lunr.stemmer);
|
||||
this.searchPipeline.remove(lunr.stemmer);
|
||||
|
||||
// Feed lunr with each file and let lunr actually index them
|
||||
pagesIndex.forEach(function(page, idx) {
|
||||
page.index = idx;
|
||||
this.add(page);
|
||||
}, this);
|
||||
})
|
||||
}
|
||||
|
||||
function initLunrJson() {
|
||||
// old way to load the search index via XHR;
|
||||
// this does not work if pages are served via
|
||||
// file:// protocol; this is only left for
|
||||
// backward compatiblity if the user did not
|
||||
// define the SEARCH output format for the homepage
|
||||
if( window.index_json_url && !window.index_js_url ){
|
||||
$.getJSON(index_json_url)
|
||||
.done(function(index) {
|
||||
pagesIndex = index;
|
||||
// Set up lunrjs by declaring the fields we use
|
||||
// Also provide their boost level for the ranking
|
||||
lunrIndex = lunr(function() {
|
||||
this.use(lunr.multiLanguage.apply(null, contentLangs));
|
||||
this.ref('index');
|
||||
this.field('title', {
|
||||
boost: 15
|
||||
});
|
||||
this.field('tags', {
|
||||
boost: 10
|
||||
});
|
||||
this.field('content', {
|
||||
boost: 5
|
||||
});
|
||||
|
||||
this.pipeline.remove(lunr.stemmer);
|
||||
this.searchPipeline.remove(lunr.stemmer);
|
||||
|
||||
// Feed lunr with each file and let lunr actually index them
|
||||
pagesIndex.forEach(function(page, idx) {
|
||||
page.index = idx;
|
||||
this.add(page);
|
||||
}, this);
|
||||
})
|
||||
initLunrIndex(index);
|
||||
})
|
||||
.fail(function(jqxhr, textStatus, error) {
|
||||
var err = textStatus + ', ' + error;
|
||||
console.error('Error getting Hugo index file:', err);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
function initLunrJs() {
|
||||
// new way to load our search index
|
||||
if( window.index_js_url ){
|
||||
var js = document.createElement("script");
|
||||
js.src = index_js_url;
|
||||
js.setAttribute("async", "");
|
||||
js.onload = function(){
|
||||
initLunrIndex(relearn_search_index);
|
||||
};
|
||||
js.onerror = function(e){
|
||||
console.error('Error getting Hugo index file');
|
||||
};
|
||||
document.head.appendChild(js);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -62,7 +87,8 @@ function searchPatterns(word) {
|
|||
}
|
||||
|
||||
// Let's get started
|
||||
initLunr();
|
||||
initLunrJson();
|
||||
initLunrJs();
|
||||
$(function() {
|
||||
var searchList = new autoComplete({
|
||||
/* selector for the search box element */
|
||||
|
|
Loading…
Reference in a new issue