Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 2 commits into from
Jan 18, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ title: Happy 1st Birthday Slash!
authors:
- name: Yangshun Tay
- slorber
tags: [birthday]
---

Happy birthday!
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ slug: /hey/my super path/héllô
title: Complex Slug
# This date is not YAML date, but we can still use it.
date: 2020/08/16
tags: [date, complex]
---

complex url slug
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
---
date: 2019-01-01
tags: [date]
---

date inside front matter
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ Array [
<updated>2020-08-16T00:00:00.000Z</updated>
<summary type=\\"html\\"><![CDATA[complex url slug]]></summary>
<content type=\\"html\\"><![CDATA[<p>complex url slug</p>]]></content>
<category label=\\"date\\" term=\\"date\\"/>
<category label=\\"complex\\" term=\\"complex\\"/>
</entry>
<entry>
<title type=\\"html\\"><![CDATA[Simple Slug]]></title>
Expand Down Expand Up @@ -71,6 +73,7 @@ Array [
<updated>2019-01-01T00:00:00.000Z</updated>
<summary type=\\"html\\"><![CDATA[date inside front matter]]></summary>
<content type=\\"html\\"><![CDATA[<p>date inside front matter</p>]]></content>
<category label=\\"date\\" term=\\"date\\"/>
</entry>
<entry>
<title type=\\"html\\"><![CDATA[Happy 1st Birthday Slash! (translated)]]></title>
Expand Down Expand Up @@ -106,23 +109,29 @@ Array [
\\"url\\": \\"https://docusaurus.io/myBaseUrl/blog/mdx-require-blog-post\\",
\\"title\\": \\"MDX Blog Sample 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\\",
\\"content_html\\": \\"<h1>HTML Heading 1</h1><h2>HTML Heading 2</h2><p>HTML Paragraph</p><div>Import DOM</div><h1>Heading 1</h1><h2>Heading 2</h2><h3>Heading 3</h3><h4>Heading 4</h4><h5>Heading 5</h5><ul><li>list1</li><li>list2</li><li>list3</li></ul><ul><li>list1</li><li>list2</li><li>list3</li></ul><p>Normal Text <em>Italics Text</em> <strong>Bold Text</strong></p><p><a href=\\\\\\"https://v2.docusaurus.io/\\\\\\">link</a>\\\\n<img src=\\\\\\"https://v2.docusaurus.io/\\\\\\" alt=\\\\\\"image\\\\\\"/></p>\\",
\\"url\\": \\"https://docusaurus.io/myBaseUrl/blog/mdx-blog-post\\",
\\"title\\": \\"Full Blog Sample\\",
\\"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ô\\",
\\"content_html\\": \\"<p>complex url slug</p>\\",
\\"url\\": \\"https://docusaurus.io/myBaseUrl/blog/hey/my super path/héllô\\",
\\"title\\": \\"Complex 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\\",
Expand All @@ -134,30 +143,36 @@ Array [
\\"author\\": {
\\"name\\": \\"Sébastien Lorber\\",
\\"url\\": \\"https://sebastienlorber.com\\"
}
},
\\"tags\\": []
},
{
\\"id\\": \\"/draft\\",
\\"content_html\\": \\"<p>this post should not be published yet</p>\\",
\\"url\\": \\"https://docusaurus.io/myBaseUrl/blog/draft\\",
\\"title\\": \\"draft\\",
\\"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\\",
\\"content_html\\": \\"\\",
\\"url\\": \\"https://docusaurus.io/myBaseUrl/blog/heading-as-title\\",
\\"title\\": \\"some heading\\",
\\"date_modified\\": \\"2019-01-02T00:00:00.000Z\\"
\\"date_modified\\": \\"2019-01-02T00:00:00.000Z\\",
\\"tags\\": []
},
{
\\"id\\": \\"/date-matter\\",
\\"content_html\\": \\"<p>date inside front matter</p>\\",
\\"url\\": \\"https://docusaurus.io/myBaseUrl/blog/date-matter\\",
\\"title\\": \\"date-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\\",
Expand All @@ -168,7 +183,8 @@ Array [
\\"date_modified\\": \\"2018-12-14T00:00:00.000Z\\",
\\"author\\": {
\\"name\\": \\"Yangshun Tay (translated)\\"
}
},
\\"tags\\": []
}
]
}",
Expand Down Expand Up @@ -213,6 +229,8 @@ Array [
<pubDate>Sun, 16 Aug 2020 00:00:00 GMT</pubDate>
<description><![CDATA[complex url slug]]></description>
<content:encoded><![CDATA[<p>complex url slug</p>]]></content:encoded>
<category>date</category>
<category>complex</category>
</item>
<item>
<title><![CDATA[Simple Slug]]></title>
Expand Down Expand Up @@ -243,6 +261,7 @@ Array [
<pubDate>Tue, 01 Jan 2019 00:00:00 GMT</pubDate>
<description><![CDATA[date inside front matter]]></description>
<content:encoded><![CDATA[<p>date inside front matter</p>]]></content:encoded>
<category>date</category>
</item>
<item>
<title><![CDATA[Happy 1st Birthday Slash! (translated)]]></title>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,9 +132,15 @@ describe('loadBlog', () => {
formattedDate: 'January 1, 2019',
frontMatter: {
date: new Date('2019-01-01'),
tags: ['date'],
},
prevItem: undefined,
tags: [],
tags: [
{
label: 'date',
permalink: '/blog/tags/date',
},
],
nextItem: {
permalink: '/blog/2018/12/14/Happy-First-Birthday-Slash',
title: 'Happy 1st Birthday Slash! (translated)',
Expand Down Expand Up @@ -207,8 +213,18 @@ describe('loadBlog', () => {
date: '2020/08/16',
slug: '/hey/my super path/héllô',
title: 'Complex Slug',
tags: ['date', 'complex'],
},
tags: [],
tags: [
{
label: 'date',
permalink: '/blog/tags/date',
},
{
label: 'complex',
permalink: '/blog/tags/complex',
},
],
truncated: false,
});

Expand Down
11 changes: 10 additions & 1 deletion packages/docusaurus-plugin-content-blog/src/feed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,14 @@ async function generateBlogFeed({
blogPosts.forEach((post) => {
const {
id,
metadata: {title: metadataTitle, permalink, date, description, authors},
metadata: {
title: metadataTitle,
permalink,
date,
description,
authors,
tags,
},
} = post;

const feedItem: FeedItem = {
Expand All @@ -78,6 +85,8 @@ async function generateBlogFeed({
link: normalizeUrl([siteUrl, permalink]),
date,
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),
};

Expand Down