mirror of
https://github.com/thegeeklab/hugo-geekdoc.git
synced 2024-11-28 15:40:36 +00:00
Robert Kaussow
5c5e2d59cb
BREAKING CHANGE: We have replaced `gulp` with `webpack` and `npm scripts` to build this theme. If you build it on your own or use build commands during the deployment, you may have to adjust your setup. BREAKING CHANGE: The `GeekblogIcons` font is using the icon name as Unicode now. As a consequence, you have to replace all references to Icons from this font if you have customized the theme. BREAKING CHANGE: We have refactored the search integration to split Hugo templates from JavaScript code. To get it working again, you need to adjust the `outputFormats` and `outputs` in your Hugo configuration file, as [documented](https://geekdocs.de/usage/configuration/#site-configuration).
97 lines
3.9 KiB
Markdown
97 lines
3.9 KiB
Markdown
---
|
|
title: Includes
|
|
---
|
|
|
|
{{< toc >}}
|
|
|
|
Include shortcode can include files of different types. By specifying a language, the included file will have syntax highlighting.
|
|
|
|
<!-- prettier-ignore-start -->
|
|
```tpl
|
|
{{</* include file="relative/path/from/hugo/root" language="go" markdown=[false|true] */>}}
|
|
```
|
|
<!-- prettier-ignore-end -->
|
|
|
|
Attributes:
|
|
|
|
| Name | Usage | default |
|
|
| -------- | ----------------------------------------------------------------------------------------------------------------------------------- | --------------- |
|
|
| file | path to the included file relative to the Hugo root | undefined |
|
|
| language | language for [syntax highlighting](https://gohugo.io/content-management/syntax-highlighting/#list-of-chroma-highlighting-languages) | undefined |
|
|
| type | special include type (`html,page`) | undefined |
|
|
| options | highlighting [options](https://gohugo.io/content-management/syntax-highlighting/#highlight-shortcode) | `linenos=table` |
|
|
|
|
## Examples
|
|
|
|
### Markdown file (default)
|
|
|
|
If no other options are specified, files will be rendered as Markdown using the `RenderString` [function](https://gohugo.io/functions/renderstring/).
|
|
|
|
{{< hint warning >}}
|
|
**Location of markdown files**\
|
|
If you include markdown files that should not get a menu entry, place them outside the content folder or exclude them otherwise.
|
|
{{< /hint >}}
|
|
|
|
<!-- prettier-ignore-start -->
|
|
```tpl
|
|
{{</* include file="/static/_includes/example.md.part" */>}}
|
|
```
|
|
<!-- prettier-ignore-end -->
|
|
|
|
<!-- prettier-ignore-start -->
|
|
<!-- spellchecker-disable -->
|
|
{{< include file="/static/_includes/example.md.part" >}}
|
|
<!-- spellchecker-enable -->
|
|
<!-- prettier-ignore-end -->
|
|
|
|
### Language files
|
|
|
|
This method can be used to include source code files and keep them automatically up to date.
|
|
|
|
<!-- prettier-ignore-start -->
|
|
```tpl
|
|
{{</* include file="config.yaml" language="yaml" options="linenos=table,hl_lines=5-6,linenostart=100" */>}}
|
|
```
|
|
<!-- prettier-ignore-end -->
|
|
|
|
Result:
|
|
|
|
<!-- prettier-ignore-start -->
|
|
<!-- spellchecker-disable -->
|
|
{{< include file="config.yaml" language="yaml" options="linenos=table,hl_lines=5-6,linenostart=100">}}
|
|
<!-- spellchecker-enable -->
|
|
<!-- prettier-ignore-end -->
|
|
|
|
### Special include types
|
|
|
|
#### HTML
|
|
|
|
HTML content will be filtered by the `safeHTML` filter and added to the rendered page output.
|
|
|
|
<!-- prettier-ignore-start -->
|
|
```tpl
|
|
{{</* include file="/static/_includes/example.html.part" */>}}
|
|
```
|
|
<!-- prettier-ignore-end -->
|
|
|
|
{{< include file="/static/_includes/example.html.part" type="html" >}}
|
|
|
|
#### Pages
|
|
|
|
In some situations, it can be helpful to include Markdown files that also contain shortcodes. While the [default method](#markdown-file-default) works fine to render plain Markdown, shortcodes are not parsed. The only way to get this to work is to use Hugo pages. There are several ways to structure these include pages, so whatever you do, keep in mind that Hugo needs to be able to render and serve these files as regular pages! How it works:
|
|
|
|
1. First you need to create a directory **within** your content directory. For this example site `_includes` is used.
|
|
2. To prevent the theme from embedding the page in the navigation, create a file `_includes/_index.md` and add `GeekdocHidden: true` to the front matter.
|
|
3. Place your Markdown files within the `_includes` folder e.g. `/_includes/include-page.md`. Make sure to name it `*.md`.
|
|
4. Include the page using `{{</* include file="/_includes/include-page.md" */>}}`.
|
|
|
|
Resulting structure should look like this:
|
|
|
|
```Shell
|
|
_includes/
|
|
├── include-page.md
|
|
└── _index.md
|
|
```
|
|
|
|
{{< include file="/_includes/include-page.md" type="page" >}}
|