Skip to content

Commit

Permalink
docs: advanced color variant #679
Browse files Browse the repository at this point in the history
  • Loading branch information
McShelby committed Nov 20, 2023
1 parent 258093e commit 98cbf97
Show file tree
Hide file tree
Showing 40 changed files with 334 additions and 313 deletions.
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ The Relearn theme is a fork of the great [Learn theme](https://github.com/matcor
- Responsive design for mobile usage
- Looks nice on paper (if it has to)
- Usable offline, no external dependencies
- [Usable from your local file system via `file://` protocol](https://mcshelby.github.io/hugo-theme-relearn/basics/configuration#serving-your-page-from-the-filesystem)
- [Usable from your local file system via `file://` protocol](https://mcshelby.github.io/hugo-theme-relearn/basics/customization#serving-your-page-from-the-filesystem)
- Support for the [VSCode Front Matter extension](https://github.com/estruyf/vscode-front-matter) for on-premise CMS capabilities
- Support for Internet Explorer 11
- [Support for Open Graph and Twitter Cards](https://mcshelby.github.io/hugo-theme-relearn/basics/configuration/#social-media-meta-tags)
- [Support for Open Graph and Twitter Cards](https://mcshelby.github.io/hugo-theme-relearn/basics/customization#social-media-meta-tags)
- **Configurable theming and visuals**
- [Configurable brand images](https://mcshelby.github.io/hugo-theme-relearn/basics/customization#change-the-logo)
- [Automatic switch for light/dark variant dependend on your OS settings](https://mcshelby.github.io/hugo-theme-relearn/basics/customization#adjusting-to-os-settings)
Expand All @@ -28,10 +28,10 @@ The Relearn theme is a fork of the great [Learn theme](https://github.com/matcor
- [Stylesheet generator](https://mcshelby.github.io/hugo-theme-relearn/basics/generator)
- [Configurable syntax highlighting](https://mcshelby.github.io/hugo-theme-relearn/shortcodes/highlight)
- **Unique theme features**
- [Print whole chapters or even the complete site](https://mcshelby.github.io/hugo-theme-relearn/basics/configuration#activate-print-support)
- [Print whole chapters or even the complete site](https://mcshelby.github.io/hugo-theme-relearn/basics/customization#activate-print-support)
- In page search
- [Site search](https://mcshelby.github.io/hugo-theme-relearn/basics/configuration#activate-search)
- [Dedicated search page](https://mcshelby.github.io/hugo-theme-relearn/basics/configuration#activate-dedicated-search-page)
- [Site search](https://mcshelby.github.io/hugo-theme-relearn/basics/customization#activate-search)
- [Dedicated search page](https://mcshelby.github.io/hugo-theme-relearn/basics/customization#activate-dedicated-search-page)
- [Taxonomy support](https://mcshelby.github.io/hugo-theme-relearn/cont/taxonomy)
- [Configurable topbar buttons](https://mcshelby.github.io/hugo-theme-relearn/basics/topbar)
- [Unlimited nested menu items](https://mcshelby.github.io/hugo-theme-relearn/cont/pages)
Expand Down
2 changes: 1 addition & 1 deletion exampleSite/config/_default/params.toml
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ themeVariant = [

# The color variants used for auto mode.
# Default: [ "relearn-light", "relearn-dark" ], overwritten by the first
# two non-auto options from themeVariant if existant.
# two non-auto options of your `themeVariant` option if present.
# The auto variant defines how your site adjusts to your selected OS settings
# for light/dark mode. The first array element is the variant for light mode,
# the second for dark mode.
Expand Down
10 changes: 5 additions & 5 deletions exampleSite/content/_index.en.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ The theme is a fork of the great [Learn theme](https://github.com/matcornic/hugo
- Responsive design for mobile usage
- Looks nice on paper (if it has to)
- Usable offline, no external dependencies
- [Usable from your local file system via `file://` protocol](basics/configuration#serving-your-page-from-the-filesystem)
- [Usable from your local file system via `file://` protocol](basics/customization#serving-your-page-from-the-filesystem)
- Support for the [VSCode Front Matter extension](https://github.com/estruyf/vscode-front-matter) for on-premise CMS capabilities
- Support for Internet Explorer 11
- [Support for Open Graph and Twitter Cards](basics/configuration/#social-media-meta-tags)
- [Support for Open Graph and Twitter Cards](basics/customization#social-media-meta-tags)
- **Configurable theming and visuals**
- [Configurable brand images](basics/customization#change-the-logo)
- [Automatic switch for light/dark variant dependend on your OS settings](basics/customization#adjusting-to-os-settings)
Expand All @@ -31,10 +31,10 @@ The theme is a fork of the great [Learn theme](https://github.com/matcornic/hugo
- [Stylesheet generator](basics/generator/)
- [Configurable syntax highlighting](shortcodes/highlight)
- **Unique theme features**
- [Print whole chapters or even the complete site](basics/configuration#activate-print-support)
- [Print whole chapters or even the complete site](basics/customization#activate-print-support)
- In page search
- [Site search](basics/configuration#activate-search)
- [Dedicated search page](basics/configuration#activate-dedicated-search-page)
- [Site search](basics/customization#activate-search)
- [Dedicated search page](basics/customization#activate-dedicated-search-page)
- [Taxonomy support](cont/taxonomy)
- [Configurable topbar buttons](basics/topbar)
- [Unlimited nested menu items](cont/pages)
Expand Down
130 changes: 130 additions & 0 deletions exampleSite/content/basics/branding/_index.en.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
+++
categories = ["custom", "theming"]
title = "Branding"
weight = 24
+++

The Relearn theme provides configuration options to change your your site's colors, favicon and logo. This allows you to easily align your site visuals to your desired style. Most of these options are exposed thru so called color variants.

A color variant lets you customize various visual effects of your site like almost any color, used fonts, color schemes of print, syntax highligtning, Mermaid and the OpenAPI shortcode, etc. It contains of a CSS file and optional configuration options in your `config.toml`.

The Relearn theme ships with a wide set of different color variants. You can use them as-is, copy them over and use them as a starting point for your customizations or just create completely new variants unique to your site. The [interactive variant generator](basics/generator) may help you with this task.

Once configured in your `config.toml`, you can select them with the variant selector at the bottom of the menu.

## Change the Variant (Simple) {#theme-variant}

### Single Variant

Set the `themeVariant` value to the name of your theme file. That's it! Your site will be displayed in this variant only.

````toml
[params]
themeVariant = "relearn-light"
````

{{% notice note %}}
Your theme variant file must reside in your site's `static/css` directory or in the theme's `static/css` directory and the file name must start with `theme-` and end wit `.css`. In the above example, the path of your theme file must be `static/css/theme-relearn-light.css`.

If you want to make changes to a shipped color variant, create a copy in your site's `static/css` directory. Don't edit the file in the theme's directory!

{{% /notice %}}

### Multiple Variants

You can also set multiple variants. In this case, the first variant is the default chosen on first view and a variant selector will be shown in the menu footer if the array contains more than one entry.

````toml
[params]
themeVariant = [ "relearn-light", "relearn-dark" ]
````

{{% notice tip %}}
The theme provides an advanced configuration mode, combining the functionality for multiple variants with the below possibilities of adjusting to your OS settings, logo and syntax highlightning and even more!

Although all options documented here are still working, the advanced configuration options are the recommended way to configure your color variants. [See below](#theme-variant-advanced).
{{% /notice %}}

## Adjust to OS Settings

You can also cause the site to adjust to your OS settings for light/dark mode. Just set the `themeVariant` to `auto`. That's it.

You can use the `auto` value with the single or multiple variants option. If you are using multiple variants, you can drop `auto` at any position in the option's array, but usually it makes sense to set it in the first position and make it the default.

````toml
[params]
themeVariant = [ "auto", "red" ]
````

If you don't configure anything else, the theme will default to use `relearn-light` for light mode and `relearn-dark` for dark mode. These defaults are overwritten by the first two non-auto options of your `themeVariant` option if present.

In the above example, you would end with `red` for light mode and the default of `relearn-dark` for dark mode.

If you don't like that behavior, you can explicitly set `themeVariantAuto`. The first entry in the array is the color variant for light mode, the second for dark mode.

````toml
[params]
themeVariantAuto = [ "learn", "neon" ]
````

## Change the Favicon

If your favicon is a SVG, PNG or ICO, just drop your image in your site's `static/images/` directory and name it `favicon.svg`, `favicon.png` or `favicon.ico` respectively.

If you want to adjust your favicon according to your OS settings for light/dark mode, add the image files `static/images/favicon-light.svg` and `static/images/favicon-dark.svg` to your site's directory, respectively, corresponding to your file format. In case some of the files are missing, the theme falls back to `favicon.svg` for each missing file. All supplied favicons must be of the same file format.

If no favicon file is found, the theme will lookup the alternative filename `logo` in the same location and will repeat the search for the list of supported file types.

If you need to change this default behavior, create a new file `layouts/partials/favicon.html` in your site's directory and write something like this:

````html
<link rel="icon" href="/images/favicon.bmp" type="image/bmp">
````

## Change the Logo

Create a new file in `layouts/partials/logo.html` of your site. Then write any HTML you want. You could use an `img` HTML tag and reference an image created under the _static_ folder, or you could paste a SVG definition!

{{% notice note %}}
The size of the logo will adapt automatically.
{{% /notice %}}

## Syntax highlightning

If you want to switch the syntax highlighting theme together with your color variant, generate a syntax highlighting stylesheet and configure your installation [according to Hugo's documentation](https://gohugo.io/content-management/syntax-highlighting/). Then, `@import` the syntax highlightning stylesheet in your color variant stylesheet.

For an example, take a look into `theme-relearn-light.css` and `config.toml` of the exampleSite.

If you want to reconfigure just the syntax highlighting of an existing color variant, you need to copy the file to your site's directory and adjust it accordingly.

## Change the Variant (Advanced) {#theme-variant-advanced}

The theme offers a new way to configure theme variants and all of the aspects above inside of a single configuration item. This comes with some features previously unsupported.

Like with the [multiple variants](#multiple-variants) option, you are defining your theme variants in an array but now _not by simple strings_ **but in a table with suboptions**.

Again, in this case, the first variant is the default chosen on first view and a variant selector will be shown in the menu footer if the array contains more than one entry.

````toml
[params]
themeVariant = [ "relearn-light", "relearn-dark" ]
````

you now write it that way:

````toml
[params]
[[params.themeVariant]]
identifier = "relearn-light"
[[params.themeVariant]]
identifier = "relearn-dark"
````

The `identifier` option is mandatory and equivalent to the string in the first example. Further options can be configured, see the table below.

### Parameter

| Name | Default | Notes |
|-----------------------|-----------------|-------------|
| identifier | _&lt;empty&gt;_ | Must correspond to the name of a color variant either in your site's or the theme's directory in the form `static/css/theme-<IDENTIFIER>.css`. |
| name | see notes | The name to be displayed in the variant selector. If not set, the identifier is used in a human readable form. |
6 changes: 6 additions & 0 deletions exampleSite/content/basics/branding/_index.pir.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
+++
categories = ["custom", "theming"]
title = "Brrrand'n"
weight = 24
+++
{{< piratify >}}
145 changes: 2 additions & 143 deletions exampleSite/content/basics/configuration/_index.en.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,152 +4,11 @@ title = "Configuration"
weight = 20
+++

## Global site parameters
On top of [Hugo's global configuration options](https://gohugo.io/overview/configuration/), the Relearn theme lets you define further options unique to the theme in your `config.toml`. The defaults are written in the comments of each option.

On top of [Hugo global configuration](https://gohugo.io/overview/configuration/), the Relearn theme lets you define the following parameters in your `config.toml` (here, values are default).

Note that some of these parameters are explained in details in other sections of this documentation.
Note that some of these options are explained in detail in other sections of this documentation.

````toml {title="config.toml"}
[params]
{{% include "config/_default/params.toml" %}}
````

## Serving your page from a subfolder

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.

## 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
````

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 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

If not already present, add the following lines in the same `config.toml` file.

```toml
[outputs]
home = ["HTML", "RSS", "SEARCH"]
```

This will generate a search index file at the root of your public folder ready to be consumed by the Lunr search library. Note that the `SEARCH` outputformat was named `JSON` in previous releases but was implemented differently. Although `JSON` still works, it is now deprecated.

### Activate dedicated search page

You can add a dedicated search page for your page by adding the `SEARCHPAGE` outputformat to your home page by adding the following lines in your `config.toml` file. This will cause Hugo to generate a new file `http://example.com/mysite/search.html`.

```toml
[outputs]
home = ["HTML", "RSS", "SEARCH", "SEARCHPAGE"]
```

You can access this page by either clicking on the magnifier glass or by typing some search term and pressing `ENTER` inside of the menu's search box .

![Screenshot of the dedicated search page](search_page.png?&width=60pc)

{{% notice note %}}
To have Hugo create the dedicated search page successfully, you must not generate the URL `http://example.com/mysite/search.html` from your own content. This can happen if you set `uglyURLs=true` in your `config.toml` and defining a Markdown file `content/search.md`.

To make sure, there is no duplicate content for any given URL of your project, run `hugo --printPathWarnings`.
{{% /notice %}}

## Activate print support

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 `config.toml` as seen below:

```toml
[outputs]
home = ["HTML", "RSS", "PRINT", "SEARCH"]
section = ["HTML", "RSS", "PRINT"]
page = ["HTML", "RSS", "PRINT"]
```

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.

{{% 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 `config.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 `config.toml` to your liking.
{{% /notice %}}

## MathJax

The MathJax configuration parameters can also be set on a specific page. In this case, the global parameter would be overwritten by the local one. See [Math](shortcodes/math) for additional documentation.

### Example {#math-example}

MathJax is globally disabled. By default it won't be loaded by any page.

On page "Physics" you coded some JavaScript for a dynamic formulae. You can set the MathJax parameters locally to load mathJax on this page.

You also can disable MathJax for specific pages while globally enabled.

## Mermaid

The Mermaid configuration parameters can also be set on a specific page. In this case, the global parameter would be overwritten by the local one. See [Mermaid](shortcodes/mermaid) for additional documentation.

### Example {#mermaid-example}

Mermaid is globally disabled. By default it won't be loaded by any page.

On page "Architecture" you coded some JavaScript to dynamically generate a class diagram. You can set the Mermaid parameters locally to load mermaid on this page.

You also can disable Mermaid for specific pages while globally enabled.

## Home Button Configuration

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 two parameters for the defined languages:

```toml
[languages]
[languages.en]
...
[languages.en.params]
landingPageName = "<i class='fas fa-home'></i> Home"
...
[languages.pir]
...
[languages.pir.params]
landingPageName = "<i class='fas fa-home'></i> Arrr! Homme"
...
```

If those params are not configured for a specific language, they will get their
default values:

```toml
landingPageName = "<i class='fas fa-home'></i> Home"
```

The home button is going to look like this:

![Default Home Button](home_button_defaults.png?width=18.75rem)

## Social Media Meta Tags

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.
Loading

0 comments on commit 98cbf97

Please sign in to comment.