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(blog): add feed XSLT options to render beautiful RSS and Atom feeds #9252

Merged
merged 41 commits into from
Aug 2, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
b62999a
feat(rss feed): added xslt for rss feed
Xebec19 Aug 23, 2023
a67a71f
Merge branch 'facebook:main' into main
Xebec19 Aug 25, 2023
25dff7b
Merge branch 'facebook:main' into main
Xebec19 Sep 3, 2023
3b02024
feat(rss feed): made xslt feed modular and added custom feeds
Xebec19 Sep 3, 2023
e5e066a
type
OzakIOne Jul 24, 2024
d9a69b7
await
OzakIOne Jul 24, 2024
034bb82
object params
OzakIOne Jul 24, 2024
3745125
refactor options, refactor build / assets
OzakIOne Jul 25, 2024
1daded2
refactor assets location
OzakIOne Jul 25, 2024
c79902b
more refactor
OzakIOne Jul 25, 2024
5454916
refactor
OzakIOne Jul 25, 2024
64538d5
Merge branch 'main' into Xebec19/main
OzakIOne Jul 26, 2024
e611d06
fix tests
OzakIOne Jul 26, 2024
76d198b
fix custom test
OzakIOne Jul 26, 2024
d59b38c
fix test
OzakIOne Jul 26, 2024
268906a
fix test
OzakIOne Jul 26, 2024
be1f67c
feat: refactor in switch
OzakIOne Jul 29, 2024
1f65318
format & dogfood
OzakIOne Jul 29, 2024
1653ed2
remove unused file
OzakIOne Jul 29, 2024
7096aff
refactor options to object
OzakIOne Jul 30, 2024
dcc797f
fix tests
OzakIOne Jul 30, 2024
298dd54
Merge branch 'main' into Xebec19/main
slorber Aug 1, 2024
b25cb9f
rename XslParams to FeedXSLTOptions
slorber Aug 1, 2024
2500197
type problem
slorber Aug 1, 2024
66f5b11
add proper feed xslt options + unit tests
slorber Aug 2, 2024
06a7b21
Merge branch 'main' into Xebec19/main
slorber Aug 2, 2024
d46a073
fix blog feed tests
slorber Aug 2, 2024
f2e0629
Add xslt options to init templates
slorber Aug 2, 2024
952da63
move xsl assets around
slorber Aug 2, 2024
988214d
use .xsl extension (more common) instead of .xslt
slorber Aug 2, 2024
6092f1d
use .xsl extension (more common) instead of .xslt
slorber Aug 2, 2024
5f1dc94
use .xsl extension (more common) instead of .xslt
slorber Aug 2, 2024
81e80fd
refactor feed xslt impl
slorber Aug 2, 2024
03647e2
capture blog tree snapshot
slorber Aug 2, 2024
7d2c181
add extra comment + missing build snap files
slorber Aug 2, 2024
d1a99ab
cspell ignore .xsl
slorber Aug 2, 2024
8c9e374
add xslt to project words
slorber Aug 2, 2024
c421e3b
fix bad spelling
slorber Aug 2, 2024
cbb91f9
Polish Blog feed default XSL/CSS
slorber Aug 2, 2024
221e695
add docs for FeedXSLTOptions
slorber Aug 2, 2024
3e55314
update test snapshots
slorber Aug 2, 2024
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 @@ -2,7 +2,7 @@

exports[`atom filters to the first two entries 1`] = `
[
"<?xml version="1.0" encoding="utf-8"?>
"<?xml version="1.0" encoding="utf-8"?><?xml-stylesheet type="text/xsl" href="/rss.xslt"?>
<feed xmlns="http://www.w3.org/2005/Atom">
<id>https://docusaurus.io/myBaseUrl/blog</id>
<title>Hello Blog</title>
Expand Down Expand Up @@ -48,7 +48,7 @@ exports[`atom filters to the first two entries 1`] = `

exports[`atom filters to the first two entries using limit 1`] = `
[
"<?xml version="1.0" encoding="utf-8"?>
"<?xml version="1.0" encoding="utf-8"?><?xml-stylesheet type="text/xsl" href="/rss.xslt"?>
<feed xmlns="http://www.w3.org/2005/Atom">
<id>https://docusaurus.io/myBaseUrl/blog</id>
<title>Hello Blog</title>
Expand Down Expand Up @@ -94,7 +94,7 @@ exports[`atom filters to the first two entries using limit 1`] = `

