Skip to content

Commit

Permalink
fix: Make sure to turn relative links absolute in feeds (#170)
Browse files Browse the repository at this point in the history
Fixes #141
  • Loading branch information
palant committed May 22, 2020
1 parent fb54c61 commit 4c6097a
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 4 deletions.
4 changes: 2 additions & 2 deletions layouts/index.sectionsatom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,9 @@
<rights>{{ . | plainify }}</rights>
{{- end }}
{{- $summary := .Description | default (partial "utils/summary.html" $page) -}}
<summary type="html">{{ $summary | html }}</summary>
<summary type="html">{{ partial "utils/make-links-absolute.html" (dict "Deliver" . "content" $summary) | html }}</summary>
{{ if $.Site.Params.includeContent }}
<content type="html">{{ .Content | html }}</content>
<content type="html">{{ partial "utils/make-links-absolute.html" (dict "Deliver" . "content" .Content) | html }}</content>
{{ end }}
<!-- Sections -->
{{ if eq $.Site.Params.categoryBy "sections" }}
Expand Down
4 changes: 2 additions & 2 deletions layouts/index.sectionsrss.xml
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,10 @@
<copyright>{{ . | plainify }}</copyright>
{{- end }}
{{ if $.Site.Params.includeContent }}
<description>{{ .Content | html }}</description>
<description>{{ partial "utils/make-links-absolute.html" (dict "Deliver" . "content" .Content) | html }}</description>
{{ else }}
{{- $summary := .Description | default (partial "utils/summary.html" $page) -}}
<description>{{ $summary | html }}</description>
<description>{{ partial "utils/make-links-absolute.html" (dict "Deliver" . "content" $summary) | html }}</description>
{{ end }}
<!-- Sections -->
{{ if eq $.Site.Params.categoryBy "sections" }}
Expand Down
6 changes: 6 additions & 0 deletions layouts/partials/utils/make-links-absolute.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{{- $Deliver := .Deliver -}}
{{- $content := .content -}}
{{- $baseURL := ($Deliver.Site.BaseURL | strings.TrimSuffix "/") -}}
{{- $content = $content | replaceRE ` (href|src)="/` (printf ` $1="%s/` $baseURL) -}}
{{- $content = $content | replaceRE ` (href|src)="#` (printf ` $1="%s#` $Deliver.Permalink) -}}
{{- $content | safeHTML -}}

0 comments on commit 4c6097a

Please sign in to comment.