Commit b0dff1a8 authored by Kaushal Modi's avatar Kaushal Modi

Move JF2 custom output format to a Hugo theme component repo

https://github.com/kaushalmodi/hugo-jf2
parent 6c250004
......@@ -8,6 +8,7 @@ To use this theme, you need to clone this theme and the components too:
cd HUGO_SITE_DIR/themes
git clone https://gitlab.com/kaushalmodi/hugo-theme-refined refined
git clone https://github.com/kaushalmodi/hugo-atom-feed hugo-atom-feed
git clone https://github.com/kaushalmodi/hugo-jf2 hugo-jf2
git clone https://github.com/kaushalmodi/hugo-debugprint hugo-debugprint
#+end_example
* Theme variables
......
theme = ["hugo-debugprint", "hugo-atom-feed", "refined"]
# Custom Output Formats defined: "JF2Post", "JF2Feed"
# JF2 - https://www.w3.org/TR/jf2/
# JF2 post
# Add "JF2Post" to the Page Kinds under [outputs] (in your site config) for which
# you want to enable JF2Post. As it is JF2 for posts, it would usually be only
# for the "page" kind.
# Example:
# [outputs]
# page = ["HTML", "JF2Post"]
[mediaTypes."application/jf2post"]
suffix = "json"
[outputFormats.JF2Post]
mediaType = "application/jf2post"
baseName = "jf2post" # generated file = <baseName>.<mediaType."application/jf2post".suffix> = jf2post.json
isPlainText = true
# JF2 feed
# Add "JF2Feed" to the Page Kinds under [outputs] (in your site config) for which
# you want to enable Jf2Feed feeds. As it is JF2 for feeds, it would usually be only
# for the list Page Kinds.
# Example:
# [outputs]
# home = ["HTML", "JF2Feed"]
# section = ["HTML", "JF2Feed"]
# taxonomy = ["HTML", "JF2Feed"]
# taxonomyTerm = ["HTML", "JF2Feed"]
[mediaTypes."application/jf2feed"]
suffix = "json"
[outputFormats.JF2Feed]
mediaType = "application/jf2feed"
baseName = "jf2feed" # generated file = <baseName>.<mediaType."application/jf2feed".suffix> = jf2feed.json
isPlainText = true
theme = ["hugo-debugprint", "hugo-atom-feed", "hugo-jf2", "refined"]
# Default values of custom .Site.Params
[Params]
......
{{/*
https://www.w3.org/TR/jf2/#jf2feed_example
{
"type": "feed",
"url": "https://example.org/myfeed.html",
"name": "Brent Simmons’s Microblog",
"author": {
"type": "card",
"name": "Brent Simmons",
"url": "http://example.org/",
"photo": "https://example.org/avatar.png"
},
"children": [
{
"type": "entry",
"uid": "https://example.org/2347259",
"url": "https://example.org/2347259",
"content": {
"text": "Cats are neat. \n\nhttps://example.org/cats"
},
"published": "2016-02-09T14:22:00-07:00"
}
]
}
*/}}
{{- $.Scratch.Add "jf2feed" slice -}}
{{- range (where .Pages "Type" "in" .Site.Params.mainSections) -}}
{{- $summary_html := (or (.Description | markdownify) .Summary) -}}
{{- $.Scratch.Add "jf2feed" (dict "type" "entry" "url" .Permalink "published" .Date "name" .Title "summary" ((or (.Description | markdownify) .Summary) | plainify) "content" (dict "html" .Content "text" .Plain)) -}}
{{- end -}}
{{- $jf2 := (dict "type" "feed" "url" .Permalink "name" .Title "author" (dict "type" "card" "url" $.Site.BaseURL "name" $.Site.Author.name) "children" ($.Scratch.Get "jf2feed")) -}}
{{- $jf2 | jsonify -}}
{{/*
https://www.w3.org/TR/jf2/#simplified-json
{
"type": "entry",
"author": {
"type": "card",
"url": "http://example.com",
"name": "A. Developer"
},
"url": "http://example.com/2015/10/21",
"published": "2015-10-21T12:00:00-0700",
"name": "Hello World",
"summary": "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vivamus imperdiet ultrices pulvinar.",
"content": {
"html": "<p>Donec dapibus enim lacus, <i>a vehicula magna bibendum non</i>. Phasellus id lacinia felis, vitae pellentesque enim. Sed at quam dui. Suspendisse accumsan, est id pulvinar consequat, urna ex tincidunt enim, nec sodales lectus nulla et augue. Cras venenatis vehicula molestie. Donec sagittis elit orci, sit amet egestas ex pharetra in.</p>",
"text": "Donec dapibus enim lacus, a vehicula magna bibendum non. Phasellus id lacinia felis, vitae pellentesque enim. Sed at quam dui. Suspendisse accumsan, est id pulvinar consequat, urna ex tincidunt enim, nec sodales lectus nulla et augue. Cras venenatis vehicula molestie. Donec sagittis elit orci, sit amet egestas ex pharetra in."
}
}
*/}}
{{- $jf2 := (dict "type" "entry" "author" (dict "type" "card" "url" $.Site.BaseURL "name" $.Site.Author.name) "url" .Permalink "published" .Date "name" .Title "summary" ((or (.Description | markdownify) .Summary) | plainify) "content" (dict "html" .Content "text" .Plain)) -}}
{{- $jf2 | jsonify -}}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment