feat(content-blog): include tags in feed (#6388)

* feat(content-blog): include tags in feed

* fix
This commit is contained in:
Joshua Chen 2022-01-18 17:20:37 +08:00 committed by GitHub
parent 62223ee556
commit 7bab9ba46d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 58 additions and 11 deletions

View file

@ -3,6 +3,7 @@ title: Happy 1st Birthday Slash!
authors: authors:
- name: Yangshun Tay - name: Yangshun Tay
- slorber - slorber
tags: [birthday]
--- ---
Happy birthday! Happy birthday!

View file

@ -3,6 +3,7 @@ slug: /hey/my super path/héllô
title: Complex Slug title: Complex Slug
# This date is not YAML date, but we can still use it. # This date is not YAML date, but we can still use it.
date: 2020/08/16 date: 2020/08/16
tags: [date, complex]
--- ---
complex url slug complex url slug

View file

@ -1,5 +1,6 @@
--- ---
date: 2019-01-01 date: 2019-01-01
tags: [date]
--- ---
date inside front matter date inside front matter

View file

@ -37,6 +37,8 @@ Array [
<updated>2020-08-16T00:00:00.000Z</updated> <updated>2020-08-16T00:00:00.000Z</updated>
<summary type=\\"html\\"><![CDATA[complex url slug]]></summary> <summary type=\\"html\\"><![CDATA[complex url slug]]></summary>
<content type=\\"html\\"><![CDATA[<p>complex url slug</p>]]></content> <content type=\\"html\\"><![CDATA[<p>complex url slug</p>]]></content>
<category label=\\"date\\" term=\\"date\\"/>
<category label=\\"complex\\" term=\\"complex\\"/>
</entry> </entry>
<entry> <entry>
<title type=\\"html\\"><![CDATA[Simple Slug]]></title> <title type=\\"html\\"><![CDATA[Simple Slug]]></title>
@ -71,6 +73,7 @@ Array [
<updated>2019-01-01T00:00:00.000Z</updated> <updated>2019-01-01T00:00:00.000Z</updated>
<summary type=\\"html\\"><![CDATA[date inside front matter]]></summary> <summary type=\\"html\\"><![CDATA[date inside front matter]]></summary>
<content type=\\"html\\"><![CDATA[<p>date inside front matter</p>]]></content> <content type=\\"html\\"><![CDATA[<p>date inside front matter</p>]]></content>
<category label=\\"date\\" term=\\"date\\"/>
</entry> </entry>
<entry> <entry>
<title type=\\"html\\"><![CDATA[Happy 1st Birthday Slash! (translated)]]></title> <title type=\\"html\\"><![CDATA[Happy 1st Birthday Slash! (translated)]]></title>
@ -106,7 +109,8 @@ Array [
\\"url\\": \\"https://docusaurus.io/myBaseUrl/blog/mdx-require-blog-post\\", \\"url\\": \\"https://docusaurus.io/myBaseUrl/blog/mdx-require-blog-post\\",
\\"title\\": \\"MDX Blog Sample with require calls\\", \\"title\\": \\"MDX Blog Sample with require calls\\",
\\"summary\\": \\"Test MDX with require calls\\", \\"summary\\": \\"Test MDX with require calls\\",
\\"date_modified\\": \\"2021-03-06T00:00:00.000Z\\" \\"date_modified\\": \\"2021-03-06T00:00:00.000Z\\",
\\"tags\\": []
}, },
{ {
\\"id\\": \\"/mdx-blog-post\\", \\"id\\": \\"/mdx-blog-post\\",
@ -114,7 +118,8 @@ Array [
\\"url\\": \\"https://docusaurus.io/myBaseUrl/blog/mdx-blog-post\\", \\"url\\": \\"https://docusaurus.io/myBaseUrl/blog/mdx-blog-post\\",
\\"title\\": \\"Full Blog Sample\\", \\"title\\": \\"Full Blog Sample\\",
\\"summary\\": \\"HTML Heading 1\\", \\"summary\\": \\"HTML Heading 1\\",
\\"date_modified\\": \\"2021-03-05T00:00:00.000Z\\" \\"date_modified\\": \\"2021-03-05T00:00:00.000Z\\",
\\"tags\\": []
}, },
{ {
\\"id\\": \\"/hey/my super path/héllô\\", \\"id\\": \\"/hey/my super path/héllô\\",
@ -122,7 +127,11 @@ Array [
\\"url\\": \\"https://docusaurus.io/myBaseUrl/blog/hey/my super path/héllô\\", \\"url\\": \\"https://docusaurus.io/myBaseUrl/blog/hey/my super path/héllô\\",
\\"title\\": \\"Complex Slug\\", \\"title\\": \\"Complex Slug\\",
\\"summary\\": \\"complex url slug\\", \\"summary\\": \\"complex url slug\\",
\\"date_modified\\": \\"2020-08-16T00:00:00.000Z\\" \\"date_modified\\": \\"2020-08-16T00:00:00.000Z\\",
\\"tags\\": [
\\"date\\",
\\"complex\\"
]
}, },
{ {
\\"id\\": \\"/simple/slug\\", \\"id\\": \\"/simple/slug\\",
@ -134,7 +143,8 @@ Array [
\\"author\\": { \\"author\\": {
\\"name\\": \\"Sébastien Lorber\\", \\"name\\": \\"Sébastien Lorber\\",
\\"url\\": \\"https://sebastienlorber.com\\" \\"url\\": \\"https://sebastienlorber.com\\"
} },
\\"tags\\": []
}, },
{ {
\\"id\\": \\"/draft\\", \\"id\\": \\"/draft\\",
@ -142,14 +152,16 @@ Array [
\\"url\\": \\"https://docusaurus.io/myBaseUrl/blog/draft\\", \\"url\\": \\"https://docusaurus.io/myBaseUrl/blog/draft\\",
\\"title\\": \\"draft\\", \\"title\\": \\"draft\\",
\\"summary\\": \\"this post should not be published yet\\", \\"summary\\": \\"this post should not be published yet\\",
\\"date_modified\\": \\"2020-02-27T00:00:00.000Z\\" \\"date_modified\\": \\"2020-02-27T00:00:00.000Z\\",
\\"tags\\": []
}, },
{ {
\\"id\\": \\"/heading-as-title\\", \\"id\\": \\"/heading-as-title\\",
\\"content_html\\": \\"\\", \\"content_html\\": \\"\\",
\\"url\\": \\"https://docusaurus.io/myBaseUrl/blog/heading-as-title\\", \\"url\\": \\"https://docusaurus.io/myBaseUrl/blog/heading-as-title\\",
\\"title\\": \\"some heading\\", \\"title\\": \\"some heading\\",
\\"date_modified\\": \\"2019-01-02T00:00:00.000Z\\" \\"date_modified\\": \\"2019-01-02T00:00:00.000Z\\",
\\"tags\\": []
}, },
{ {
\\"id\\": \\"/date-matter\\", \\"id\\": \\"/date-matter\\",
@ -157,7 +169,10 @@ Array [
\\"url\\": \\"https://docusaurus.io/myBaseUrl/blog/date-matter\\", \\"url\\": \\"https://docusaurus.io/myBaseUrl/blog/date-matter\\",
\\"title\\": \\"date-matter\\", \\"title\\": \\"date-matter\\",
\\"summary\\": \\"date inside front matter\\", \\"summary\\": \\"date inside front matter\\",
\\"date_modified\\": \\"2019-01-01T00:00:00.000Z\\" \\"date_modified\\": \\"2019-01-01T00:00:00.000Z\\",
\\"tags\\": [
\\"date\\"
]
}, },
{ {
\\"id\\": \\"/2018/12/14/Happy-First-Birthday-Slash\\", \\"id\\": \\"/2018/12/14/Happy-First-Birthday-Slash\\",
@ -168,7 +183,8 @@ Array [
\\"date_modified\\": \\"2018-12-14T00:00:00.000Z\\", \\"date_modified\\": \\"2018-12-14T00:00:00.000Z\\",
\\"author\\": { \\"author\\": {
\\"name\\": \\"Yangshun Tay (translated)\\" \\"name\\": \\"Yangshun Tay (translated)\\"
} },
\\"tags\\": []
} }
] ]
}", }",
@ -213,6 +229,8 @@ Array [
<pubDate>Sun, 16 Aug 2020 00:00:00 GMT</pubDate> <pubDate>Sun, 16 Aug 2020 00:00:00 GMT</pubDate>
<description><![CDATA[complex url slug]]></description> <description><![CDATA[complex url slug]]></description>
<content:encoded><![CDATA[<p>complex url slug</p>]]></content:encoded> <content:encoded><![CDATA[<p>complex url slug</p>]]></content:encoded>
<category>date</category>
<category>complex</category>
</item> </item>
<item> <item>
<title><![CDATA[Simple Slug]]></title> <title><![CDATA[Simple Slug]]></title>
@ -243,6 +261,7 @@ Array [
<pubDate>Tue, 01 Jan 2019 00:00:00 GMT</pubDate> <pubDate>Tue, 01 Jan 2019 00:00:00 GMT</pubDate>
<description><![CDATA[date inside front matter]]></description> <description><![CDATA[date inside front matter]]></description>
<content:encoded><![CDATA[<p>date inside front matter</p>]]></content:encoded> <content:encoded><![CDATA[<p>date inside front matter</p>]]></content:encoded>
<category>date</category>
</item> </item>
<item> <item>
<title><![CDATA[Happy 1st Birthday Slash! (translated)]]></title> <title><![CDATA[Happy 1st Birthday Slash! (translated)]]></title>

View file

@ -132,9 +132,15 @@ describe('loadBlog', () => {
formattedDate: 'January 1, 2019', formattedDate: 'January 1, 2019',
frontMatter: { frontMatter: {
date: new Date('2019-01-01'), date: new Date('2019-01-01'),
tags: ['date'],
}, },
prevItem: undefined, prevItem: undefined,
tags: [], tags: [
{
label: 'date',
permalink: '/blog/tags/date',
},
],
nextItem: { nextItem: {
permalink: '/blog/2018/12/14/Happy-First-Birthday-Slash', permalink: '/blog/2018/12/14/Happy-First-Birthday-Slash',
title: 'Happy 1st Birthday Slash! (translated)', title: 'Happy 1st Birthday Slash! (translated)',
@ -207,8 +213,18 @@ describe('loadBlog', () => {
date: '2020/08/16', date: '2020/08/16',
slug: '/hey/my super path/héllô', slug: '/hey/my super path/héllô',
title: 'Complex Slug', title: 'Complex Slug',
tags: ['date', 'complex'],
}, },
tags: [], tags: [
{
label: 'date',
permalink: '/blog/tags/date',
},
{
label: 'complex',
permalink: '/blog/tags/complex',
},
],
truncated: false, truncated: false,
}); });

View file

@ -69,7 +69,14 @@ async function generateBlogFeed({
blogPosts.forEach((post) => { blogPosts.forEach((post) => {
const { const {
id, id,
metadata: {title: metadataTitle, permalink, date, description, authors}, metadata: {
title: metadataTitle,
permalink,
date,
description,
authors,
tags,
},
} = post; } = post;
const feedItem: FeedItem = { const feedItem: FeedItem = {
@ -78,6 +85,8 @@ async function generateBlogFeed({
link: normalizeUrl([siteUrl, permalink]), link: normalizeUrl([siteUrl, permalink]),
date, date,
description, description,
// Atom feed demands the "term", while other feeds use "name"
category: tags.map((tag) => ({name: tag.label, term: tag.label})),
content: mdxToFeedContent(post.content), content: mdxToFeedContent(post.content),
}; };