From 309d8c1c8a97843fc6187dd3f232d8fb5ea31abe Mon Sep 17 00:00:00 2001 From: Thedro Neely Date: Sun, 3 Apr 2022 02:18:04 -0400 Subject: generators/hugo/layouts/_default: Add JSON Feed --- .gitignore | 1 + app/views/partials/footer.php | 2 ++ app/views/snippets/rss.php | 1 + generators/hugo/config.yaml | 4 +++ .../hugo/themes/tdro/layouts/_default/index.json | 40 ++++++++++++++++++++++ 5 files changed, 48 insertions(+) create mode 100644 generators/hugo/themes/tdro/layouts/_default/index.json diff --git a/.gitignore b/.gitignore index 45087b7..3b5269f 100644 --- a/.gitignore +++ b/.gitignore @@ -11,6 +11,7 @@ public/abstracts public/archives public/bookmarks public/images +public/index.json public/posts public/projects public/rss.xml diff --git a/app/views/partials/footer.php b/app/views/partials/footer.php index e4c9aac..5f35a25 100644 --- a/app/views/partials/footer.php +++ b/app/views/partials/footer.php @@ -11,6 +11,8 @@ RSS Feed | + JSON Feed | + Resume | Gitlab | diff --git a/app/views/snippets/rss.php b/app/views/snippets/rss.php index 1b8b6df..a37df92 100644 --- a/app/views/snippets/rss.php +++ b/app/views/snippets/rss.php @@ -1,4 +1,5 @@ + diff --git a/generators/hugo/config.yaml b/generators/hugo/config.yaml index 14c5751..45b175c 100644 --- a/generators/hugo/config.yaml +++ b/generators/hugo/config.yaml @@ -24,7 +24,11 @@ outputFormats: rss: baseName: rss mediaType: application/xml + json: + baseName: index + mediaType: application/json outputs: home: - rss + - json diff --git a/generators/hugo/themes/tdro/layouts/_default/index.json b/generators/hugo/themes/tdro/layouts/_default/index.json new file mode 100644 index 0000000..af03997 --- /dev/null +++ b/generators/hugo/themes/tdro/layouts/_default/index.json @@ -0,0 +1,40 @@ +{ + "version": "https://jsonfeed.org/version/1.1", + "title": "{{ .Site.Title }}", + "home_page_url": "{{ .Site.BaseURL }}", + "feed_url": "{{ .Site.BaseURL }}/index.json", + "items": [ + {{- range $index, $data := .Site.Pages -}} + {{- if ne $data.Type "json" -}} + {{- if and $index (gt $index 0) -}},{{- end }} + { + "id": "{{ md5 $data.Permalink }}", + "url": "{{ $data.Permalink }}", + "title": "{{ htmlEscape $data.Title}}", + "content_text": {{ $data.Plain | jsonify }}, + "content_html": {{ $data.Content | jsonify }}, + "summary": "{{ $data.Summary }}", + "date_modified": "{{ $data.Date | time.Format "2006-01-02T15:04:05Z" }}", + "date_published": "{{ $data.PublishDate | time.Format "2006-01-02T15:04:05Z" }}", + "_metadata": { + "slug": "{{ $data.Slug }}", + "type": "{{ $data.Type }}" + }, + "author": { + "name": "{{ .Site.Author.name }}" + }, + "tags": [ + {{- range $tags, $tag := $data.Params.tags -}} + {{- if $tags -}} + , + {{- end -}} + " + {{- $tag | htmlEscape -}} + " + {{- end -}} + ] + } + {{- end -}} + {{ end }} + ] +} -- cgit v1.2.3