exports[`atom has feed item for each post 1`] = `
[
"<?xml version="1.0" encoding="utf-8"?>
"<?xml version="1.0" encoding="utf-8"?><?xml-stylesheet type="text/xsl" href="/rss.xslt"?>
<feed xmlns="http://www.w3.org/2005/Atom">
<id>https://docusaurus.io/myBaseUrl/blog</id>
<title>Hello Blog</title>
Expand Down Expand Up @@ -380,7 +380,7 @@ exports[`json has feed item for each post 1`] = `

exports[`rss filters to the first two entries 1`] = `
[
"<?xml version="1.0" encoding="utf-8"?>
"<?xml version="1.0" encoding="utf-8"?><?xml-stylesheet type="text/xsl" href="/rss.xslt"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/">
<channel>
<title>Hello Blog</title>
Expand Down Expand Up @@ -428,7 +428,7 @@ exports[`rss filters to the first two entries 1`] = `

exports[`rss filters to the first two entries using limit 1`] = `
[
"<?xml version="1.0" encoding="utf-8"?>
"<?xml version="1.0" encoding="utf-8"?><?xml-stylesheet type="text/xsl" href="/rss.xslt"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/">
<channel>
<title>Hello Blog</title>
Expand Down Expand Up @@ -476,7 +476,7 @@ exports[`rss filters to the first two entries using limit 1`] = `

exports[`rss has feed item for each post 1`] = `
[
"<?xml version="1.0" encoding="utf-8"?>
"<?xml version="1.0" encoding="utf-8"?><?xml-stylesheet type="text/xsl" href="/rss.xslt"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/">
<channel>
<title>Hello Blog</title>
Expand Down
17 changes: 15 additions & 2 deletions packages/docusaurus-plugin-content-blog/src/feed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ async function createBlogFeedFile({
feedType: FeedType;
generatePath: string;
}) {
const [feedContent, feedPath] = (() => {
const feedDetails = (() => {
switch (feedType) {
case 'rss':
return [feed.rss2(), 'rss.xml'];
Expand All @@ -187,7 +187,20 @@ async function createBlogFeedFile({
}
})();
try {
await fs.outputFile(path.join(generatePath, feedPath), feedContent);
const xsltLink =
'<?xml version="1.0" encoding="utf-8"?><?xml-stylesheet type="text/xsl" href="/rss.xslt"?>';

if (feedDetails[1] !== 'feed.json' && feedDetails[0]) {
feedDetails[0] = feedDetails[0]?.replace(
'<?xml version="1.0" encoding="utf-8"?>',
xsltLink,
);
}
Xebec19 marked this conversation as resolved.
Show resolved Hide resolved

await fs.outputFile(
path.join(generatePath, `${feedDetails[1]}`),
feedDetails[0],
);
} catch (err) {
logger.error(`Generating ${feedType} feed failed.`);
throw err;
Expand Down
33 changes: 33 additions & 0 deletions website/static/rss.xslt
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:template match="/">
<html>
<head>
<title>Blog Information</title>
<link rel="stylesheet" type="text/css" href="/styles.css" />
</head>
<body>
<main class="markdown">
<div class="description">
<h1><xsl:value-of select="rss/channel/title"/></h1>
<p>Description: <xsl:value-of select="rss/channel/description"/></p>
<p>Last Build Date: <xsl:value-of select="substring(rss/channel/lastBuildDate,0,11)"/></p>
<p>Language: <xsl:value-of select="rss/channel/language"/></p>
</div>
<h2>Recent Posts</h2>
<ul class="postsList">
<xsl:for-each select="rss/channel/item">
<li>
<a href="{link}">
<xsl:value-of select="title"/>
</a>
</li>
</xsl:for-each>
</ul>
</main>
</body>
</html>
</xsl:template>

</xsl:stylesheet>
Xebec19 marked this conversation as resolved.
Show resolved Hide resolved
35 changes: 35 additions & 0 deletions website/static/styles.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/**
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/

.markdown {
padding: 4rem;
margin: auto;
text-align: center;
/* stylelint-disable-next-line font-family-name-quotes */
font-family: system-ui, -apple-system, Segoe UI, Roboto, Ubuntu;
line-height: 1.65;
}

.col,
.container {
padding: 0 var(--ifm-spacing-horizontal);
width: 100%;
}

.markdown li,
body {
word-wrap: break-word;
list-style: none;
}

body,
ol ol,
ol ul,
ul ol,
ul ul {
margin: 0 auto;
}
Xebec19 marked this conversation as resolved.
Show resolved Hide resolved
Loading