fix atom feed, add json feed
This commit is contained in:
parent
9a712b54c8
commit
a64ea2033e
3 changed files with 46 additions and 12 deletions
|
|
@ -33,6 +33,11 @@ export const blog = {
|
||||||
title: 'Atom Feed',
|
title: 'Atom Feed',
|
||||||
url: '/feed.xml',
|
url: '/feed.xml',
|
||||||
type: 'application/atom+xml'
|
type: 'application/atom+xml'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: 'JSON Feed',
|
||||||
|
url: '/feed.json',
|
||||||
|
type: 'application/json'
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
// Tags
|
// Tags
|
||||||
|
|
|
||||||
|
|
@ -2,31 +2,28 @@
|
||||||
permalink: /feed.xml
|
permalink: /feed.xml
|
||||||
eleventyExcludeFromCollections: true
|
eleventyExcludeFromCollections: true
|
||||||
excludeFromSitemap: true
|
excludeFromSitemap: true
|
||||||
eleventyComputed:
|
|
||||||
absoluteContent: "{{ content | htmlToAbsoluteUrls(url) }}"
|
|
||||||
---
|
---
|
||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<feed xmlns="http://www.w3.org/2005/Atom" xml:base="{{ meta.url }}/">
|
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="{{ meta.lang or page.lang }}" xml:base="{{ meta.url }}/">
|
||||||
<title>{{ meta.blog.name }}</title>
|
<title>{{ meta.blog.name }}</title>
|
||||||
<subtitle>{{ meta.blog.description }}</subtitle>
|
<subtitle>{{ meta.blog.description }}</subtitle>
|
||||||
<link href="{{ meta.url }}/feed.xml" rel="self" />
|
<link href="{{ permalink | htmlBaseUrl(meta.url) }}" rel="self" />
|
||||||
<link href="{{ meta.url }}/" />
|
<link href="{{ meta.url | addPathPrefixToFullUrl }}" />
|
||||||
{% set postslist = collections.posts %}
|
|
||||||
<updated>{{ postslist | getNewestCollectionItemDate | dateToRfc3339 }}</updated>
|
<updated>{{ postslist | getNewestCollectionItemDate | dateToRfc3339 }}</updated>
|
||||||
<id>{{ meta.url }}/</id>
|
<id>{{ meta.url | addPathPrefixToFullUrl }}</id>
|
||||||
<author>
|
<author>
|
||||||
<name>{{ meta.author.name }}</name>
|
<name>{{ meta.author.name }}</name>
|
||||||
<email>{{ meta.author.email }}</email>
|
|
||||||
</author>
|
</author>
|
||||||
{%- for post in postslist -%}
|
{% set postslist = collections.posts %}
|
||||||
{%- set absolutePostUrl = post.url | absoluteUrl(meta.url) -%}
|
{%- for post in postslist | reverse -%}
|
||||||
|
{%- set absolutePostUrl = post.url | absoluteUrl(meta.url) -%}
|
||||||
<entry>
|
<entry>
|
||||||
<title>{{ post.data.title }}</title>
|
<title>{{ post.data.title }}</title>
|
||||||
<link href="{{ absolutePostUrl }}" />
|
<link href="{{ absolutePostUrl }}" />
|
||||||
<updated>{{ post.date | dateToRfc3339 }}</updated>
|
<updated>{{ post.date | dateToRfc3339 }}</updated>
|
||||||
<id>{{ absolutePostUrl }}</id>
|
<id>{{ absolutePostUrl }}</id>
|
||||||
<content xml:lang="{{ meta.locale }}" type="html">
|
<content type="html">
|
||||||
{{ post.data.absoluteContent }}
|
{{ post.content | renderTransforms(post.data.page, meta.url) }}
|
||||||
</content>
|
</content>
|
||||||
</entry>
|
</entry>
|
||||||
{%- endfor -%}
|
{%- endfor -%}
|
||||||
32
src/common/rss-json.njk
Normal file
32
src/common/rss-json.njk
Normal file
|
|
@ -0,0 +1,32 @@
|
||||||
|
---
|
||||||
|
permalink: /feed.json
|
||||||
|
eleventyExcludeFromCollections: true
|
||||||
|
excludeFromSitemap: true
|
||||||
|
---
|
||||||
|
{
|
||||||
|
"version": "https://jsonfeed.org/version/1.1",
|
||||||
|
"title": "{{ meta.blog.name }}",
|
||||||
|
"language": "{{ meta.lang or page.lang }}",
|
||||||
|
"home_page_url": "{{ meta.url | addPathPrefixToFullUrl }}",
|
||||||
|
"feed_url": "{{ permalink | htmlBaseUrl(meta.url) }}",
|
||||||
|
"description": "{{ meta.blog.description }}",
|
||||||
|
"authors": [
|
||||||
|
{
|
||||||
|
"name": "{{ meta.author.name }}"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"items": [
|
||||||
|
{%- set postslist = collections.posts -%}
|
||||||
|
{%- for post in postslist | reverse -%}
|
||||||
|
{%- set absolutePostUrl = post.url | absoluteUrl(meta.url) -%}
|
||||||
|
{
|
||||||
|
"id": "{{ absolutePostUrl }}",
|
||||||
|
"url": "{{ absolutePostUrl }}",
|
||||||
|
"title": "{{ post.data.title }}",
|
||||||
|
"content_html": {% if post.content %}{{ post.content | renderTransforms(post.data.page, metadata.base) | dump | safe }}{% else %}""{% endif %},
|
||||||
|
"date_published": "{{ post.date | dateToRfc3339 }}"
|
||||||
|
}
|
||||||
|
{% if not loop.last %},{% endif %}
|
||||||
|
{%- endfor %}
|
||||||
|
]
|
||||||
|
}
|
||||||
Loading…
Reference in a new issue