mirror of
https://github.com/McShelby/hugo-theme-relearn.git
synced 2024-11-27 01:33:04 +00:00
theme: make page be servable with uglyURLs=false from the FS by default
This commit is contained in:
parent
f2523234bd
commit
ea266f26fd
3 changed files with 28 additions and 20 deletions
|
@ -1,15 +1,20 @@
|
|||
# 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"
|
||||
# change this to a value appropriate for you; if your site is served from a subdirectory
|
||||
# set it like "https://example.com/mysite/"
|
||||
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 # 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
|
||||
# canonicalization will only be used for the sitemap.xml and index.xml files;
|
||||
# if set to false, a site served from a subdirectory will generate wrong links
|
||||
# inside of the above mentioned files; if you serve the page from the servers root
|
||||
# you are free to set the value to false as recommended by the official Hugo documentation
|
||||
canonifyURLs = true # true -> all relative URLs would instead be canonicalized using baseURL
|
||||
# required value to serve this page from a webserver AND the file system;
|
||||
# if you don't want to serve your page from the file system, you can also set this value
|
||||
# to false
|
||||
relativeURLs = true # true -> rewrite all relative URLs to be relative to the current content
|
||||
# if you set uglyURLs to false, this theme will append 'index.html' to any branch bundle link
|
||||
# so your page can be also served from the file system; if you don't want that,
|
||||
# set disableExplicitIndexURLs=true 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
|
||||
|
@ -32,7 +37,6 @@ 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"
|
||||
|
|
|
@ -80,17 +80,19 @@ 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
|
||||
# If set to true, no index.html will be appended to prettyURLs; this will cause pages not
|
||||
# to be servable from the file system
|
||||
disableExplicitIndexURLs = false
|
||||
```
|
||||
|
||||
## 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`
|
||||
If your site is served from a subfolder, eg. `https://example.com/mysite/`, you have to set the following lines to your `config.toml`
|
||||
|
||||
````toml
|
||||
baseURL = "https://example.com/mysite/"
|
||||
canonifyURLs = true
|
||||
relativeURLs = 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.
|
||||
|
@ -101,15 +103,17 @@ If you want your page served from the filesystem by using URLs starting with `fi
|
|||
|
||||
````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`.
|
||||
The theme will append an additional `index.html` to all branch bundle links by default to make the page be servable from the file system. If you don't care about the file system and only serve your page via a webserver you can also generate the links without this change by adding this to your `config.toml`
|
||||
|
||||
````toml
|
||||
[params]
|
||||
disableExplicitIndexURLs = true
|
||||
````
|
||||
|
||||
{{% 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).
|
||||
If you want to use the search feature from the file system using an older installation of the theme make sure to change your outputformat for the homepage from the now deprecated `JSON` to `SEARCH` [as seen below](#activate-search).
|
||||
{{% /notice %}}
|
||||
|
||||
## Activate search
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
{{- $page := .page }}
|
||||
{{- $to := .to }}
|
||||
{{- $link := $to.RelPermalink }}
|
||||
{{- if and .page.Site.Params.uglyURLs (eq (substr $link -1) "/") }}
|
||||
{{- if and (ne .page.Site.Params.disableExplicitIndexURLs true) (eq (substr $link -1) "/") }}
|
||||
{{- $link = printf "%sindex.html" $link }}
|
||||
{{- end }}
|
||||
{{- $link }}
|
Loading…
Reference in a new issue