Skip to content

Commit

Permalink
🔍 Refactor: add JSON feed support and refactor output formats build i…
Browse files Browse the repository at this point in the history
…n FixIt

Close #475
  • Loading branch information
Lruihao committed Aug 12, 2024
1 parent 6a83650 commit bc254bc
Show file tree
Hide file tree
Showing 7 changed files with 94 additions and 32 deletions.
51 changes: 32 additions & 19 deletions hugo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -231,24 +231,19 @@ enableEmoji = true
# -------------------------------------------------------------------------------------

[mediaTypes]
# Options to make output .md files
[mediaTypes."text/markdown"]
suffixes = ["md"]
# Options to make output .txt files
[mediaTypes."text/plain"]
suffixes = ["txt"]
# Options to make output feed.json files
[mediaTypes."application/feed+json"]
suffixes = ["json"]

# -------------------------------------------------------------------------------------
# Output Format Definitions
# See: https://gohugo.io/templates/output-formats/#output-format-definitions
# -------------------------------------------------------------------------------------

[outputFormats]
# Options to make output .md files
[outputFormats.MarkDown]
mediaType = "text/markdown"
isPlainText = true
isHTML = false
# FixIt 0.3.0 | NEW Options to make output /archives/index.html file
[outputFormats.archives]
path = "archives"
Expand All @@ -257,6 +252,7 @@ enableEmoji = true
isPlainText = false
isHTML = true
permalinkable = true
notAlternative = true
# FixIt 0.3.0 | NEW Options to make output /offline/index.html file
[outputFormats.offline]
path = "offline"
Expand All @@ -265,36 +261,53 @@ enableEmoji = true
isPlainText = false
isHTML = true
permalinkable = true
notAlternative = true
# FixIt 0.3.0 | NEW Options to make output readme.md file
[outputFormats.README]
[outputFormats.readme]
baseName = "readme"
mediaType = "text/markdown"
isPlainText = true
isHTML = false
notAlternative = true
# FixIt 0.3.0 | CHANGED Options to make output baidu_urls.txt file
[outputFormats.baidu_urls]
baseName = "baidu_urls"
mediaType = "text/plain"
isPlainText = true
isHTML = false
notAlternative = true
# FixIt 0.3.10 | NEW Options to make output feed.json file
[outputFormats.feed]
baseName = "feed"
mediaType = "application/feed+json"
isPlainText = true
isHTML = false
# FixIt 0.3.10 | NEW Options to make output search.json file
[outputFormats.search]
baseName = "search"
mediaType = "application/json"
rel = "search"
isPlainText = true
isHTML = false
permalinkable = true

# -------------------------------------------------------------------------------------
# Customizing Output Formats
# See: https://gohugo.io/templates/output-formats/#customizing-output-formats
# -------------------------------------------------------------------------------------

# Options to make hugo output files, the optional values are below:
# home: ["HTML", "RSS", "JSON", "archives", "offline", "README", "baidu_urls"]
# page: ["HTML", "MarkDown"]
# section: ["HTML", "RSS"]
# taxonomy: ["HTML", "RSS"]
# term: ["HTML", "RSS"]
# home: html, rss, json, feed, archives, offline, readme, baidu_urls, search etc.
# page: html, markdown
# section: html, rss
# taxonomy: html, rss
# term: html, rss
[outputs]
home = ["HTML", "RSS", "JSON", "archives"]
page = ["HTML", "MarkDown"]
section = ["HTML", "RSS"]
taxonomy = ["HTML"]
term = ["HTML", "RSS"]
home = ["html", "rss", "feed", "archives", "offline", "readme", "baidu_urls", "search"]
page = ["html", "markdown"]
section = ["html", "rss"]
taxonomy = ["html", "rss"]
term = ["html", "rss"]

# -------------------------------------------------------------------------------------
# Taxonomies Configuration
Expand Down
46 changes: 46 additions & 0 deletions layouts/index.feed.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
{{ $list := .Pages -}}
{{ $length := (len $list) -}}

