mirror of
https://github.com/thegeeklab/hugo-geekdoc.git
synced 2024-11-24 22:00:39 +00:00
Merge pull request #5 from micbar/add-include
add include shortcode and doc
This commit is contained in:
commit
8e98e5c814
51
exampleSite/content/shortcodes/includes.md
Normal file
51
exampleSite/content/shortcodes/includes.md
Normal file
@ -0,0 +1,51 @@
|
||||
Include Shortcode can include files of different types. By specifying a language, the included file will have syntax highlighting.
|
||||
|
||||
## Shortcode
|
||||
|
||||
```tpl
|
||||
{{</* include file="relative/path/from/hugo/root" language="go" markdown=[false|true] */>}}
|
||||
```
|
||||
|
||||
Attributes:
|
||||
|
||||
| Name | Usage | default |
|
||||
|---|---|---|
|
||||
| file | path to the included file relative to the hugo root | empty value |
|
||||
| language* | language for [syntax highlighting](https://gohugo.io/content-management/syntax-highlighting/#list-of-chroma-highlighting-languages) | empty value |
|
||||
| markdown | included file is markdown | false |
|
||||
| options | highlighting [options](https://gohugo.io/content-management/syntax-highlighting/#highlight-shortcode) | linenos=table |
|
||||
|
||||
\* if not set, the content will be rendered as plain html
|
||||
|
||||
### Include *.yml file with options
|
||||
|
||||
```tpl
|
||||
{{</* include file="config.yaml" language="yaml" options="linenos=table,hl_lines=5-6,linenostart=100" */>}}
|
||||
```
|
||||
|
||||
{{< include file="config.yaml" language="yaml" options="linenos=table,hl_lines=5-6,linenostart=100">}}
|
||||
|
||||
### Include *.md file
|
||||
|
||||
Included markdown files will be rendered using the `markdownify` filter.
|
||||
|
||||
{{< 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 exlude them otherwise.
|
||||
{{< /hint >}}
|
||||
|
||||
```tpl
|
||||
{{</* include file="static/table.md" markdown="true" */>}}
|
||||
```
|
||||
|
||||
{{< include file="static/table.md" markdown="true" >}}
|
||||
|
||||
### Include *.html file
|
||||
|
||||
Html content will be filtered by the `safeHTML` filter and added to the rendered page output.
|
||||
|
||||
```tpl
|
||||
{{</* include file="static/example.html" */>}}
|
||||
```
|
||||
|
||||
{{< include file="static/example.html" >}}
|
13
exampleSite/static/example.html
Normal file
13
exampleSite/static/example.html
Normal file
@ -0,0 +1,13 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<body>
|
||||
|
||||
<h1>This is heading 1</h1>
|
||||
<h2>This is heading 2</h2>
|
||||
<h3>This is heading 3</h3>
|
||||
<h4>This is heading 4</h4>
|
||||
<h5>This is heading 5</h5>
|
||||
<h6>This is heading 6</h6>
|
||||
|
||||
</body>
|
||||
</html>
|
5
exampleSite/static/table.md
Normal file
5
exampleSite/static/table.md
Normal file
@ -0,0 +1,5 @@
|
||||
#### Test Table
|
||||
|
||||
| Head 1 | Head 2 | Head 3 |
|
||||
|---|---|---|
|
||||
| 1 | 2 | 3 |
|
8
layouts/shortcodes/include.html
Normal file
8
layouts/shortcodes/include.html
Normal file
@ -0,0 +1,8 @@
|
||||
{{$file := .Get "file"}}
|
||||
{{- if eq (.Get "markdown") "true" -}}
|
||||
{{- $file | readFile | markdownify -}}
|
||||
{{- else if (.Get "language") -}}
|
||||
{{- highlight ($file | readFile) (.Get "language") (default "linenos=table" (.Get "options")) -}}
|
||||
{{- else -}}
|
||||
{{ $file | readFile | safeHTML }}
|
||||
{{- end -}}
|
Loading…
Reference in New Issue
Block a user