Skip to content

Commit

Permalink
Merge pull request #660 from gethinode/develop
Browse files Browse the repository at this point in the history
Add support for absolute paths
  • Loading branch information
markdumay authored Dec 16, 2023
2 parents 41711fb + 1223a22 commit dd05225
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 5 deletions.
3 changes: 3 additions & 0 deletions config/_default/hugo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,9 @@ home = ["HTML", "RSS", "REDIR"]
[[module.mounts]]
source = "content"
target = "content"
[[module.mounts]]
source = "data"
target = "data"
[[module.mounts]]
source = "i18n"
target = "i18n"
Expand Down
19 changes: 17 additions & 2 deletions layouts/partials/utilities/GetResource.html
Original file line number Diff line number Diff line change
@@ -1,13 +1,28 @@
<!--
Retrieve a local or remote resource. If the url starts with 'http', the resource is retrieved from an external
location. Else, the url is matched with a page resource and site asset (in that order). The partial returns nil if
the resource cannot be found. The partial supports the following arguments:
location. Else, the url is matched with a page resource and site asset (in that order).
This partial supports both relative and absolute paths. Hugo has different methods to retrieve page bundle assets
and site assets. Absolute paths are converted to a relative path to make them compatible with Hugo's methods. The
prefix of an absolute path is truncated if it matches either with the page bundle folder (starting with "/content/")
or the assets folder ("/assets/").
The partial returns nil if the resource cannot be found. The partial supports the following arguments:
"url" Required path or url of the resource, e.g. "img/example.jpg" or "https://example.com/img.jpg"
"page" Optional page context, used to retrieve a resource from page resources.
-->

{{ $url := .url -}}
{{ $page := .page -}}
{{ if hasPrefix $url "/" }}
{{ $pageContext := (path.Join "/content" $page.File.Dir) -}}
{{ if hasPrefix $url $pageContext }}
{{ $url = strings.TrimPrefix $pageContext $url -}}
{{ else if hasPrefix $url "/assets/" }}
{{ $url = strings.TrimPrefix "/assets/" $url -}}
{{ end }}
{{ $url = strings.TrimPrefix "/" $url -}}
{{ end }}

{{ $res := "" }}
{{ $remote := hasPrefix (lower $url) "http" }}
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@gethinode/hinode",
"version": "0.21.10",
"version": "0.21.11",
"description": "Hinode is a clean documentation and blog theme for Hugo, an open-source static site generator",
"keywords": [
"hugo",
Expand Down

0 comments on commit dd05225

Please sign in to comment.