{
"version" : "https://jsonfeed.org/version/1.1",
"title" : "{{- .Site.Title -}}",
"description": "{{- .Site.Params.description | default .Site.Title -}}",
"home_page_url" : "{{ .Site.BaseURL }}",
{{ with .OutputFormats.Get "JSONFeed" -}}
"feed_url" : "{{ .Permalink }}",
{{ end -}}
"icon" : "{{ `/apple-touch-icon.png` | absURL }}",
"favicon" : "{{ `/favicon.ico` | absURL }}",
{{ with .Site.Params.author.name -}}
"author" : {
"name" : "{{ . }}"{{ with $.Site.Params.author.link }},
"url": "{{ . }}"{{ end }}{{ with $.Site.Params.author.avatar }},
"avatar": "{{ . | absURL }}"{{ end }}
},
{{ end -}}
"items" : [
{{ range $index, $element := .Scratch.Get "mainSectionPages" -}}
{
"title" : {{ .Title | jsonify }},
"date_published" : "{{ .Date.Format "2006-01-02T15:04:05Z07:00" }}",
{{ if .Lastmod -}}
"date_modified" : "{{ .Date.Format "2006-01-02T15:04:05Z07:00" }}",
{{ else -}}
"date_modified" : "{{ .LastMod.Format "2006-01-02T15:04:05Z07:00" }}",
{{ end -}}
"id" : "{{ .Permalink }}",
"url" : "{{ .Permalink }}",
{{ with .Summary -}}
"summary": {{ . | plainify | jsonify }},
{{ end -}}
{{ with (.Param "author").name -}}
"author" : {
"name" : "{{ . }}"
},
{{ end -}}
"content_html" : {{ .Content | jsonify }},
"language": {{ .Language.Lang | default $.Lang | jsonify }}
}{{ if ne (add $index 1) $length }},{{ end }}
{{ end -}}
]
}
File renamed without changes.
2 changes: 1 addition & 1 deletion layouts/partials/assets.html
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
{{- dict "Source" $source "Fingerprint" $fingerprint "Defer" true | dict "Scratch" .Scratch "Data" | partial "scratch/script.html" -}}
{{- $config = dict "type" "algolia" "algoliaIndex" $search.algolia.index "algoliaAppID" $search.algolia.appID "algoliaSearchKey" $search.algolia.searchKey | dict "search" | merge $config -}}
{{- else if eq $search.type "fuse" -}}
{{- with .Site.Home.OutputFormats.Get "json" -}}
{{- with .Site.Home.OutputFormats.Get "search" -}}
{{- $config = dict "type" "fuse" "fuseIndexURL" .RelPermalink | dict "search" | merge $config -}}
{{- end -}}
{{- $source := $cdn.fuseJS | default "lib/fuse/fuse.min.js" -}}
Expand Down
20 changes: 11 additions & 9 deletions layouts/partials/head/link.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
{{- $cdn := .Scratch.Get "cdn" | default dict -}}
{{- $fingerprint := .Scratch.Get "fingerprint" -}}
{{- $title := printf "%s | %s" .Title site.Title -}}
{{- if .IsHome -}}
{{- $title = site.Title -}}
{{- end -}}

{{- if not .Site.Params.app.noFavicon -}}
{{- with .Site.Params.app.svgFavicon -}}
Expand All @@ -18,17 +22,15 @@
{{- end -}}
{{- end -}}

<link rel="canonical" href="{{ .Permalink }}" />
{{- if .Prev -}}
<link rel="prev" href="{{ .Prev.Permalink }}" />
<link rel="canonical" type="text/html" href="{{ .Permalink }}" title="{{ $title }}" />
{{- with .Prev -}}
<link rel="prev" type="text/html" href="{{ .Permalink }}" title="{{ .Title }}" />
{{- end -}}
{{- if .Next -}}
<link rel="next" href="{{ .Next.Permalink }}" />
{{- with .Next -}}
<link rel="next" type="text/html" href="{{ .Permalink }}" title="{{ .Title }}" />
{{- end -}}

{{- with .OutputFormats.Get "RSS" -}}
<link rel="alternate" href="{{ .RelPermalink }}" type="application/rss+xml" title="{{ $.Site.Title }}">
<link rel="feed" href="{{ .RelPermalink }}" type="application/rss+xml" title="{{ $.Site.Title }}">
{{- range .AlternativeOutputFormats -}}
{{- printf `<link rel=%q type=%q href=%q title=%q>` .Rel .MediaType.Type .Permalink $title | safeHTML -}}
{{- end -}}

{{- /* style.min.css */ -}}
Expand Down
5 changes: 3 additions & 2 deletions layouts/partials/head/meta.html
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
{{- $params := partial "function/params.html" -}}
{{- $author := .Param "author" -}}

<meta name="author" content="{{ .Site.Params.author.name }}">
<meta name="author-link" content="{{ .Site.Params.author.link }}">
<meta name="author" content="{{ $author.name }}">
<meta name="author-link" content="{{ $author.link }}">
<meta name="description" content="{{ with .Description }}{{ . }}{{ else }}{{ if .IsPage | and .Summary }}{{ .Summary }}{{ else }}{{ with .Site.Params.description }}{{ . }}{{ end }}{{ end }}{{ end }}" />

{{- $keywords := .Keywords -}}
Expand Down
2 changes: 1 addition & 1 deletion layouts/partials/init/index.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{{- .Scratch.Set "version" "v0.3.10-c936e541" -}}
{{- .Scratch.Set "version" "v0.3.10-66e628d4" -}}
{{- .Scratch.Set "this" dict -}}

{{- partial "init/detection-env.html" . -}}
Expand Down

0 comments on commit bc254bc

Please sign in to comment.