hugo-theme-relearn/exampleSite/content/basics/customization/_index.en.md

278 lines
13 KiB
Markdown
Raw Normal View History

+++
title = "Customization"
weight = 25
+++
2017-09-04 17:14:13 +00:00
## Usage scenarios
2017-09-04 17:14:13 +00:00
The theme is usable in different scenarios, requiring the following mandatory settings in your `hugo.toml`. All settings not mentioned can be set to your liking.
2024-04-12 15:30:16 +00:00
### Public Web Server from Root
2024-03-02 10:04:52 +00:00
{{< multiconfig file=hugo >}}
baseURL = "https://example.com/"
2024-03-02 10:04:52 +00:00
{{< /multiconfig >}}
2024-04-12 15:30:16 +00:00
### Public Web Server from Subdirectory
2017-09-04 17:14:13 +00:00
2024-03-02 10:04:52 +00:00
{{< multiconfig file=hugo >}}
2023-11-20 23:53:33 +00:00
baseURL = "https://example.com/mysite/"
relativeURLs = false
2024-03-02 10:04:52 +00:00
{{< /multiconfig >}}
2023-06-09 22:21:58 +00:00
2024-04-12 15:30:16 +00:00
### Private Web Server (LAN)
2017-09-04 17:14:13 +00:00
2024-04-12 15:30:16 +00:00
The same settings as with any of the public web server usage scenarios or
2017-09-04 17:14:13 +00:00
2024-03-02 10:04:52 +00:00
{{< multiconfig file=hugo >}}
baseURL = "/"
2023-11-20 23:53:33 +00:00
relativeURLs = true
2024-03-02 10:04:52 +00:00
{{< /multiconfig >}}
2017-09-04 17:14:13 +00:00
### File System
2021-10-30 20:00:46 +00:00
2024-03-02 10:04:52 +00:00
{{< multiconfig file=hugo >}}
baseURL = "/"
relativeURLs = true
2024-03-02 10:04:52 +00:00
{{< /multiconfig >}}
{{% notice warning %}}
2024-04-12 15:30:16 +00:00
Using a `baseURL` with a subdirectory and `relativeURLs=true` are mutually exclusive due to the fact, that [Hugo does not apply the `baseURL` correctly](https://github.com/gohugoio/hugo/issues/12130).
If you need both, you have to generate your site twice but with different settings into separate directories.
2024-02-24 12:49:46 +00:00
{{% /notice %}}
{{% notice note %}}
Sublemental pages (like `sitemap.xml`, `rss.xml`) and generated social media links inside of your pages will always be generated with absolute URLs and will not work if you set `relativeURLs=true`.
{{% /notice %}}
{{% notice info %}}
2024-04-12 15:30:16 +00:00
If you are using `uglyURLs=false` (Hugo's default), the theme will append an additional `index.html` to all page links to make your site be servable from the file system. If you don't care about the file system and only serve your page via a web server you can generate the links without this:
2024-02-24 14:39:25 +00:00
2024-03-02 10:04:52 +00:00
{{< multiconfig file=hugo >}}
[params]
disableExplicitIndexURLs = true
2024-03-02 10:04:52 +00:00
{{< /multiconfig >}}
2024-02-24 14:39:25 +00:00
{{% /notice %}}
2024-08-26 22:06:23 +00:00
## Configure Search
2017-09-04 17:14:13 +00:00
2024-08-26 22:06:23 +00:00
The theme comes with three levels of search, all provided through the search form in the menu:
2017-09-04 17:14:13 +00:00
2024-08-26 22:06:23 +00:00
- in-page search: a found search term will be marked in the currently displayed page
- search popup: if a search index is generated, a popup will open during typing in the search form, if the term is found in other pages of your site
- dedicated search page: access the dedicated search page by either clicking on the magnifier glass or by typing some search term in the search form and pressing `ENTER`
2024-08-26 22:06:23 +00:00
Each level depends on the previous level to be enabled, eg. the dedicated search page is only available, if you have search popup and in-page search enabled.
2023-10-05 16:13:52 +00:00
2024-08-26 22:06:23 +00:00
By default all three levels are enabled. You can disable each level by the following settings in your `hugo.toml`:
2023-10-05 16:13:52 +00:00
2024-08-26 22:06:23 +00:00
- in-page search: `disableSearch=true`
- search popup: `disableSearchIndex=true`
- dedicated search page: `disableSearchPage=true`
2023-10-05 16:13:52 +00:00
2024-08-26 22:06:23 +00:00
By default the following files will be created for each level, relative to each languages home page but can be overwritten:
2023-10-05 12:59:27 +00:00
2024-08-26 22:06:23 +00:00
- search popup: `search_index.js`, configured by `searchIndexURL`
- dedicated search page: either `/search.html` or `search/index.html` depending on your settings for `uglyURLs`, configured by `searchPageURL`
2023-10-05 12:59:27 +00:00
2023-11-20 23:53:33 +00:00
{{% notice note %}}
2024-08-26 22:06:23 +00:00
You only need to reconfigure the file / page URLs if you have own content at those URLs in your project. Eg. this can happen if you set `uglyURLs=true` in your `hugo.toml` and defining a Markdown file `content/search.md`.
2021-07-01 14:25:08 +00:00
2023-11-20 23:53:33 +00:00
To make sure, there is no duplicate content for any given URL of your project, run `hugo --printPathWarnings`.
{{% /notice %}}
2021-07-01 14:25:08 +00:00
2023-11-20 23:53:33 +00:00
## Activate print support
2017-09-04 17:14:13 +00:00
You can activate print support to add the capability to print whole chapters or even the complete site. Just add the `print` output format to your home, section and page in your `hugo.toml` as seen below:
2017-09-04 17:14:13 +00:00
2024-03-02 10:04:52 +00:00
{{< multiconfig file=hugo >}}
2023-11-20 23:53:33 +00:00
[outputs]
home = ["html", "rss", "print"]
section = ["html", "rss", "print"]
page = ["html", "rss", "print"]
2024-03-02 10:04:52 +00:00
{{< /multiconfig >}}
2017-09-04 17:14:13 +00:00
2023-11-20 23:53:33 +00:00
This will add a little printer icon in the top bar. It will switch the page to print preview when clicked. You can then send this page to the printer by using your browser's usual print functionality.
2022-02-13 00:53:23 +00:00
2023-11-20 23:53:33 +00:00
{{% notice note %}}
The resulting URL will not be [configured ugly](https://gohugo.io/templates/output-formats/#configure-output-formats) in terms of [Hugo's URL handling](https://gohugo.io/content-management/urls/#ugly-urls) even if you've set `uglyURLs=true` in your `hugo.toml`. This is due to the fact that for one mime type only one suffix can be configured.
Nevertheless, if you're unhappy with the resulting URLs you can manually redefine `outputFormats.print` in your own `hugo.toml` to your liking.
{{% /notice %}}
2022-02-21 23:04:16 +00:00
2023-11-20 23:53:33 +00:00
## Home Button Configuration
2023-11-20 23:53:33 +00:00
If the `disableLandingPageButton` option is set to `false`, a Home button will appear
on the left menu. It is an alternative for clicking on the logo. To edit the
appearance, you will have to configure the `landingPageName` for the defined languages:
2024-03-02 10:04:52 +00:00
{{< multiconfig file=hugo >}}
2023-11-20 23:53:33 +00:00
[languages]
[languages.en]
[languages.en.params]
landingPageName = "<i class='fa-fw fas fa-home'></i> Home"
2023-11-20 23:53:33 +00:00
[languages.pir]
[languages.pir.params]
landingPageName = "<i class='fa-fw fas fa-home'></i> Arrr! Homme"
2024-03-02 10:04:52 +00:00
{{< /multiconfig >}}
2023-11-20 23:53:33 +00:00
If this option is not configured for a specific language, they will get their default values:
2024-03-02 10:04:52 +00:00
{{< multiconfig >}}
landingPageName = "<i class='fa-fw fas fa-home'></i> Home"
2024-03-02 10:04:52 +00:00
{{< /multiconfig >}}
2023-11-20 23:53:33 +00:00
The home button is going to look like this:
2023-02-04 22:38:09 +00:00
2023-11-20 23:53:33 +00:00
![Default Home Button](home_button_defaults.png?width=18.75rem)
2023-11-20 23:53:33 +00:00
## Social Media Meta Tags
2023-11-20 23:53:33 +00:00
You can add social media meta tags for the [Open Graph](https://gohugo.io/templates/internal/#open-graph) protocol and [Twitter Cards](https://gohugo.io/templates/internal/#twitter-cards) to your site. These are configured as mentioned in the Hugo docs.
2023-11-20 23:53:33 +00:00
## Change the Menu Width
2023-11-20 23:53:33 +00:00
The menu width adjusts automatically for different screen sizes.
2022-02-21 23:04:16 +00:00
2023-11-20 23:53:33 +00:00
| Name | Screen Width | Menu Width |
| ---- | ------------- | ---------- |
2024-01-21 13:19:44 +00:00
| S | < 48rem | 14.375rem |
2023-11-20 23:53:33 +00:00
| M | 48rem - 60rem | 14.375rem |
| L | >= 60rem | 18.75rem |
The values for the screen width breakpoints aren't configurable.
If you want to adjust the menu width you can define the following CSS variables in your `custom-header.html`. Note that `--MENU-WIDTH-S` applies to the menu flyout width in mobile mode for small screen sizes.
2023-11-20 23:53:33 +00:00
````css
:root {
--MENU-WIDTH-S: 14.375rem;
2023-11-20 23:53:33 +00:00
--MENU-WIDTH-M: 14.375rem;
--MENU-WIDTH-L: 18.75rem;
}
````
2024-03-11 22:52:26 +00:00
## Change the Main Area's Max Width
By default the main area width will only grow to a certain extent if more vertical screen space is available. This is done for readability purposes as long line are usually harder to read.
If you are unhappy with the default, you can define the following CSS variable in your `custom-header.html` and set the value to your liking. If you want to use all available space, select a really big value like `1000rem`;
````css
:root {
--MAIN-WIDTH-MAX: 80.25rem;
}
````
## Change Heading Anchor Behavior
Each heading may have an anchor link that is displayed when the heading is hovered.
The behavior what should happen if the anchor icon is clicked is configurable in your `hugo.toml`. By default all options are activated. If you deactivate all options, no link will be shown on hover.
{{< multiconfig file=hugo >}}
[params]
disableAnchorCopy = false
disableAnchorScrolling = false
{{< /multiconfig >}}
### `disableAnchorCopy`
If set to `true`, this disables the copying of anchor links to the clipboard.
### `disableAnchorScrolling`
If set to `true`, this disables the scrolling to the beginning of the heading when clicked.
## Own Shortcodes with JavaScript Dependencies
Certain shortcodes make use of additional dependencies like JavaScript and CSS files. The theme only loads these dependencies if the shortcode is used. To do so correctly the theme adds management code in various files.
2023-11-20 23:53:33 +00:00
You can you use this mechanism in your own shortcodes. Say you want to add a shortcode `myshortcode` that also requires the `jquery` JavaScript library.
2023-10-10 17:04:18 +00:00
1. Write the shortcode file `layouts/shortcodes/myshortcode.html` and add the following line
````go {title="layouts/shortcodes/myshortcode.html"}
2023-12-20 19:17:33 +00:00
{{- .Page.Store.Set "hasMyShortcode" true }}
````
1. Add the following snippet to your `hugo.toml`
2024-03-02 13:19:46 +00:00
{{< multiconfig file=hugo >}}
[params.relearn.dependencies]
[params.relearn.dependencies.myshortcode]
name = "MyShortcode"
2024-03-02 13:19:46 +00:00
{{< /multiconfig >}}
1. Add the dependency loader file `layouts/partials/dependencies/myshortcode.html`. The loader file will be called from multiple locations inside of the theme with the parameter `page` containing the current [page](https://gohugo.io/methods/page/) variable and `location` with one of the currently defined locations
* `header`: if called at the end of the HTML `head` element
* `footer`: if called at the end of the HTML `body` element
````go {title="layouts/partials/dependencies/myshortcode.html"}
{{- if eq .location "footer" }}
<script src="https://www.unpkg.com/jquery/dist/jquery.js"></script>
{{- end }}
````
Character casing is relevant!
- the `name` setting in your `hugo.toml` must match the key (that needs to be prefixed with a `has`) you used for the store in your `layouts/shortcodes/myshortcode.html`.
- the key on `params.relearn.dependencies` in your `hugo.toml` must match the base file name of your loader file.
See the `math`, `mermaid` and `openapi` shortcodes for examples.
{{% notice note %}}
If you are really into customization of the theme and want to use the dependency loader for your own locations, you can do this by simply calling it from inside of your overriden partials
````go
{{- partial "dependencies.html" (dict "page" . "location" "mylocation") }}
````
{{% /notice %}}
## Output Formats
Certain parts of the theme can be changed for support of your own [output formats](https://gohugo.io/templates/output-formats/). Eg. if you define a new output format `PLAINTEXT` in your `hugo.toml`, you can add a file `layouts/partials/header.plaintext.html` to change the way, the page header should look like for that output format.
2023-11-20 23:53:33 +00:00
## React to Variant Switches in JavaScript
Once a color variant is fully loaded, either initially or by switching the color variant manually with the variant selector, the custom event `themeVariantLoaded` on the `document` will be dispatched. You can add an event listener and react to changes.
````javascript
document.addEventListener( 'themeVariantLoaded', function( e ){
console.log( e.detail.variant ); // `relearn-light`
});
````
## Partials
The Relearn theme has been built to be as configurable as possible by defining multiple [partials](https://gohugo.io/templates/partials/)
In `themes/hugo-theme-relearn/layouts/partials/`, you will find all the partials defined for this theme. If you need to overwrite something, don't change the code directly. Instead [follow this page](https://gohugo.io/themes/customizing/). You'd create a new partial in the `layouts/partials` folder of your local project. This partial will have the priority.
This theme defines the following partials :
- `header.html`: the header of the page. See [output-formats](#output-formats)
- `footer.html`: the footer of the page. See [output-formats](#output-formats)
- `body.html`: the body of the page. The body may contain of one or many articles. See [output-formats](#output-formats)
- `article.html`: the output for a single article, can contain elements around your content. See [output-formats](#output-formats)
- `menu.html`: left menu. _Not meant to be overwritten_
- `search.html`: search box. _Not meant to be overwritten_
- `custom-header.html`: custom headers in page. Meant to be overwritten when adding CSS imports. Don't forget to include `style` HTML tag directive in your file.
- `custom-footer.html`: custom footer in page. Meant to be overwritten when adding JavaScript. Don't forget to include `javascript` HTML tag directive in your file.
- `favicon.html`: the favicon
2023-12-02 00:09:45 +00:00
- `heading.html`: side-wide configuration to change the pages title headings.
2023-11-20 23:53:33 +00:00
- `heading-pre.html`: side-wide configuration to prepend to pages title headings. If you override this, it is your responsibility to take the page's `headingPre` setting into account.
- `heading-post.html`: side-wide configuration to append to pages title headings. If you override this, it is your responsibility to take the page's `headingPost` setting into account.
- `logo.html`: the logo, on top left hand corner
- `meta.html`: HTML meta tags, if you want to change default behavior
- `menu-pre.html`: side-wide configuration to prepend to menu items. If you override this, it is your responsibility to take the page's `menuPre` setting into account.
- `menu-post.html`: side-wide configuration to append to menu items. If you override this, it is your responsibility to take the page's `menuPost` setting into account.
2024-04-07 21:58:08 +00:00
- `menu-footer.html`: footer of the left menu
2023-11-20 23:53:33 +00:00
- `toc.html`: table of contents
- `content.html`: the content page itself. This can be overridden if you want to display page's meta data above or below the content.
- `content-header.html`: header above the title, has a default implementation but you can overwrite it if you don't like it.
- `content-footer.html`: footer below the content, has a default implementation but you can overwrite it if you don't like it.