-
Notifications
You must be signed in to change notification settings - Fork 285
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: Make templates return results properly (#153)
...instead of abusing .Scratch Fixes #137 * Make markdownify.html and content.html return results properly * Make author.html return results properly * Make auto-detect-images.html and images.html return results properly * Make date.html return results properly * Make data-attributes.html return result properly * Make title.html return results properly * Make toc.html return results properly * Make relative-url.html return results properly * Make tree-sections.html return results properly (untested) * Rolled back change to tree-sections.html, doesn't work BREAKING CHANGE: Various templates under `utils/partials/` will return results directly rather than via `.Scratch` now.
- Loading branch information
Showing
23 changed files
with
162 additions
and
323 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,47 +1,48 @@ | ||
{{- .Scratch.Delete "author" -}} | ||
{{- $author := dict -}} | ||
{{- if .Params.original | default .Site.Params.original -}} | ||
{{- with .Site.Author.name -}} | ||
{{- $.Scratch.SetInMap "author" "name" . -}} | ||
{{- $author = merge $author (dict "name" .) -}} | ||
{{- end -}} | ||
{{- with .Site.Author.email -}} | ||
{{- $.Scratch.SetInMap "author" "email" . -}} | ||
{{- $author = merge $author (dict "email" .) -}} | ||
{{- end -}} | ||
{{- with .Site.Author.motto -}} | ||
{{- $.Scratch.SetInMap "author" "motto" . -}} | ||
{{- $author = merge $author (dict "motto" .) -}} | ||
{{- end -}} | ||
{{- with .Site.Author.avatar -}} | ||
{{- $.Scratch.SetInMap "author" "avatar" . -}} | ||
{{- $author = merge $author (dict "avatar" .) -}} | ||
{{- end -}} | ||
{{- $baseURLWithLangFix := (printf "%s%s/" (strings.TrimSuffix "/" .Site.BaseURL) .Site.LanguagePrefix) -}} | ||
{{- with .Site.Author.website | default $baseURLWithLangFix -}} | ||
{{- $.Scratch.SetInMap "author" "website" . -}} | ||
{{- $author = merge $author (dict "website" .) -}} | ||
{{- end -}} | ||
{{- with .Site.Copyright -}} | ||
{{- $.Scratch.SetInMap "author" "copyright" . -}} | ||
{{- $author = merge $author (dict "copyright" .) -}} | ||
{{- end -}} | ||
{{- with .Site.Author.twitter -}} | ||
{{- $.Scratch.SetInMap "author" "twitter" . -}} | ||
{{- $author = merge $author (dict "twitter" .) -}} | ||
{{- end -}} | ||
{{- else -}} | ||
{{- with .Params.author -}} | ||
{{- $.Scratch.SetInMap "author" "name" . -}} | ||
{{- $author = merge $author (dict "name" .) -}} | ||
{{- end -}} | ||
{{- with .Params.email -}} | ||
{{- $.Scratch.SetInMap "author" "email" . -}} | ||
{{- $author = merge $author (dict "email" .) -}} | ||
{{- end -}} | ||
{{- with .Params.motto -}} | ||
{{- $.Scratch.SetInMap "author" "motto" . -}} | ||
{{- $author = merge $author (dict "motto" .) -}} | ||
{{- end -}} | ||
{{- with .Params.avatar -}} | ||
{{- $.Scratch.SetInMap "author" "avatar" . -}} | ||
{{- $author = merge $author (dict "avatar" .) -}} | ||
{{- end -}} | ||
{{- with .Params.website -}} | ||
{{- $.Scratch.SetInMap "author" "website" . -}} | ||
{{- $author = merge $author (dict "website" .) -}} | ||
{{- end -}} | ||
{{- with .Params.copyright -}} | ||
{{- $.Scratch.SetInMap "author" "copyright" . -}} | ||
{{- $author = merge $author (dict "copyright" .) -}} | ||
{{- end -}} | ||
{{- with .Params.twitter -}} | ||
{{- $.Scratch.SetInMap "author" "twitter" . -}} | ||
{{- $author = merge $author (dict "twitter" .) -}} | ||
{{- end -}} | ||
{{- end -}} | ||
{{- end -}} | ||
{{- return $author -}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,11 @@ | ||
<!-- https://gohugo.io/functions/findre/ --> | ||
<!-- https://gohugo.io/functions/replacere/ --> | ||
<!-- https://regex101.com/ --> | ||
{{- $imgs := slice -}} | ||
{{- if and .IsPage (in .Site.Params.mainSections .Section) -}} | ||
{{- $imgs := findRE `<img src="/?([^"]+)` .Content | uniq -}} | ||
{{- with $imgs -}} | ||
{{- $.Scratch.Delete "imgsURL" -}} | ||
{{- range . -}} | ||
{{- $.Scratch.Delete "replacement" -}} | ||
{{- if and $.Site.Params.enableImageHost $.Site.Params.headAlso -}} | ||
{{- if (eq hugo.Environment "production") -}} | ||
{{- $url := replaceRE `<img src="/?([^"]+)` `$1` . -}} | ||
{{- if ne (substr $url 0 4) "http" -}} | ||
{{- $hostURL := $.Site.Params.imageHostURL -}} | ||
{{- $replacement := (printf `%s$1` $hostURL) -}} | ||
{{- $.Scratch.Set "replacement" $replacement -}} | ||
{{- else -}} | ||
{{- $.Scratch.Set "replacement" `$1` -}} | ||
{{- end -}} | ||
{{- end -}} | ||
{{- else -}} | ||
{{- $.Scratch.Set "replacement" `$1` -}} | ||
{{- end -}} | ||
{{- $replacement := $.Scratch.Get "replacement" -}} | ||
{{- $imgsURL := replaceRE `<img src="/?([^"]+)` $replacement . -}} | ||
{{- $.Scratch.Add "imgsURL" (slice $imgsURL) -}} | ||
{{- end -}} | ||
{{- range (findRE `<img src="/?([^"]+)` .Content | uniq) -}} | ||
{{- $url := replaceRE `<img src="/?([^"]+)` `$1` . -}} | ||
{{- $imgs = union $imgs (slice $url) -}} | ||
{{- end -}} | ||
{{- end -}} | ||
{{- return $imgs -}} |
Oops, something went wrong.