From: kengrimes Date: Sat, 21 Apr 2018 23:21:08 +0000 (-0700) Subject: json feeds and favicon support X-Git-Url: https://www.kengrimes.com/gitweb/?p=kengrimes.com%2Ftheme.git;a=commitdiff_plain;h=HEAD json feeds and favicon support --- diff --git a/layouts/_default/baseof.html b/layouts/_default/baseof.html index ddfb8b0..d57f909 100644 --- a/layouts/_default/baseof.html +++ b/layouts/_default/baseof.html @@ -6,6 +6,7 @@ + {{- partialCached "meta.html" . -}} {{ .Hugo.Generator }} diff --git a/layouts/_default/list.json b/layouts/_default/list.json new file mode 100644 index 0000000..e869d70 --- /dev/null +++ b/layouts/_default/list.json @@ -0,0 +1,46 @@ +{{ $iconRoot := cond (not $.Params.iconroot) "" $.Params.iconroot }} +{{- $sp := .Site.GetPage "section" .Section }} +{{ $secIcon := cond (or (not $sp.Params.header) (not (fileExists (printf "static/%s" $sp.Params.header)))) "/img/speedy.png" $sp.Params.header }} +{ + "version" : "https://jsonfeed.org/version/1", + "title" : "{{ .Site.Title }} :: {{ .Title }}", + "description" : "{{ if not .Description }}{{ .Title }}{{ else }}{{ .Description }}{{ end }}", + "home_page_url": "{{ .Site.BaseURL }}", + "feed_url": "{{ .Site.BaseURL }}/index.json", + "icon" : "{{ printf `%s%s` .Site.BaseURL $secIcon }}", + "favicon" : "{{ printf `%s%s/favicon-32x32.png` .Site.BaseURL $iconRoot }}", + {{- with .Site.Author }} + "author" : { + "name" : "{{ .name }}", + "url" : "{{ .url }}", + "avatar" : "{{ .avatar }}" + }, + {{- end }} + "items" : [ + {{- $pages := .Pages.ByPublishDate.Reverse }} + {{- $length := (len $pages) }} + {{- range $index, $element := $pages }} + {{- $ph := cond (or (not .Params.header) (not (fileExists (printf "static/%s" .Params.header)))) (cond (or (not .Parent.Params.header) (not (fileExists (printf "static/%s" .Parent.Params.header)))) "/img/speedy.png" .Parent.Params.header) .Params.header }} + { + "title" : {{ jsonify .Title }}, + "date_published" : "{{ .Date }}", + {{- if not .Lastmod }} + "date_modified" : "{{ .Date }}", + {{- else }} + "date_modified" : "{{ .Lastmod }}", + {{- end }} + "id" : "{{ .Permalink }}", + "url" : "{{ .Permalink }}", + {{- with .Params.author }} + "author" : { + "name" : "{{ . }}" + }, + {{- end }} + "content_html" : {{ jsonify .Content }}, + "summary" : {{ jsonify .Summary }}, + "tags" : {{ jsonify .Params.tags }} + }{{ if ne (add $index 1) $length }}, + {{ end }} + {{- end }} + ] +} diff --git a/layouts/_default/single.json b/layouts/_default/single.json new file mode 100644 index 0000000..f4f1c34 --- /dev/null +++ b/layouts/_default/single.json @@ -0,0 +1,41 @@ +{{ $iconRoot := cond (not $.Params.iconroot) "" $.Params.iconroot }} +{{- $sp := .Site.GetPage "section" .Section }} +{{- $sh := cond (or (not $sp.Params.header) (not (fileExists (printf "static/%s" $sp.Params.header)))) (cond (or (not .Site.Home.Params.header) (not (fileExists (printf "static/%s" .Site.Home.Params.header)))) "/img/speedy.png" .Site.Home.Params.header) $sp.Params.header }} +{{- $ph := cond (or (not .Params.header) (not (fileExists (printf "static/%s" .Params.header)))) $sh .Params.header }} +{ + "version" : "https://jsonfeed.org/version/1", + "title" : "{{ .Site.Title }} :: {{ .Title }}", + "description" : "{{ if not .Description }}{{ .Title }}{{ else }}{{ .Description }}{{ end }}", + "home_page_url": "{{ .Site.BaseURL }}", + "feed_url": "{{ .Site.BaseURL }}/index.json", + "icon" : "{{ printf `%s%s` .Site.BaseURL $ph }}", + "favicon" : "{{ printf `%s%s/favicon-32x32.png` .Site.BaseURL $iconRoot }}", + {{- with .Site.Author }} + "author" : { + "name" : "{{ .name }}", + "url" : "{{ .url }}", + "avatar" : "{{ .avatar }}" + }, + {{- end }} + "items" : [ + { + "title" : {{ jsonify .Title }}, + "date_published" : "{{ .Date }}", + {{- if not .Lastmod }} + "date_modified" : "{{ .Date }}", + {{- else }} + "date_modified" : "{{ .Lastmod }}", + {{- end }} + "id" : "{{ .Permalink }}", + "url" : "{{ .Permalink }}", + {{- with .Params.author }} + "author" : { + "name" : "{{ . }}" + }, + {{- end }} + "content_html" : {{ jsonify .Content }}, + "summary" : {{ jsonify .Summary }}, + "tags" : {{ jsonify .Params.tags }} + } + ] +} diff --git a/layouts/partials/meta.html b/layouts/partials/meta.html new file mode 100644 index 0000000..9a1b702 --- /dev/null +++ b/layouts/partials/meta.html @@ -0,0 +1,13 @@ +{{ $iconRoot := cond (not $.Params.iconroot) "" $.Params.iconroot }} + + + + + + + + + + + +