mirror of
https://github.com/McShelby/hugo-theme-relearn.git
synced 2025-01-18 19:00:24 +00:00
include: adjust to Hugo's build-in link render hook #859
- resolve render hook destination with leading ./ - resolve not only resources but pages as well
This commit is contained in:
parent
db38203826
commit
5c2a221dad
3 changed files with 18 additions and 9 deletions
|
@ -18,6 +18,12 @@ This document shows you what's new in the latest release and flags it with one o
|
|||
|
||||
---
|
||||
|
||||
## 6.1.0.beta (XXXX-XX-XX) {#610}
|
||||
|
||||
- {{% badge style="note" title=" " %}}Change{{% /badge %}} The [`include` shortcode](shortcodes/include) is now able to resolve links to pages as well as resources or files in the file system (the old behavior).
|
||||
|
||||
---
|
||||
|
||||
## 6.0.0 (2024-04-27) {#600}
|
||||
|
||||
- {{% badge style="warning" title=" " %}}Breaking{{% /badge %}} This release requires you to move your self-defined variant (`theme-*.css`) and chroma stylesheets (`chroma-*.css`) from `static/css` to `assets/css`.
|
||||
|
|
|
@ -3,7 +3,7 @@ description = "Displays content from other files"
|
|||
title = "Include"
|
||||
+++
|
||||
|
||||
The `include` shortcode includes other files from your project inside of the current page.
|
||||
The `include` shortcode includes other pages, resources or files from your project.
|
||||
|
||||
## Usage
|
||||
|
||||
|
@ -42,7 +42,7 @@ The included files can even contain Markdown and will be taken into account when
|
|||
|
||||
| Name | Position | Default | Notes |
|
||||
|----------------------|----------|------------------|-------------|
|
||||
| **file** | 1 | _<empty>_ | The path to the file to be included. Path resolution adheres to [Hugo's build-in `readFile` function](https://gohugo.io/functions/readfile/) |
|
||||
| **file** | 1 | _<empty>_ | The path to the page, resource or file to be included. Page and resource paths adhere to [Hugo's logical path](https://gohugo.io/methods/page/path/). If not found by logical path it falls back to [Hugo's build-in `readFile` function](https://gohugo.io/functions/readfile/) |
|
||||
| **hidefirstheading** | 2 | `false` | When `true` and the included file contains headings, the first heading will be hidden. This comes in handy, eg. if you include otherwise standalone Markdown files. |
|
||||
|
||||
## Examples
|
||||
|
|
|
@ -3,21 +3,24 @@
|
|||
{{- $page = .context }}
|
||||
{{- warnf "%q: DEPRECATED parameter 'context' for shortcode 'include' found, use 'page' instead; see https://mcshelby.github.io/hugo-theme-relearn/basics/migration#5180" $page.File.Filename }}
|
||||
{{- end }}
|
||||
{{- $file := .file }}
|
||||
{{- $u := urls.Parse .file }}
|
||||
{{- $path := strings.TrimPrefix "./" $u.Path }}
|
||||
{{- $content := "" }}
|
||||
{{- with or
|
||||
($page.Resources.Get $file)
|
||||
(resources.Get $file)
|
||||
($page.Page.GetPage $path)
|
||||
($page.Page.GetPage (strings.TrimRight "/" $path))
|
||||
($page.Page.Resources.Get $path)
|
||||
(resources.Get $path)
|
||||
}}
|
||||
{{- $content = .Content }}
|
||||
{{- else }}
|
||||
{{- if (fileExists $file) }}
|
||||
{{- $content = $file | readFile }}
|
||||
{{- if (fileExists .file) }}
|
||||
{{- $content = .file | readFile }}
|
||||
{{- else }}
|
||||
{{- if eq $page.Site.Params.include.errorlevel "warning" }}
|
||||
{{- warnf "%q: file '%s' is not a resource nor accessible via file system" $page.File.Filename $file }}
|
||||
{{- warnf "%q: included file '%s' is not a page, resource or accessible via file system" $page.File.Filename .file }}
|
||||
{{- else if eq $page.Site.Params.include.errorlevel "error" }}
|
||||
{{- errorf "%q: image '%s' is not a resource nor accessible via file system" $page.File.Filename $file }}
|
||||
{{- errorf "%q: included file '%s' is not a page, resource or accessible via file system" $page.File.Filename .file }}
|
||||
{{- end }}
|
||||
{{- end }}
|
||||
{{- end }}
|
||||
|
|
Loading…
Reference in a new issue