Skip to content

Commit

Permalink
Merge pull request #1114 from gethinode/download-link
Browse files Browse the repository at this point in the history
Support links to static files and page resources
  • Loading branch information
markdumay authored Aug 17, 2024
2 parents 0caa00a + 1700abc commit c7e70bf
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 5 deletions.
19 changes: 16 additions & 3 deletions layouts/partials/assets/link.html
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,22 @@
{{ if not $isLocal }}
{{ $ref := partial "utilities/GetPage.html" (dict "url" $destination "page" $page) }}
{{- if not $ref -}}
{{- errorf "partial [assets/link.html] - Cannot find page: %s" $destination -}}
{{- $error = true -}}
{{- else -}}
{{ $pageContext := "" }}
{{ with $page.File }}{{ $pageContext = path.Join "/content" .Dir }}{{ end }}
{{ $isPageRes := fileExists (path.Join $pageContext $destination) }}
{{ $isStatic := fileExists (path.Join "static" $destination) }}
{{ if and (not $isPageRes) (not $isStatic) }}
{{- errorf "partial [assets/link.html] - Cannot find page or asset: '%s' at '%s'" $destination $page.File.Path -}}
{{- $error = true -}}
{{ else if $isPageRes }}
{{ $destination = urls.JoinPath "/" (strings.TrimPrefix "/content" $pageContext) $destination }}
{{ else if $isStatic }}
{{ $destination = urls.JoinPath "/" $destination }}
{{ end }}
{{- with $anchor }}{{ $destination = printf "%s#%s" (strings.TrimSuffix "/" $destination) . -}}{{ end -}}
{{ end }}

{{- if and $ref (not $error) -}}
{{- $destination = $ref.RelPermalink -}}
{{- with $anchor }}{{ $destination = printf "%s#%s" (strings.TrimSuffix "/" $destination) . -}}{{ end -}}
{{- end -}}
Expand Down
10 changes: 8 additions & 2 deletions layouts/shortcodes/link.html
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,14 @@
{{- if not $isExternal -}}
{{ $ref := partial "utilities/GetPage.html" (dict "url" $url "page" .Page) }}
{{- if not $ref -}}
{{- errorf "Cannot find page: '%s' at %s" $url .Position -}}
{{- $error = true -}}
{{ $pageContext := "" }}
{{ with .Page.File }}{{ $pageContext = path.Join "/content" .Dir }}{{ end }}
{{ $isPageRes := fileExists (path.Join $pageContext $url) }}
{{ $isStatic := fileExists (path.Join "/static" $url) }}
{{ if and (not $isPageRes) (not $isStatic) }}
{{- errorf "Cannot find page or asset: '%s' at %s" $url .Position -}}
{{- $error = true -}}
{{ end }}
{{- end -}}
{{- end -}}

Expand Down

0 comments on commit c7e70bf

Please sign in to comment.