From b62999aba795f73bca06f76f2e46419ce5c28952 Mon Sep 17 00:00:00 2001 From: xebec19 Date: Wed, 23 Aug 2023 23:35:11 +0530 Subject: [PATCH 01/36] feat(rss feed): added xslt for rss feed --- .../__tests__/__snapshots__/feed.test.ts.snap | 12 +++---- .../src/feed.ts | 17 +++++++-- website/static/rss.xslt | 33 +++++++++++++++++ website/static/styles.css | 35 +++++++++++++++++++ 4 files changed, 89 insertions(+), 8 deletions(-) create mode 100644 website/static/rss.xslt create mode 100644 website/static/styles.css diff --git a/packages/docusaurus-plugin-content-blog/src/__tests__/__snapshots__/feed.test.ts.snap b/packages/docusaurus-plugin-content-blog/src/__tests__/__snapshots__/feed.test.ts.snap index 8af04cf9ae22..faa3d6444520 100644 --- a/packages/docusaurus-plugin-content-blog/src/__tests__/__snapshots__/feed.test.ts.snap +++ b/packages/docusaurus-plugin-content-blog/src/__tests__/__snapshots__/feed.test.ts.snap @@ -2,7 +2,7 @@ exports[`atom filters to the first two entries 1`] = ` [ - " + " https://docusaurus.io/myBaseUrl/blog Hello Blog @@ -48,7 +48,7 @@ exports[`atom filters to the first two entries 1`] = ` exports[`atom filters to the first two entries using limit 1`] = ` [ - " + " https://docusaurus.io/myBaseUrl/blog Hello Blog @@ -94,7 +94,7 @@ exports[`atom filters to the first two entries using limit 1`] = ` exports[`atom has feed item for each post 1`] = ` [ - " + " https://docusaurus.io/myBaseUrl/blog Hello Blog @@ -380,7 +380,7 @@ exports[`json has feed item for each post 1`] = ` exports[`rss filters to the first two entries 1`] = ` [ - " + " Hello Blog @@ -428,7 +428,7 @@ exports[`rss filters to the first two entries 1`] = ` exports[`rss filters to the first two entries using limit 1`] = ` [ - " + " Hello Blog @@ -476,7 +476,7 @@ exports[`rss filters to the first two entries using limit 1`] = ` exports[`rss has feed item for each post 1`] = ` [ - " + " Hello Blog diff --git a/packages/docusaurus-plugin-content-blog/src/feed.ts b/packages/docusaurus-plugin-content-blog/src/feed.ts index 22b7f53cbb80..4f4c2a6f5a3a 100644 --- a/packages/docusaurus-plugin-content-blog/src/feed.ts +++ b/packages/docusaurus-plugin-content-blog/src/feed.ts @@ -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']; @@ -187,7 +187,20 @@ async function createBlogFeedFile({ } })(); try { - await fs.outputFile(path.join(generatePath, feedPath), feedContent); + const xsltLink = + ''; + + if (feedDetails[1] !== 'feed.json' && feedDetails[0]) { + feedDetails[0] = feedDetails[0]?.replace( + '', + xsltLink, + ); + } + + await fs.outputFile( + path.join(generatePath, `${feedDetails[1]}`), + feedDetails[0], + ); } catch (err) { logger.error(`Generating ${feedType} feed failed.`); throw err; diff --git a/website/static/rss.xslt b/website/static/rss.xslt new file mode 100644 index 000000000000..40cb219efc74 --- /dev/null +++ b/website/static/rss.xslt @@ -0,0 +1,33 @@ + + + + + + + Blog Information + + + +
+
+

+

Description:

+

Last Build Date:

+

Language:

+
+

Recent Posts

+ +
+ + +
+ +
diff --git a/website/static/styles.css b/website/static/styles.css new file mode 100644 index 000000000000..55d607bb351a --- /dev/null +++ b/website/static/styles.css @@ -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; +} From 3b0202479a81ad97db7c3d9347b6ba8ab900821f Mon Sep 17 00:00:00 2001 From: xebec19 Date: Sun, 3 Sep 2023 13:39:15 +0530 Subject: [PATCH 02/36] feat(rss feed): made xslt feed modular and added custom feeds --- .cspell.json | 1 + .../assets/atom-feed.stylesheet.css | 72 + .../assets/atom-feed.xslt | 65 + .../assets/rss-feed.stylesheet.css | 72 + .../assets/rss-feed.xslt | 66 + .../build-snap/blog/rss-feed.stylesheet.css | 68 + .../__tests__/__snapshots__/feed.test.ts.snap | 1686 ++++++++++++++--- .../src/__tests__/feed.test.ts | 92 + .../src/feed.ts | 129 +- .../src/options.ts | 5 + .../src/plugin-content-blog.d.ts | 9 + website/_dogfooding/dogfooding.config.js | 5 + website/docusaurus.config.js | 3 + website/static/custom-atom.stylesheet.xslt | 65 + website/static/custom-rss.stylesheet.xslt | 66 + website/static/rss.xslt | 33 - website/static/styles.css | 35 - website/static/xslt-stylesheet.css | 76 + 18 files changed, 2250 insertions(+), 298 deletions(-) create mode 100644 packages/docusaurus-plugin-content-blog/assets/atom-feed.stylesheet.css create mode 100644 packages/docusaurus-plugin-content-blog/assets/atom-feed.xslt create mode 100644 packages/docusaurus-plugin-content-blog/assets/rss-feed.stylesheet.css create mode 100644 packages/docusaurus-plugin-content-blog/assets/rss-feed.xslt create mode 100644 packages/docusaurus-plugin-content-blog/src/__tests__/__fixtures__/website/build-snap/blog/rss-feed.stylesheet.css create mode 100644 website/static/custom-atom.stylesheet.xslt create mode 100644 website/static/custom-rss.stylesheet.xslt delete mode 100644 website/static/rss.xslt delete mode 100644 website/static/styles.css create mode 100644 website/static/xslt-stylesheet.css diff --git a/.cspell.json b/.cspell.json index 792ec239195d..b5579c09ab93 100644 --- a/.cspell.json +++ b/.cspell.json @@ -31,6 +31,7 @@ "website/docusaurus.config.localized.json", "*.xyz", "*.docx", + "*.xslt", "*.gitignore", "versioned_docs", "*.min.*", diff --git a/packages/docusaurus-plugin-content-blog/assets/atom-feed.stylesheet.css b/packages/docusaurus-plugin-content-blog/assets/atom-feed.stylesheet.css new file mode 100644 index 000000000000..17d483670f0d --- /dev/null +++ b/packages/docusaurus-plugin-content-blog/assets/atom-feed.stylesheet.css @@ -0,0 +1,72 @@ +/** + * 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. + */ + +main { + flex: 1 0 auto; + width: 100%; + margin: 4rem auto; + padding: 1.5 rem; + max-width: 800px; + /* stylelint-disable-next-line font-family-name-quotes */ + font-family: system-ui, -apple-system, Segoe UI, Roboto, Ubuntu, Cantarell; +} + +.info { + display: block; + margin: 3rem 0; + padding: 2rem 3rem; + border: 1px solid dodgerblue; + border-left-width: 0.5rem; + border-radius: 0.4rem; + background-color: #edf5ff; +} + +.rss-icon { + height: 3.8rem; + width: 3.8rem; + margin-right: 1rem; +} + +.flex { + display: flex; +} + +.items-start { + align-items: flex-start; +} + +.pb-7 { + padding-bottom: 3rem; +} + +a { + color: #005aff; + text-decoration: none; +} + +h1 { + text-wrap: balance; + font-size: 3.8rem; + line-height: 1; + font-weight: 800; + margin-bottom: 4rem; +} + +h2 { + font-size: 3rem; + line-height: 1.2; + font-weight: 700; + margin-bottom: 3rem; +} + +h2:not(:first-child) { + margin-top: 5.8rem; +} + +.italic { + font-style: italic; +} diff --git a/packages/docusaurus-plugin-content-blog/assets/atom-feed.xslt b/packages/docusaurus-plugin-content-blog/assets/atom-feed.xslt new file mode 100644 index 000000000000..d619961df098 --- /dev/null +++ b/packages/docusaurus-plugin-content-blog/assets/atom-feed.xslt @@ -0,0 +1,65 @@ + + + + + + + + + Atom Feed | <xsl:value-of select="atom:feed/atom:title" /> + + + +
+
+
+ This is an Atom feed. Subscribe by copying the URL from the address + bar into your newsreader. Visit About Feeds to learn more + and get started. It’s free.
+

+
+ + + + + + + + + + +
+ Atom Feed Preview

+

+ +

+

Description:

+
+

Recent Posts

+
+ +
+ + + +
Published on +
+
+ +
+
+
+
+
+ + +
+ +
\ No newline at end of file diff --git a/packages/docusaurus-plugin-content-blog/assets/rss-feed.stylesheet.css b/packages/docusaurus-plugin-content-blog/assets/rss-feed.stylesheet.css new file mode 100644 index 000000000000..17d483670f0d --- /dev/null +++ b/packages/docusaurus-plugin-content-blog/assets/rss-feed.stylesheet.css @@ -0,0 +1,72 @@ +/** + * 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. + */ + +main { + flex: 1 0 auto; + width: 100%; + margin: 4rem auto; + padding: 1.5 rem; + max-width: 800px; + /* stylelint-disable-next-line font-family-name-quotes */ + font-family: system-ui, -apple-system, Segoe UI, Roboto, Ubuntu, Cantarell; +} + +.info { + display: block; + margin: 3rem 0; + padding: 2rem 3rem; + border: 1px solid dodgerblue; + border-left-width: 0.5rem; + border-radius: 0.4rem; + background-color: #edf5ff; +} + +.rss-icon { + height: 3.8rem; + width: 3.8rem; + margin-right: 1rem; +} + +.flex { + display: flex; +} + +.items-start { + align-items: flex-start; +} + +.pb-7 { + padding-bottom: 3rem; +} + +a { + color: #005aff; + text-decoration: none; +} + +h1 { + text-wrap: balance; + font-size: 3.8rem; + line-height: 1; + font-weight: 800; + margin-bottom: 4rem; +} + +h2 { + font-size: 3rem; + line-height: 1.2; + font-weight: 700; + margin-bottom: 3rem; +} + +h2:not(:first-child) { + margin-top: 5.8rem; +} + +.italic { + font-style: italic; +} diff --git a/packages/docusaurus-plugin-content-blog/assets/rss-feed.xslt b/packages/docusaurus-plugin-content-blog/assets/rss-feed.xslt new file mode 100644 index 000000000000..c8a4c85780f1 --- /dev/null +++ b/packages/docusaurus-plugin-content-blog/assets/rss-feed.xslt @@ -0,0 +1,66 @@ + + + + + + + + + RSS Feed | <xsl:value-of select="rss/channel/title" /> + + + +
+
+
+ This is an RSS feed. Subscribe by copying the URL from the address + bar into your newsreader. Visit About Feeds to learn more + and get started. It’s free.
+

+
+ + + + + + + + + + +
+ RSS Feed Preview

+

+ +

+

Description:

+
+

Recent Posts

+
+ +
+ + + +
Published on +
+
+ +
+
+
+
+
+ + +
+ +
\ No newline at end of file diff --git a/packages/docusaurus-plugin-content-blog/src/__tests__/__fixtures__/website/build-snap/blog/rss-feed.stylesheet.css b/packages/docusaurus-plugin-content-blog/src/__tests__/__fixtures__/website/build-snap/blog/rss-feed.stylesheet.css new file mode 100644 index 000000000000..2be936239e3b --- /dev/null +++ b/packages/docusaurus-plugin-content-blog/src/__tests__/__fixtures__/website/build-snap/blog/rss-feed.stylesheet.css @@ -0,0 +1,68 @@ +/** + * 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. + */ + +main { + flex: 1 0 auto; + width: 100%; + margin: 4rem auto; + padding: 1.5 rem; + max-width: 800px; + /* stylelint-disable-next-line font-family-name-quotes */ + font-family: system-ui, -apple-system, Segoe UI, Roboto, Ubuntu, Cantarell; +} + +.info { + display: block; + margin: 3rem 0; + padding: 2rem 3rem; + border: 1px solid dodgerblue; + border-left-width: 0.5rem; + border-radius: 0.4rem; + background-color: #edf5ff; +} + +.rss-icon { + height: 3.8rem; + width: 3.8rem; + margin-right: 1rem; +} + +.flex { + display: flex; +} + +.items-start { + align-items: flex-start; +} + +.pb-7 { + padding-bottom: 3rem; +} + +a { + color: #005aff; + text-decoration: none; +} + +h1 { + text-wrap: balance; + font-size: 3.8rem; + line-height: 1; + font-weight: 800; + margin-bottom: 4rem; +} + +h2 { + font-size: 3rem; + line-height: 1.2; + font-weight: 700; + margin-bottom: 3rem; +} + +h2:not(:first-child) { + margin-top: 5.8rem; +} diff --git a/packages/docusaurus-plugin-content-blog/src/__tests__/__snapshots__/feed.test.ts.snap b/packages/docusaurus-plugin-content-blog/src/__tests__/__snapshots__/feed.test.ts.snap index faa3d6444520..23679d1dd731 100644 --- a/packages/docusaurus-plugin-content-blog/src/__tests__/__snapshots__/feed.test.ts.snap +++ b/packages/docusaurus-plugin-content-blog/src/__tests__/__snapshots__/feed.test.ts.snap @@ -2,7 +2,7 @@ exports[`atom filters to the first two entries 1`] = ` [ - " + " https://docusaurus.io/myBaseUrl/blog Hello Blog @@ -48,7 +48,7 @@ exports[`atom filters to the first two entries 1`] = ` exports[`atom filters to the first two entries using limit 1`] = ` [ - " + " https://docusaurus.io/myBaseUrl/blog Hello Blog @@ -92,9 +92,147 @@ exports[`atom filters to the first two entries using limit 1`] = ` ] `; -exports[`atom has feed item for each post 1`] = ` +exports[`atom has custom xslt files for feed 1`] = ` [ - " + " + + + + + + + + Atom Feed | <xsl:value-of select="atom:feed/atom:title" /> + + + +
+
+
+ This is an Atom feed. Subscribe by copying the URL from the address + bar into your newsreader. Visit About Feeds to learn more + and get started. It’s free.
+

+
+ + + + + + + + + + +
+ Atom Feed Preview

+

+ +

+

Description:

+
+

Recent Posts

+
+ +
+ + + +
Published on +
+
+ +
+
+
+
+
+ + +
+ +
", + "/** + * 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. + */ + +main { + flex: 1 0 auto; + width: 100%; + margin: 4rem auto; + padding: 1.5 rem; + max-width: 800px; + /* stylelint-disable-next-line font-family-name-quotes */ + font-family: system-ui, -apple-system, Segoe UI, Roboto, Ubuntu, Cantarell; +} + +.info { + display: block; + margin: 3rem 0; + padding: 2rem 3rem; + border: 1px solid dodgerblue; + border-left-width: 0.5rem; + border-radius: 0.4rem; + background-color: #edf5ff; +} + +.rss-icon { + height: 3.8rem; + width: 3.8rem; + margin-right: 1rem; +} + +.flex { + display: flex; +} + +.items-start { + align-items: flex-start; +} + +.pb-7 { + padding-bottom: 3rem; +} + +a { + color: #005aff; + text-decoration: none; +} + +h1 { + text-wrap: balance; + font-size: 3.8rem; + line-height: 1; + font-weight: 800; + margin-bottom: 4rem; +} + +h2 { + font-size: 3rem; + line-height: 1.2; + font-weight: 700; + margin-bottom: 3rem; +} + +h2:not(:first-child) { + margin-top: 5.8rem; +} + +.italic { + font-style: italic; +} +", + " https://docusaurus.io/myBaseUrl/blog Hello Blog @@ -220,184 +358,25 @@ exports[`atom has feed item for each post 1`] = ` ] `; -exports[`json filters to the first two entries 1`] = ` -[ - "{ - "version": "https://jsonfeed.org/version/1", - "title": "Hello Blog", - "home_page_url": "https://docusaurus.io/myBaseUrl/blog", - "description": "Hello Blog", - "items": [ - { - "id": "https://docusaurus.io/myBaseUrl/blog/blog-with-links", - "content_html": "

absolute full url

/n

absolute pathname

/n

relative pathname

/n

md link

/n

anchor

/n

relative pathname + anchor

/n

/n

\\"\\"

/n/n", - "url": "https://docusaurus.io/myBaseUrl/blog/blog-with-links", - "title": "test links", - "summary": "absolute full url", - "date_modified": "2023-07-23T00:00:00.000Z", - "tags": [] - }, - { - "id": "https://docusaurus.io/myBaseUrl/blog/mdx-require-blog-post", - "content_html": "

Test MDX with require calls

/n/n/n/n/n", - "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", - "tags": [] - } - ] -}", -] -`; - -exports[`json filters to the first two entries using limit 1`] = ` -[ - "{ - "version": "https://jsonfeed.org/version/1", - "title": "Hello Blog", - "home_page_url": "https://docusaurus.io/myBaseUrl/blog", - "description": "Hello Blog", - "items": [ - { - "id": "https://docusaurus.io/myBaseUrl/blog/blog-with-links", - "content_html": "

absolute full url

/n

absolute pathname

/n

relative pathname

/n

md link

/n

anchor

/n

relative pathname + anchor

/n

/n

\\"\\"

/n/n", - "url": "https://docusaurus.io/myBaseUrl/blog/blog-with-links", - "title": "test links", - "summary": "absolute full url", - "date_modified": "2023-07-23T00:00:00.000Z", - "tags": [] - }, - { - "id": "https://docusaurus.io/myBaseUrl/blog/mdx-require-blog-post", - "content_html": "

Test MDX with require calls

/n/n/n/n/n", - "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", - "tags": [] - } - ] -}", -] -`; - -exports[`json has feed item for each post 1`] = ` -[ - "{ - "version": "https://jsonfeed.org/version/1", - "title": "Hello Blog", - "home_page_url": "https://docusaurus.io/myBaseUrl/blog", - "description": "Hello Blog", - "items": [ - { - "id": "https://docusaurus.io/myBaseUrl/blog/blog-with-links", - "content_html": "

absolute full url

/n

absolute pathname

/n

relative pathname

/n

md link

/n

anchor

/n

relative pathname + anchor

/n

/n

\\"\\"

/n/n", - "url": "https://docusaurus.io/myBaseUrl/blog/blog-with-links", - "title": "test links", - "summary": "absolute full url", - "date_modified": "2023-07-23T00:00:00.000Z", - "tags": [] - }, - { - "id": "https://docusaurus.io/myBaseUrl/blog/mdx-require-blog-post", - "content_html": "

Test MDX with require calls

/n/n/n/n/n", - "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", - "tags": [] - }, - { - "id": "https://docusaurus.io/myBaseUrl/blog/mdx-blog-post", - "content_html": "

HTML Heading 1

/n

HTML Heading 2

/n

HTML Paragraph

/n/n/n

Import DOM

/n

Heading 1

/n

Heading 2

/n

Heading 3

/n

Heading 4

/n
Heading 5
/n
    /n
  • list1
  • /n
  • list2
  • /n
  • list3
  • /n
/n
    /n
  • list1
  • /n
  • list2
  • /n
  • list3
  • /n
/n

Normal Text Italics Text Bold Text

/n

link \\"image\\"

", - "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", - "tags": [] - }, - { - "id": "https://docusaurus.io/myBaseUrl/blog/hey/my super path/héllô", - "content_html": "

complex url slug

", - "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", - "tags": [ - "date", - "complex" - ] - }, - { - "id": "https://docusaurus.io/myBaseUrl/blog/simple/slug", - "content_html": "

simple url slug

", - "url": "https://docusaurus.io/myBaseUrl/blog/simple/slug", - "title": "Simple Slug", - "summary": "simple url slug", - "date_modified": "2020-08-15T00:00:00.000Z", - "author": { - "name": "Sébastien Lorber", - "url": "https://sebastienlorber.com" - }, - "tags": [] - }, - { - "id": "https://docusaurus.io/myBaseUrl/blog/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", - "tags": [] - }, - { - "id": "https://docusaurus.io/myBaseUrl/blog/date-matter", - "content_html": "

date inside front matter

", - "url": "https://docusaurus.io/myBaseUrl/blog/date-matter", - "title": "date-matter", - "summary": "date inside front matter", - "date_modified": "2019-01-01T00:00:00.000Z", - "tags": [ - "date" - ] - }, - { - "id": "https://docusaurus.io/myBaseUrl/blog/2018/12/14/Happy-First-Birthday-Slash", - "content_html": "

Happy birthday! (translated)

", - "url": "https://docusaurus.io/myBaseUrl/blog/2018/12/14/Happy-First-Birthday-Slash", - "title": "Happy 1st Birthday Slash! (translated)", - "summary": "Happy birthday! (translated)", - "date_modified": "2018-12-14T00:00:00.000Z", - "author": { - "name": "Yangshun Tay (translated)" - }, - "tags": [] - } - ] -}", -] -`; - -exports[`rss filters to the first two entries 1`] = ` +exports[`atom has feed item for each post 1`] = ` [ - " - - - Hello Blog - https://docusaurus.io/myBaseUrl/blog - Hello Blog - Sun, 23 Jul 2023 00:00:00 GMT - https://validator.w3.org/feed/docs/rss2.html - https://github.com/jpmonette/feed - en - Copyright - - <![CDATA[test links]]> - https://docusaurus.io/myBaseUrl/blog/blog-with-links - https://docusaurus.io/myBaseUrl/blog/blog-with-links - Sun, 23 Jul 2023 00:00:00 GMT - - absolute full url

+ " + + https://docusaurus.io/myBaseUrl/blog + Hello Blog + 2023-07-23T00:00:00.000Z + https://github.com/jpmonette/feed + + Hello Blog + https://docusaurus.io/myBaseUrl/image/favicon.ico + Copyright + + <![CDATA[test links]]> + https://docusaurus.io/myBaseUrl/blog/blog-with-links + + 2023-07-23T00:00:00.000Z + + absolute full url

absolute pathname

relative pathname

md link

@@ -406,50 +385,983 @@ exports[`rss filters to the first two entries 1`] = `

-]]>
-
- - <![CDATA[MDX Blog Sample with require calls]]> - https://docusaurus.io/myBaseUrl/blog/mdx-require-blog-post - https://docusaurus.io/myBaseUrl/blog/mdx-require-blog-post - Sat, 06 Mar 2021 00:00:00 GMT - - Test MDX with require calls

+]]> + + + <![CDATA[MDX Blog Sample with require calls]]> + https://docusaurus.io/myBaseUrl/blog/mdx-require-blog-post + + 2021-03-06T00:00:00.000Z + + Test MDX with require calls

-]]>
-
-
-
", -] -`; - -exports[`rss filters to the first two entries using limit 1`] = ` -[ - " - - - Hello Blog - https://docusaurus.io/myBaseUrl/blog - Hello Blog - Sun, 23 Jul 2023 00:00:00 GMT - https://validator.w3.org/feed/docs/rss2.html - https://github.com/jpmonette/feed - en - Copyright - - <![CDATA[test links]]> - https://docusaurus.io/myBaseUrl/blog/blog-with-links - https://docusaurus.io/myBaseUrl/blog/blog-with-links - Sun, 23 Jul 2023 00:00:00 GMT - - absolute full url

-

absolute pathname

-

relative pathname

-

md link

-

anchor

+]]> + + + <![CDATA[Full Blog Sample]]> + https://docusaurus.io/myBaseUrl/blog/mdx-blog-post + + 2021-03-05T00:00:00.000Z + + HTML Heading 1 +

HTML Heading 2

+

HTML Paragraph

+ + +

Import DOM

+

Heading 1

+

Heading 2

+

Heading 3

+

Heading 4

+
Heading 5
+
    +
  • list1
  • +
  • list2
  • +
  • list3
  • +
+
    +
  • list1
  • +
  • list2
  • +
  • list3
  • +
+

Normal Text Italics Text Bold Text

+

link image

]]>
+
+ + <![CDATA[Complex Slug]]> + https://docusaurus.io/myBaseUrl/blog/hey/my super path/héllô + + 2020-08-16T00:00:00.000Z + + complex url slug

]]>
+ + +
+ + <![CDATA[Simple Slug]]> + https://docusaurus.io/myBaseUrl/blog/simple/slug + + 2020-08-15T00:00:00.000Z + + simple url slug

]]>
+ + Sébastien Lorber + https://sebastienlorber.com + +
+ + <![CDATA[some heading]]> + https://docusaurus.io/myBaseUrl/blog/heading-as-title + + 2019-01-02T00:00:00.000Z + + + <![CDATA[date-matter]]> + https://docusaurus.io/myBaseUrl/blog/date-matter + + 2019-01-01T00:00:00.000Z + + date inside front matter

]]>
+ +
+ + <![CDATA[Happy 1st Birthday Slash! (translated)]]> + https://docusaurus.io/myBaseUrl/blog/2018/12/14/Happy-First-Birthday-Slash + + 2018-12-14T00:00:00.000Z + + Happy birthday! (translated)

]]>
+ + Yangshun Tay (translated) + + + Sébastien Lorber (translated) + lorber.sebastien@gmail.com + +
+
", +] +`; + +exports[`atom has xslt files for feed 1`] = ` +[ + " + + https://docusaurus.io/myBaseUrl/blog + Hello Blog + 2023-07-23T00:00:00.000Z + https://github.com/jpmonette/feed + + Hello Blog + https://docusaurus.io/myBaseUrl/image/favicon.ico + Copyright + + <![CDATA[test links]]> + https://docusaurus.io/myBaseUrl/blog/blog-with-links + + 2023-07-23T00:00:00.000Z + + absolute full url

+

absolute pathname

+

relative pathname

+

md link

+

anchor

+

relative pathname + anchor

+

+

+ +]]>
+
+ + <![CDATA[MDX Blog Sample with require calls]]> + https://docusaurus.io/myBaseUrl/blog/mdx-require-blog-post + + 2021-03-06T00:00:00.000Z + + Test MDX with require calls

+ + + + +]]>
+
+ + <![CDATA[Full Blog Sample]]> + https://docusaurus.io/myBaseUrl/blog/mdx-blog-post + + 2021-03-05T00:00:00.000Z + + HTML Heading 1 +

HTML Heading 2

+

HTML Paragraph

+ + +

Import DOM

+

Heading 1

+

Heading 2

+

Heading 3

+

Heading 4

+
Heading 5
+
    +
  • list1
  • +
  • list2
  • +
  • list3
  • +
+
    +
  • list1
  • +
  • list2
  • +
  • list3
  • +
+

Normal Text Italics Text Bold Text

+

link image

]]>
+
+ + <![CDATA[Complex Slug]]> + https://docusaurus.io/myBaseUrl/blog/hey/my super path/héllô + + 2020-08-16T00:00:00.000Z + + complex url slug

]]>
+ + +
+ + <![CDATA[Simple Slug]]> + https://docusaurus.io/myBaseUrl/blog/simple/slug + + 2020-08-15T00:00:00.000Z + + simple url slug

]]>
+ + Sébastien Lorber + https://sebastienlorber.com + +
+ + <![CDATA[some heading]]> + https://docusaurus.io/myBaseUrl/blog/heading-as-title + + 2019-01-02T00:00:00.000Z + + + <![CDATA[date-matter]]> + https://docusaurus.io/myBaseUrl/blog/date-matter + + 2019-01-01T00:00:00.000Z + + date inside front matter

]]>
+ +
+ + <![CDATA[Happy 1st Birthday Slash! (translated)]]> + https://docusaurus.io/myBaseUrl/blog/2018/12/14/Happy-First-Birthday-Slash + + 2018-12-14T00:00:00.000Z + + Happy birthday! (translated)

]]>
+ + Yangshun Tay (translated) + + + Sébastien Lorber (translated) + lorber.sebastien@gmail.com + +
+
", +] +`; + +exports[`json filters to the first two entries 1`] = ` +[ + "{ + "version": "https://jsonfeed.org/version/1", + "title": "Hello Blog", + "home_page_url": "https://docusaurus.io/myBaseUrl/blog", + "description": "Hello Blog", + "items": [ + { + "id": "https://docusaurus.io/myBaseUrl/blog/blog-with-links", + "content_html": "

absolute full url

/n

absolute pathname

/n

relative pathname

/n

md link

/n

anchor

/n

relative pathname + anchor

/n

/n

\\"\\"

/n/n", + "url": "https://docusaurus.io/myBaseUrl/blog/blog-with-links", + "title": "test links", + "summary": "absolute full url", + "date_modified": "2023-07-23T00:00:00.000Z", + "tags": [] + }, + { + "id": "https://docusaurus.io/myBaseUrl/blog/mdx-require-blog-post", + "content_html": "

Test MDX with require calls

/n/n/n/n/n", + "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", + "tags": [] + } + ] +}", +] +`; + +exports[`json filters to the first two entries using limit 1`] = ` +[ + "{ + "version": "https://jsonfeed.org/version/1", + "title": "Hello Blog", + "home_page_url": "https://docusaurus.io/myBaseUrl/blog", + "description": "Hello Blog", + "items": [ + { + "id": "https://docusaurus.io/myBaseUrl/blog/blog-with-links", + "content_html": "

absolute full url

/n

absolute pathname

/n

relative pathname

/n

md link

/n

anchor

/n

relative pathname + anchor

/n

/n

\\"\\"

/n/n", + "url": "https://docusaurus.io/myBaseUrl/blog/blog-with-links", + "title": "test links", + "summary": "absolute full url", + "date_modified": "2023-07-23T00:00:00.000Z", + "tags": [] + }, + { + "id": "https://docusaurus.io/myBaseUrl/blog/mdx-require-blog-post", + "content_html": "

Test MDX with require calls

/n/n/n/n/n", + "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", + "tags": [] + } + ] +}", +] +`; + +exports[`json has custom xslt files for feed 1`] = ` +[ + "{ + "version": "https://jsonfeed.org/version/1", + "title": "Hello Blog", + "home_page_url": "https://docusaurus.io/myBaseUrl/blog", + "description": "Hello Blog", + "items": [ + { + "id": "https://docusaurus.io/myBaseUrl/blog/blog-with-links", + "content_html": "

absolute full url

/n

absolute pathname

/n

relative pathname

/n

md link

/n

anchor

/n

relative pathname + anchor

/n

/n

\\"\\"

/n/n", + "url": "https://docusaurus.io/myBaseUrl/blog/blog-with-links", + "title": "test links", + "summary": "absolute full url", + "date_modified": "2023-07-23T00:00:00.000Z", + "tags": [] + }, + { + "id": "https://docusaurus.io/myBaseUrl/blog/mdx-require-blog-post", + "content_html": "

Test MDX with require calls

/n/n/n/n/n", + "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", + "tags": [] + }, + { + "id": "https://docusaurus.io/myBaseUrl/blog/mdx-blog-post", + "content_html": "

HTML Heading 1

/n

HTML Heading 2

/n

HTML Paragraph

/n/n/n

Import DOM

/n

Heading 1

/n

Heading 2

/n

Heading 3

/n

Heading 4

/n
Heading 5
/n
    /n
  • list1
  • /n
  • list2
  • /n
  • list3
  • /n
/n
    /n
  • list1
  • /n
  • list2
  • /n
  • list3
  • /n
/n

Normal Text Italics Text Bold Text

/n

link \\"image\\"

", + "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", + "tags": [] + }, + { + "id": "https://docusaurus.io/myBaseUrl/blog/hey/my super path/héllô", + "content_html": "

complex url slug

", + "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", + "tags": [ + "date", + "complex" + ] + }, + { + "id": "https://docusaurus.io/myBaseUrl/blog/simple/slug", + "content_html": "

simple url slug

", + "url": "https://docusaurus.io/myBaseUrl/blog/simple/slug", + "title": "Simple Slug", + "summary": "simple url slug", + "date_modified": "2020-08-15T00:00:00.000Z", + "author": { + "name": "Sébastien Lorber", + "url": "https://sebastienlorber.com" + }, + "tags": [] + }, + { + "id": "https://docusaurus.io/myBaseUrl/blog/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", + "tags": [] + }, + { + "id": "https://docusaurus.io/myBaseUrl/blog/date-matter", + "content_html": "

date inside front matter

", + "url": "https://docusaurus.io/myBaseUrl/blog/date-matter", + "title": "date-matter", + "summary": "date inside front matter", + "date_modified": "2019-01-01T00:00:00.000Z", + "tags": [ + "date" + ] + }, + { + "id": "https://docusaurus.io/myBaseUrl/blog/2018/12/14/Happy-First-Birthday-Slash", + "content_html": "

Happy birthday! (translated)

", + "url": "https://docusaurus.io/myBaseUrl/blog/2018/12/14/Happy-First-Birthday-Slash", + "title": "Happy 1st Birthday Slash! (translated)", + "summary": "Happy birthday! (translated)", + "date_modified": "2018-12-14T00:00:00.000Z", + "author": { + "name": "Yangshun Tay (translated)" + }, + "tags": [] + } + ] +}", +] +`; + +exports[`json has feed item for each post 1`] = ` +[ + " + + + + + + + + RSS Feed | <xsl:value-of select="rss/channel/title" /> + + + +
+
+
+ This is an RSS feed. Subscribe by copying the URL from the address + bar into your newsreader. Visit About Feeds to learn more + and get started. It’s free.
+

+
+ + + + + + + + + + +
+ RSS Feed Preview

+

+ +

+

Description:

+
+

Recent Posts

+
+ +
+ + + +
Published on +
+
+ +
+
+
+
+
+ + +
+ +
", + "/** + * 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. + */ + +main { + flex: 1 0 auto; + width: 100%; + margin: 4rem auto; + padding: 1.5 rem; + max-width: 800px; + /* stylelint-disable-next-line font-family-name-quotes */ + font-family: system-ui, -apple-system, Segoe UI, Roboto, Ubuntu, Cantarell; +} + +.info { + display: block; + margin: 3rem 0; + padding: 2rem 3rem; + border: 1px solid dodgerblue; + border-left-width: 0.5rem; + border-radius: 0.4rem; + background-color: #edf5ff; +} + +.rss-icon { + height: 3.8rem; + width: 3.8rem; + margin-right: 1rem; +} + +.flex { + display: flex; +} + +.items-start { + align-items: flex-start; +} + +.pb-7 { + padding-bottom: 3rem; +} + +a { + color: #005aff; + text-decoration: none; +} + +h1 { + text-wrap: balance; + font-size: 3.8rem; + line-height: 1; + font-weight: 800; + margin-bottom: 4rem; +} + +h2 { + font-size: 3rem; + line-height: 1.2; + font-weight: 700; + margin-bottom: 3rem; +} + +h2:not(:first-child) { + margin-top: 5.8rem; +} + +.italic { + font-style: italic; +} +", + "{ + "version": "https://jsonfeed.org/version/1", + "title": "Hello Blog", + "home_page_url": "https://docusaurus.io/myBaseUrl/blog", + "description": "Hello Blog", + "items": [ + { + "id": "https://docusaurus.io/myBaseUrl/blog/blog-with-links", + "content_html": "

absolute full url

/n

absolute pathname

/n

relative pathname

/n

md link

/n

anchor

/n

relative pathname + anchor

/n

/n

\\"\\"

/n/n", + "url": "https://docusaurus.io/myBaseUrl/blog/blog-with-links", + "title": "test links", + "summary": "absolute full url", + "date_modified": "2023-07-23T00:00:00.000Z", + "tags": [] + }, + { + "id": "https://docusaurus.io/myBaseUrl/blog/mdx-require-blog-post", + "content_html": "

Test MDX with require calls

/n/n/n/n/n", + "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", + "tags": [] + }, + { + "id": "https://docusaurus.io/myBaseUrl/blog/mdx-blog-post", + "content_html": "

HTML Heading 1

/n

HTML Heading 2

/n

HTML Paragraph

/n/n/n

Import DOM

/n

Heading 1

/n

Heading 2

/n

Heading 3

/n

Heading 4

/n
Heading 5
/n
    /n
  • list1
  • /n
  • list2
  • /n
  • list3
  • /n
/n
    /n
  • list1
  • /n
  • list2
  • /n
  • list3
  • /n
/n

Normal Text Italics Text Bold Text

/n

link \\"image\\"

", + "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", + "tags": [] + }, + { + "id": "https://docusaurus.io/myBaseUrl/blog/hey/my super path/héllô", + "content_html": "

complex url slug

", + "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", + "tags": [ + "date", + "complex" + ] + }, + { + "id": "https://docusaurus.io/myBaseUrl/blog/simple/slug", + "content_html": "

simple url slug

", + "url": "https://docusaurus.io/myBaseUrl/blog/simple/slug", + "title": "Simple Slug", + "summary": "simple url slug", + "date_modified": "2020-08-15T00:00:00.000Z", + "author": { + "name": "Sébastien Lorber", + "url": "https://sebastienlorber.com" + }, + "tags": [] + }, + { + "id": "https://docusaurus.io/myBaseUrl/blog/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", + "tags": [] + }, + { + "id": "https://docusaurus.io/myBaseUrl/blog/date-matter", + "content_html": "

date inside front matter

", + "url": "https://docusaurus.io/myBaseUrl/blog/date-matter", + "title": "date-matter", + "summary": "date inside front matter", + "date_modified": "2019-01-01T00:00:00.000Z", + "tags": [ + "date" + ] + }, + { + "id": "https://docusaurus.io/myBaseUrl/blog/2018/12/14/Happy-First-Birthday-Slash", + "content_html": "

Happy birthday! (translated)

", + "url": "https://docusaurus.io/myBaseUrl/blog/2018/12/14/Happy-First-Birthday-Slash", + "title": "Happy 1st Birthday Slash! (translated)", + "summary": "Happy birthday! (translated)", + "date_modified": "2018-12-14T00:00:00.000Z", + "author": { + "name": "Yangshun Tay (translated)" + }, + "tags": [] + } + ] +}", +] +`; + +exports[`json has xslt files for feed 1`] = ` +[ + "{ + "version": "https://jsonfeed.org/version/1", + "title": "Hello Blog", + "home_page_url": "https://docusaurus.io/myBaseUrl/blog", + "description": "Hello Blog", + "items": [ + { + "id": "https://docusaurus.io/myBaseUrl/blog/blog-with-links", + "content_html": "

absolute full url

/n

absolute pathname

/n

relative pathname

/n

md link

/n

anchor

/n

relative pathname + anchor

/n

/n

\\"\\"

/n/n", + "url": "https://docusaurus.io/myBaseUrl/blog/blog-with-links", + "title": "test links", + "summary": "absolute full url", + "date_modified": "2023-07-23T00:00:00.000Z", + "tags": [] + }, + { + "id": "https://docusaurus.io/myBaseUrl/blog/mdx-require-blog-post", + "content_html": "

Test MDX with require calls

/n/n/n/n/n", + "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", + "tags": [] + }, + { + "id": "https://docusaurus.io/myBaseUrl/blog/mdx-blog-post", + "content_html": "

HTML Heading 1

/n

HTML Heading 2

/n

HTML Paragraph

/n/n/n

Import DOM

/n

Heading 1

/n

Heading 2

/n

Heading 3

/n

Heading 4

/n
Heading 5
/n
    /n
  • list1
  • /n
  • list2
  • /n
  • list3
  • /n
/n
    /n
  • list1
  • /n
  • list2
  • /n
  • list3
  • /n
/n

Normal Text Italics Text Bold Text

/n

link \\"image\\"

", + "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", + "tags": [] + }, + { + "id": "https://docusaurus.io/myBaseUrl/blog/hey/my super path/héllô", + "content_html": "

complex url slug

", + "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", + "tags": [ + "date", + "complex" + ] + }, + { + "id": "https://docusaurus.io/myBaseUrl/blog/simple/slug", + "content_html": "

simple url slug

", + "url": "https://docusaurus.io/myBaseUrl/blog/simple/slug", + "title": "Simple Slug", + "summary": "simple url slug", + "date_modified": "2020-08-15T00:00:00.000Z", + "author": { + "name": "Sébastien Lorber", + "url": "https://sebastienlorber.com" + }, + "tags": [] + }, + { + "id": "https://docusaurus.io/myBaseUrl/blog/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", + "tags": [] + }, + { + "id": "https://docusaurus.io/myBaseUrl/blog/date-matter", + "content_html": "

date inside front matter

", + "url": "https://docusaurus.io/myBaseUrl/blog/date-matter", + "title": "date-matter", + "summary": "date inside front matter", + "date_modified": "2019-01-01T00:00:00.000Z", + "tags": [ + "date" + ] + }, + { + "id": "https://docusaurus.io/myBaseUrl/blog/2018/12/14/Happy-First-Birthday-Slash", + "content_html": "

Happy birthday! (translated)

", + "url": "https://docusaurus.io/myBaseUrl/blog/2018/12/14/Happy-First-Birthday-Slash", + "title": "Happy 1st Birthday Slash! (translated)", + "summary": "Happy birthday! (translated)", + "date_modified": "2018-12-14T00:00:00.000Z", + "author": { + "name": "Yangshun Tay (translated)" + }, + "tags": [] + } + ] +}", +] +`; + +exports[`rss filters to the first two entries 1`] = ` +[ + " + + + Hello Blog + https://docusaurus.io/myBaseUrl/blog + Hello Blog + Sun, 23 Jul 2023 00:00:00 GMT + https://validator.w3.org/feed/docs/rss2.html + https://github.com/jpmonette/feed + en + Copyright + + <![CDATA[test links]]> + https://docusaurus.io/myBaseUrl/blog/blog-with-links + https://docusaurus.io/myBaseUrl/blog/blog-with-links + Sun, 23 Jul 2023 00:00:00 GMT + + absolute full url

+

absolute pathname

+

relative pathname

+

md link

+

anchor

+

relative pathname + anchor

+

+

+ +]]>
+
+ + <![CDATA[MDX Blog Sample with require calls]]> + https://docusaurus.io/myBaseUrl/blog/mdx-require-blog-post + https://docusaurus.io/myBaseUrl/blog/mdx-require-blog-post + Sat, 06 Mar 2021 00:00:00 GMT + + Test MDX with require calls

+ + + + +]]>
+
+
+
", +] +`; + +exports[`rss filters to the first two entries using limit 1`] = ` +[ + " + + + Hello Blog + https://docusaurus.io/myBaseUrl/blog + Hello Blog + Sun, 23 Jul 2023 00:00:00 GMT + https://validator.w3.org/feed/docs/rss2.html + https://github.com/jpmonette/feed + en + Copyright + + <![CDATA[test links]]> + https://docusaurus.io/myBaseUrl/blog/blog-with-links + https://docusaurus.io/myBaseUrl/blog/blog-with-links + Sun, 23 Jul 2023 00:00:00 GMT + + absolute full url

+

absolute pathname

+

relative pathname

+

md link

+

anchor

+

relative pathname + anchor

+

+

+ +]]>
+
+ + <![CDATA[MDX Blog Sample with require calls]]> + https://docusaurus.io/myBaseUrl/blog/mdx-require-blog-post + https://docusaurus.io/myBaseUrl/blog/mdx-require-blog-post + Sat, 06 Mar 2021 00:00:00 GMT + + Test MDX with require calls

+ + + + +]]>
+
+
+
", +] +`; + +exports[`rss has custom xslt files for feed 1`] = ` +[ + " + + + + + + + + RSS Feed | <xsl:value-of select="rss/channel/title" /> + + + +
+
+
+ This is an RSS feed. Subscribe by copying the URL from the address + bar into your newsreader. Visit About Feeds to learn more + and get started. It’s free.
+

+
+ + + + + + + + + + +
+ RSS Feed Preview

+

+ +

+

Description:

+
+

Recent Posts

+
+ +
+ + + +
Published on +
+
+ +
+
+
+
+
+ + +
+ +
", + "/** + * 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. + */ + +main { + flex: 1 0 auto; + width: 100%; + margin: 4rem auto; + padding: 1.5 rem; + max-width: 800px; + /* stylelint-disable-next-line font-family-name-quotes */ + font-family: system-ui, -apple-system, Segoe UI, Roboto, Ubuntu, Cantarell; +} + +.info { + display: block; + margin: 3rem 0; + padding: 2rem 3rem; + border: 1px solid dodgerblue; + border-left-width: 0.5rem; + border-radius: 0.4rem; + background-color: #edf5ff; +} + +.rss-icon { + height: 3.8rem; + width: 3.8rem; + margin-right: 1rem; +} + +.flex { + display: flex; +} + +.items-start { + align-items: flex-start; +} + +.pb-7 { + padding-bottom: 3rem; +} + +a { + color: #005aff; + text-decoration: none; +} + +h1 { + text-wrap: balance; + font-size: 3.8rem; + line-height: 1; + font-weight: 800; + margin-bottom: 4rem; +} + +h2 { + font-size: 3rem; + line-height: 1.2; + font-weight: 700; + margin-bottom: 3rem; +} + +h2:not(:first-child) { + margin-top: 5.8rem; +} + +.italic { + font-style: italic; +} +", + " + + + Hello Blog + https://docusaurus.io/myBaseUrl/blog + Hello Blog + Sun, 23 Jul 2023 00:00:00 GMT + https://validator.w3.org/feed/docs/rss2.html + https://github.com/jpmonette/feed + en + Copyright + + <![CDATA[test links]]> + https://docusaurus.io/myBaseUrl/blog/blog-with-links + https://docusaurus.io/myBaseUrl/blog/blog-with-links + Sun, 23 Jul 2023 00:00:00 GMT + + absolute full url

+

absolute pathname

+

relative pathname

+

md link

+

anchor

relative pathname + anchor

@@ -469,6 +1381,78 @@ exports[`rss filters to the first two entries using limit 1`] = ` ]]>
+ + <![CDATA[Full Blog Sample]]> + https://docusaurus.io/myBaseUrl/blog/mdx-blog-post + https://docusaurus.io/myBaseUrl/blog/mdx-blog-post + Fri, 05 Mar 2021 00:00:00 GMT + + HTML Heading 1 +

HTML Heading 2

+

HTML Paragraph

+ + +

Import DOM

+

Heading 1

+

Heading 2

+

Heading 3

+

Heading 4

+
Heading 5
+
    +
  • list1
  • +
  • list2
  • +
  • list3
  • +
+
    +
  • list1
  • +
  • list2
  • +
  • list3
  • +
+

Normal Text Italics Text Bold Text

+

link image

]]>
+
+ + <![CDATA[Complex Slug]]> + https://docusaurus.io/myBaseUrl/blog/hey/my super path/héllô + https://docusaurus.io/myBaseUrl/blog/hey/my super path/héllô + Sun, 16 Aug 2020 00:00:00 GMT + + complex url slug

]]>
+ date + complex +
+ + <![CDATA[Simple Slug]]> + https://docusaurus.io/myBaseUrl/blog/simple/slug + https://docusaurus.io/myBaseUrl/blog/simple/slug + Sat, 15 Aug 2020 00:00:00 GMT + + simple url slug

]]>
+
+ + <![CDATA[some heading]]> + https://docusaurus.io/myBaseUrl/blog/heading-as-title + https://docusaurus.io/myBaseUrl/blog/heading-as-title + Wed, 02 Jan 2019 00:00:00 GMT + + + <![CDATA[date-matter]]> + https://docusaurus.io/myBaseUrl/blog/date-matter + https://docusaurus.io/myBaseUrl/blog/date-matter + Tue, 01 Jan 2019 00:00:00 GMT + + date inside front matter

]]>
+ date +
+ + <![CDATA[Happy 1st Birthday Slash! (translated)]]> + https://docusaurus.io/myBaseUrl/blog/2018/12/14/Happy-First-Birthday-Slash + https://docusaurus.io/myBaseUrl/blog/2018/12/14/Happy-First-Birthday-Slash + Fri, 14 Dec 2018 00:00:00 GMT + + Happy birthday! (translated)

]]>
+ lorber.sebastien@gmail.com (Sébastien Lorber (translated)) +
", ] @@ -476,7 +1460,265 @@ exports[`rss filters to the first two entries using limit 1`] = ` exports[`rss has feed item for each post 1`] = ` [ - " + " + + + + + + + + Atom Feed | <xsl:value-of select="atom:feed/atom:title" /> + + + +
+
+
+ This is an Atom feed. Subscribe by copying the URL from the address + bar into your newsreader. Visit About Feeds to learn more + and get started. It’s free.
+

+
+ + + + + + + + + + +
+ Atom Feed Preview

+

+ +

+

Description:

+
+

Recent Posts

+
+ +
+ + + +
Published on +
+
+ +
+
+
+
+
+ + +
+ +
", + "/** + * 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. + */ + +main { + flex: 1 0 auto; + width: 100%; + margin: 4rem auto; + padding: 1.5 rem; + max-width: 800px; + /* stylelint-disable-next-line font-family-name-quotes */ + font-family: system-ui, -apple-system, Segoe UI, Roboto, Ubuntu, Cantarell; +} + +.info { + display: block; + margin: 3rem 0; + padding: 2rem 3rem; + border: 1px solid dodgerblue; + border-left-width: 0.5rem; + border-radius: 0.4rem; + background-color: #edf5ff; +} + +.rss-icon { + height: 3.8rem; + width: 3.8rem; + margin-right: 1rem; +} + +.flex { + display: flex; +} + +.items-start { + align-items: flex-start; +} + +.pb-7 { + padding-bottom: 3rem; +} + +a { + color: #005aff; + text-decoration: none; +} + +h1 { + text-wrap: balance; + font-size: 3.8rem; + line-height: 1; + font-weight: 800; + margin-bottom: 4rem; +} + +h2 { + font-size: 3rem; + line-height: 1.2; + font-weight: 700; + margin-bottom: 3rem; +} + +h2:not(:first-child) { + margin-top: 5.8rem; +} + +.italic { + font-style: italic; +} +", + " + + + Hello Blog + https://docusaurus.io/myBaseUrl/blog + Hello Blog + Sun, 23 Jul 2023 00:00:00 GMT + https://validator.w3.org/feed/docs/rss2.html + https://github.com/jpmonette/feed + en + Copyright + + <![CDATA[test links]]> + https://docusaurus.io/myBaseUrl/blog/blog-with-links + https://docusaurus.io/myBaseUrl/blog/blog-with-links + Sun, 23 Jul 2023 00:00:00 GMT + + absolute full url

+

absolute pathname

+

relative pathname

+

md link

+

anchor

+

relative pathname + anchor

+

+

+ +]]>
+
+ + <![CDATA[MDX Blog Sample with require calls]]> + https://docusaurus.io/myBaseUrl/blog/mdx-require-blog-post + https://docusaurus.io/myBaseUrl/blog/mdx-require-blog-post + Sat, 06 Mar 2021 00:00:00 GMT + + Test MDX with require calls

+ + + + +]]>
+
+ + <![CDATA[Full Blog Sample]]> + https://docusaurus.io/myBaseUrl/blog/mdx-blog-post + https://docusaurus.io/myBaseUrl/blog/mdx-blog-post + Fri, 05 Mar 2021 00:00:00 GMT + + HTML Heading 1 +

HTML Heading 2

+

HTML Paragraph

+ + +

Import DOM

+

Heading 1

+

Heading 2

+

Heading 3

+

Heading 4

+
Heading 5
+
    +
  • list1
  • +
  • list2
  • +
  • list3
  • +
+
    +
  • list1
  • +
  • list2
  • +
  • list3
  • +
+

Normal Text Italics Text Bold Text

+

link image

]]>
+
+ + <![CDATA[Complex Slug]]> + https://docusaurus.io/myBaseUrl/blog/hey/my super path/héllô + https://docusaurus.io/myBaseUrl/blog/hey/my super path/héllô + Sun, 16 Aug 2020 00:00:00 GMT + + complex url slug

]]>
+ date + complex +
+ + <![CDATA[Simple Slug]]> + https://docusaurus.io/myBaseUrl/blog/simple/slug + https://docusaurus.io/myBaseUrl/blog/simple/slug + Sat, 15 Aug 2020 00:00:00 GMT + + simple url slug

]]>
+
+ + <![CDATA[some heading]]> + https://docusaurus.io/myBaseUrl/blog/heading-as-title + https://docusaurus.io/myBaseUrl/blog/heading-as-title + Wed, 02 Jan 2019 00:00:00 GMT + + + <![CDATA[date-matter]]> + https://docusaurus.io/myBaseUrl/blog/date-matter + https://docusaurus.io/myBaseUrl/blog/date-matter + Tue, 01 Jan 2019 00:00:00 GMT + + date inside front matter

]]>
+ date +
+ + <![CDATA[Happy 1st Birthday Slash! (translated)]]> + https://docusaurus.io/myBaseUrl/blog/2018/12/14/Happy-First-Birthday-Slash + https://docusaurus.io/myBaseUrl/blog/2018/12/14/Happy-First-Birthday-Slash + Fri, 14 Dec 2018 00:00:00 GMT + + Happy birthday! (translated)

]]>
+ lorber.sebastien@gmail.com (Sébastien Lorber (translated)) +
+
+
", +] +`; + +exports[`rss has xslt files for feed 1`] = ` +[ + " Hello Blog diff --git a/packages/docusaurus-plugin-content-blog/src/__tests__/feed.test.ts b/packages/docusaurus-plugin-content-blog/src/__tests__/feed.test.ts index f928296bf9df..b11cb7c5460c 100644 --- a/packages/docusaurus-plugin-content-blog/src/__tests__/feed.test.ts +++ b/packages/docusaurus-plugin-content-blog/src/__tests__/feed.test.ts @@ -238,4 +238,96 @@ describe.each(['atom', 'rss', 'json'])('%s', (feedType) => { ).toMatchSnapshot(); fsMock.mockClear(); }); + + it('has xslt files for feed', async () => { + const siteDir = path.join(__dirname, '__fixtures__', 'website'); + const outDir = path.join(siteDir, 'build-snap'); + const siteConfig = { + title: 'Hello', + baseUrl: '/myBaseUrl/', + url: 'https://docusaurus.io', + favicon: 'image/favicon.ico', + }; + + // Build is quite difficult to mock, so we built the blog beforehand and + // copied the output to the fixture... + await testGenerateFeeds( + { + siteDir, + siteConfig, + i18n: DefaultI18N, + outDir, + } as LoadContext, + { + path: 'blog', + routeBasePath: 'blog', + tagsBasePath: 'tags', + authorsMapPath: 'authors.yml', + include: DEFAULT_OPTIONS.include, + exclude: DEFAULT_OPTIONS.exclude, + feedOptions: { + type: [feedType], + copyright: 'Copyright', + xsl: { + enable: true, + }, + }, + readingTime: ({content, defaultReadingTime}) => + defaultReadingTime({content}), + truncateMarker: //, + } as PluginOptions, + ); + + expect( + fsMock.mock.calls.map((call) => call[1] as string), + ).toMatchSnapshot(); + fsMock.mockClear(); + }); + + it('has custom xslt files for feed', async () => { + const siteDir = path.join(__dirname, '__fixtures__', 'website'); + const outDir = path.join(siteDir, 'build-snap'); + const siteConfig = { + title: 'Hello', + baseUrl: '/myBaseUrl/', + url: 'https://docusaurus.io', + favicon: 'image/favicon.ico', + }; + + // Build is quite difficult to mock, so we built the blog beforehand and + // copied the output to the fixture... + await testGenerateFeeds( + { + siteDir, + siteConfig, + i18n: DefaultI18N, + outDir, + } as LoadContext, + { + path: 'blog', + routeBasePath: 'blog', + tagsBasePath: 'tags', + authorsMapPath: 'authors.yml', + include: DEFAULT_OPTIONS.include, + exclude: DEFAULT_OPTIONS.exclude, + feedOptions: { + type: [feedType], + copyright: 'Copyright', + xsl: { + enable: true, + rssStylesheet: 'custom-rss.stylesheet.xsl', + atomStylesheet: 'custom-atom.stylesheet.xsl', + }, + }, + readingTime: ({content, defaultReadingTime}) => + defaultReadingTime({content}), + truncateMarker: //, + } as PluginOptions, + ); + + expect( + fsMock.mock.calls.map((call) => call[1] as string), + ).toMatchSnapshot(); + fsMock.mockClear(); + }); }); diff --git a/packages/docusaurus-plugin-content-blog/src/feed.ts b/packages/docusaurus-plugin-content-blog/src/feed.ts index 4f4c2a6f5a3a..12c67957e183 100644 --- a/packages/docusaurus-plugin-content-blog/src/feed.ts +++ b/packages/docusaurus-plugin-content-blog/src/feed.ts @@ -20,6 +20,7 @@ import type { Author, BlogPost, BlogFeedItem, + IXslParams, } from '@docusaurus/plugin-content-blog'; async function generateBlogFeed({ @@ -165,16 +166,127 @@ async function defaultCreateFeedItems({ ); } +/** + * @description addXmlStyleSheet appends a xsl stylesheet to the generated xml feed + * @param feedDetails array containing blog feed content and name of file + * @param generatePath path where the file would be copied in website + */ +async function addXmlStyleSheet( + feedDetails: string[], + generatePath: string, + stylesheet: string, +) { + const DEFAULT_RSS_FEED = 'rss-feed.xslt'; + const DEFAULT_ATOM_FEED = 'atom-feed.xslt'; + + if (!feedDetails[0]) { + return feedDetails; + } + + if (feedDetails[1] === 'rss.xml') { + let xsltLink = ``; + + if (stylesheet) { + xsltLink = ``; + } + + feedDetails[0] = feedDetails[0]?.replace( + '', + xsltLink, + ); + + const rssXsltSourceFilePath = path.join( + __dirname, + '../assets/rss-feed.xslt', + ); + const rssStylesheetSourceFilePath = path.join( + __dirname, + '../assets/rss-feed.stylesheet.css', + ); + + const rssXsltDestinationFilePath = path.join(generatePath, 'rss-feed.xslt'); + const rssStylesheetDestinationFilePath = path.join( + generatePath, + 'rss-feed.stylesheet.css', + ); + + // output rss xslt file to website + fs.readFile(rssXsltSourceFilePath, 'utf8').then((xsltContent) => + fs.outputFile(rssXsltDestinationFilePath, xsltContent, 'utf-8'), + ); + + // output rss stylesheet to website + fs.readFile(rssStylesheetSourceFilePath, 'utf8').then( + (stylesheetContent) => { + fs.outputFile( + rssStylesheetDestinationFilePath, + stylesheetContent, + 'utf-8', + ); + }, + ); + } else if (feedDetails[1] === 'atom.xml') { + let xsltLink = ``; + + if (stylesheet) { + xsltLink = ``; + } + + feedDetails[0] = feedDetails[0]?.replace( + '', + xsltLink, + ); + + const atomXsltSourceFilePath = path.join( + __dirname, + '../assets/atom-feed.xslt', + ); + const atomStylesheetSourceFilePath = path.join( + __dirname, + '../assets/atom-feed.stylesheet.css', + ); + + const atomXsltDestinationFilePath = path.join( + generatePath, + 'atom-feed.xslt', + ); + const atomStylesheetDestinationFilePath = path.join( + generatePath, + 'atom-feed.stylesheet.css', + ); + + // output rss xslt file to website + fs.readFile(atomXsltSourceFilePath, 'utf8').then((xsltContent) => + fs.outputFile(atomXsltDestinationFilePath, xsltContent, 'utf-8'), + ); + + // output rss stylesheet to website + fs.readFile(atomStylesheetSourceFilePath, 'utf8').then( + (stylesheetContent) => { + fs.outputFile( + atomStylesheetDestinationFilePath, + stylesheetContent, + 'utf-8', + ); + }, + ); + } + + return feedDetails; +} + async function createBlogFeedFile({ feed, feedType, generatePath, + addXSL, }: { feed: Feed; feedType: FeedType; generatePath: string; + addXSL?: IXslParams; }) { - const feedDetails = (() => { + let feedDetails = (() => { switch (feedType) { case 'rss': return [feed.rss2(), 'rss.xml']; @@ -187,13 +299,13 @@ async function createBlogFeedFile({ } })(); try { - const xsltLink = - ''; - - if (feedDetails[1] !== 'feed.json' && feedDetails[0]) { - feedDetails[0] = feedDetails[0]?.replace( - '', - xsltLink, + if (addXSL?.enable) { + feedDetails = await addXmlStyleSheet( + feedDetails, + generatePath, + feedDetails[1] === 'atom.xml' + ? addXSL.atomStylesheet + : addXSL.rssStylesheet, ); } @@ -248,6 +360,7 @@ export async function createBlogFeedFiles({ feed, feedType, generatePath: path.join(outDir, options.routeBasePath), + addXSL: options.feedOptions.xsl, }), ), ); diff --git a/packages/docusaurus-plugin-content-blog/src/options.ts b/packages/docusaurus-plugin-content-blog/src/options.ts index 5b9889399a10..7fdcd9c06741 100644 --- a/packages/docusaurus-plugin-content-blog/src/options.ts +++ b/packages/docusaurus-plugin-content-blog/src/options.ts @@ -111,6 +111,11 @@ const PluginOptionSchema = Joi.object({ ) .allow(null) .default(DEFAULT_OPTIONS.feedOptions.type), + xsl: Joi.object({ + enable: Joi.boolean(), + atomStylesheet: Joi.string(), + rssStylesheet: Joi.string(), + }), title: Joi.string().allow(''), description: Joi.string().allow(''), // Only add default value when user actually wants a feed (type is not null) diff --git a/packages/docusaurus-plugin-content-blog/src/plugin-content-blog.d.ts b/packages/docusaurus-plugin-content-blog/src/plugin-content-blog.d.ts index b1915f75196f..f57c07eed02c 100644 --- a/packages/docusaurus-plugin-content-blog/src/plugin-content-blog.d.ts +++ b/packages/docusaurus-plugin-content-blog/src/plugin-content-blog.d.ts @@ -256,6 +256,13 @@ yarn workspace v1.22.19image` is a collocated image path, this entry will be the }) => string | undefined; export type FeedType = 'rss' | 'atom' | 'json'; + + export interface IXslParams { + enable: boolean; + rssStylesheet: string; + atomStylesheet: string; + } + /** * Normalized feed options used within code. */ @@ -274,6 +281,8 @@ yarn workspace v1.22.19image` is a collocated image path, this entry will be the createFeedItems?: CreateFeedItemsFn; /** Limits the feed to the specified number of posts, false|null for all */ limit?: number | false | null; + /** Enable xsl stylesheet */ + xsl?: IXslParams; }; type DefaultCreateFeedItemsParams = { diff --git a/website/_dogfooding/dogfooding.config.js b/website/_dogfooding/dogfooding.config.js index a6e2bcde9592..7b5cf84164f8 100644 --- a/website/_dogfooding/dogfooding.config.js +++ b/website/_dogfooding/dogfooding.config.js @@ -67,6 +67,11 @@ const dogfoodingPluginInstances = [ type: 'all', title: 'Docusaurus Tests Blog', copyright: `Copyright © ${new Date().getFullYear()} Facebook, Inc.`, + xsl: { + enable: true, + rssStylesheet: 'custom-rss.stylesheet.xslt', + atomStylesheet: 'custom-atom.stylesheet.xslt', + }, }, readingTime: ({content, frontMatter, defaultReadingTime}) => frontMatter.hide_reading_time diff --git a/website/docusaurus.config.js b/website/docusaurus.config.js index 087e9716cd3c..6ef97f69580b 100644 --- a/website/docusaurus.config.js +++ b/website/docusaurus.config.js @@ -420,6 +420,9 @@ module.exports = async function createConfigAsync() { feedOptions: { type: 'all', copyright: `Copyright © ${new Date().getFullYear()} Facebook, Inc.`, + xsl: { + enable: true + } }, blogSidebarCount: 'ALL', blogSidebarTitle: 'All our posts', diff --git a/website/static/custom-atom.stylesheet.xslt b/website/static/custom-atom.stylesheet.xslt new file mode 100644 index 000000000000..3f37d7419c43 --- /dev/null +++ b/website/static/custom-atom.stylesheet.xslt @@ -0,0 +1,65 @@ + + + + + + + + + Atom Feed | <xsl:value-of select="atom:feed/atom:title" /> + + + +
+
+
+ This is an Atom feed. Subscribe by copying the URL from the address + bar into your newsreader. Visit About Feeds to learn more + and get started. It’s free.
+

+
+ + + + + + + + + + +
+ Custom Atom Feed Preview

+

+ +

+

Description:

+
+

Recent Posts

+
+ +
+ + + +
Published on +
+
+ +
+
+
+
+
+ + +
+ +
\ No newline at end of file diff --git a/website/static/custom-rss.stylesheet.xslt b/website/static/custom-rss.stylesheet.xslt new file mode 100644 index 000000000000..4159dab155d0 --- /dev/null +++ b/website/static/custom-rss.stylesheet.xslt @@ -0,0 +1,66 @@ + + + + + + + + + RSS Feed | <xsl:value-of select="rss/channel/title" /> + + + +
+
+
+ This is an RSS feed. Subscribe by copying the URL from the address + bar into your newsreader. Visit About Feeds to learn more + and get started. It’s free.
+

+
+ + + + + + + + + + +
+ Custom RSS Feed Preview

+

+ +

+

Description:

+
+

Recent Posts

+
+ +
+ + + +
Published on +
+
+ +
+
+
+
+
+ + +
+ +
\ No newline at end of file diff --git a/website/static/rss.xslt b/website/static/rss.xslt deleted file mode 100644 index 40cb219efc74..000000000000 --- a/website/static/rss.xslt +++ /dev/null @@ -1,33 +0,0 @@ - - - - - - - Blog Information - - - -
-
-

-

Description:

-

Last Build Date:

-

Language:

-
-

Recent Posts

- -
- - -
- -
diff --git a/website/static/styles.css b/website/static/styles.css deleted file mode 100644 index 55d607bb351a..000000000000 --- a/website/static/styles.css +++ /dev/null @@ -1,35 +0,0 @@ -/** - * 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; -} diff --git a/website/static/xslt-stylesheet.css b/website/static/xslt-stylesheet.css new file mode 100644 index 000000000000..c016178d9007 --- /dev/null +++ b/website/static/xslt-stylesheet.css @@ -0,0 +1,76 @@ +/** + * 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. + */ + +* { + color: #0d1137; +} + +main { + flex: 1 0 auto; + width: 100%; + margin: 4rem auto; + padding: 1.5 rem; + max-width: 800px; + /* stylelint-disable-next-line font-family-name-quotes */ + font-family: system-ui, -apple-system, Segoe UI, Roboto, Ubuntu, Cantarell; +} + +.info { + display: block; + margin: 3rem 0; + padding: 2rem 3rem; + border: 1px solid dodgerblue; + border-left-width: 0.5rem; + border-radius: 0.4rem; + background-color: #e52165; +} + +.rss-icon { + height: 3.8rem; + width: 3.8rem; + margin-right: 1rem; +} + +.flex { + display: flex; +} + +.items-start { + align-items: flex-start; +} + +.pb-7 { + padding-bottom: 3rem; +} + +a { + color: #005aff; + text-decoration: none; +} + +h1 { + text-wrap: balance; + font-size: 3.8rem; + line-height: 1; + font-weight: 800; + margin-bottom: 4rem; +} + +h2 { + font-size: 3rem; + line-height: 1.2; + font-weight: 700; + margin-bottom: 3rem; +} + +h2:not(:first-child) { + margin-top: 5.8rem; +} + +.italic { + font-style: italic; +} From e5e066a0a52c995827aeaa152e46603dbfeb6534 Mon Sep 17 00:00:00 2001 From: ozakione <29860391+OzakIOne@users.noreply.github.com> Date: Wed, 24 Jul 2024 14:48:40 +0200 Subject: [PATCH 03/36] type --- packages/docusaurus-plugin-content-blog/src/feed.ts | 4 ++-- .../src/plugin-content-blog.d.ts | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/packages/docusaurus-plugin-content-blog/src/feed.ts b/packages/docusaurus-plugin-content-blog/src/feed.ts index 12c67957e183..b4876d718db8 100644 --- a/packages/docusaurus-plugin-content-blog/src/feed.ts +++ b/packages/docusaurus-plugin-content-blog/src/feed.ts @@ -20,7 +20,7 @@ import type { Author, BlogPost, BlogFeedItem, - IXslParams, + XslParams, } from '@docusaurus/plugin-content-blog'; async function generateBlogFeed({ @@ -284,7 +284,7 @@ async function createBlogFeedFile({ feed: Feed; feedType: FeedType; generatePath: string; - addXSL?: IXslParams; + addXSL?: XslParams; }) { let feedDetails = (() => { switch (feedType) { diff --git a/packages/docusaurus-plugin-content-blog/src/plugin-content-blog.d.ts b/packages/docusaurus-plugin-content-blog/src/plugin-content-blog.d.ts index f57c07eed02c..63723f1870ad 100644 --- a/packages/docusaurus-plugin-content-blog/src/plugin-content-blog.d.ts +++ b/packages/docusaurus-plugin-content-blog/src/plugin-content-blog.d.ts @@ -257,11 +257,11 @@ yarn workspace v1.22.19image` is a collocated image path, this entry will be the export type FeedType = 'rss' | 'atom' | 'json'; - export interface IXslParams { + export type XslParams = { enable: boolean; rssStylesheet: string; atomStylesheet: string; - } + }; /** * Normalized feed options used within code. @@ -282,7 +282,7 @@ yarn workspace v1.22.19image` is a collocated image path, this entry will be the /** Limits the feed to the specified number of posts, false|null for all */ limit?: number | false | null; /** Enable xsl stylesheet */ - xsl?: IXslParams; + xsl?: XslParams; }; type DefaultCreateFeedItemsParams = { From d9a69b7964d54da9d09a8300360644175e045c37 Mon Sep 17 00:00:00 2001 From: ozakione <29860391+OzakIOne@users.noreply.github.com> Date: Wed, 24 Jul 2024 14:50:07 +0200 Subject: [PATCH 04/36] await --- .../src/feed.ts | 42 +++++++++---------- 1 file changed, 20 insertions(+), 22 deletions(-) diff --git a/packages/docusaurus-plugin-content-blog/src/feed.ts b/packages/docusaurus-plugin-content-blog/src/feed.ts index b4876d718db8..3ef8cf40fc2f 100644 --- a/packages/docusaurus-plugin-content-blog/src/feed.ts +++ b/packages/docusaurus-plugin-content-blog/src/feed.ts @@ -211,19 +211,18 @@ async function addXmlStyleSheet( ); // output rss xslt file to website - fs.readFile(rssXsltSourceFilePath, 'utf8').then((xsltContent) => - fs.outputFile(rssXsltDestinationFilePath, xsltContent, 'utf-8'), - ); + const xsltContent = await fs.readFile(rssXsltSourceFilePath, 'utf8'); + await fs.outputFile(rssXsltDestinationFilePath, xsltContent, 'utf-8'); // output rss stylesheet to website - fs.readFile(rssStylesheetSourceFilePath, 'utf8').then( - (stylesheetContent) => { - fs.outputFile( - rssStylesheetDestinationFilePath, - stylesheetContent, - 'utf-8', - ); - }, + const stylesheetContent = await fs.readFile( + rssStylesheetSourceFilePath, + 'utf8', + ); + await fs.outputFile( + rssStylesheetDestinationFilePath, + stylesheetContent, + 'utf-8', ); } else if (feedDetails[1] === 'atom.xml') { let xsltLink = ``; @@ -256,19 +255,18 @@ async function addXmlStyleSheet( ); // output rss xslt file to website - fs.readFile(atomXsltSourceFilePath, 'utf8').then((xsltContent) => - fs.outputFile(atomXsltDestinationFilePath, xsltContent, 'utf-8'), - ); + const xsltContent = await fs.readFile(atomXsltSourceFilePath, 'utf8'); + await fs.outputFile(atomXsltDestinationFilePath, xsltContent, 'utf-8'); // output rss stylesheet to website - fs.readFile(atomStylesheetSourceFilePath, 'utf8').then( - (stylesheetContent) => { - fs.outputFile( - atomStylesheetDestinationFilePath, - stylesheetContent, - 'utf-8', - ); - }, + const stylesheetContent = await fs.readFile( + atomStylesheetSourceFilePath, + 'utf8', + ); + await fs.outputFile( + atomStylesheetDestinationFilePath, + stylesheetContent, + 'utf-8', ); } From 034bb821752e2203c25a282b8a61b4c4ea2a1f0e Mon Sep 17 00:00:00 2001 From: ozakione <29860391+OzakIOne@users.noreply.github.com> Date: Wed, 24 Jul 2024 14:52:03 +0200 Subject: [PATCH 05/36] object params --- package.json | 3 +- .../src/feed.ts | 33 +++++++++++-------- 2 files changed, 21 insertions(+), 15 deletions(-) diff --git a/package.json b/package.json index 2ba6e75b2dea..0594b94fcff3 100644 --- a/package.json +++ b/package.json @@ -117,5 +117,6 @@ "stylelint-config-prettier": "^9.0.5", "stylelint-config-standard": "^29.0.0", "typescript": "~5.2.2" - } + }, + "packageManager": "yarn@1.22.21+sha1.1959a18351b811cdeedbd484a8f86c3cc3bbaf72" } diff --git a/packages/docusaurus-plugin-content-blog/src/feed.ts b/packages/docusaurus-plugin-content-blog/src/feed.ts index 3ef8cf40fc2f..8c5e57ab352b 100644 --- a/packages/docusaurus-plugin-content-blog/src/feed.ts +++ b/packages/docusaurus-plugin-content-blog/src/feed.ts @@ -171,11 +171,15 @@ async function defaultCreateFeedItems({ * @param feedDetails array containing blog feed content and name of file * @param generatePath path where the file would be copied in website */ -async function addXmlStyleSheet( - feedDetails: string[], - generatePath: string, - stylesheet: string, -) { +async function addXmlStyleSheet({ + feedDetails, + generatePath, + stylesheet, +}: { + feedDetails: string[]; + generatePath: string; + stylesheet: string; +}) { const DEFAULT_RSS_FEED = 'rss-feed.xslt'; const DEFAULT_ATOM_FEED = 'atom-feed.xslt'; @@ -277,12 +281,12 @@ async function createBlogFeedFile({ feed, feedType, generatePath, - addXSL, + xslParams, }: { feed: Feed; feedType: FeedType; generatePath: string; - addXSL?: XslParams; + xslParams?: XslParams; }) { let feedDetails = (() => { switch (feedType) { @@ -297,14 +301,15 @@ async function createBlogFeedFile({ } })(); try { - if (addXSL?.enable) { - feedDetails = await addXmlStyleSheet( + if (xslParams?.enable) { + feedDetails = await addXmlStyleSheet({ feedDetails, generatePath, - feedDetails[1] === 'atom.xml' - ? addXSL.atomStylesheet - : addXSL.rssStylesheet, - ); + stylesheet: + feedDetails[1] === 'atom.xml' + ? xslParams.atomStylesheet + : xslParams.rssStylesheet, + }); } await fs.outputFile( @@ -358,7 +363,7 @@ export async function createBlogFeedFiles({ feed, feedType, generatePath: path.join(outDir, options.routeBasePath), - addXSL: options.feedOptions.xsl, + xslParams: options.feedOptions.xsl, }), ), ); From 3745125c129fadbca4b7d7e94994b5c77613ed71 Mon Sep 17 00:00:00 2001 From: ozakione <29860391+OzakIOne@users.noreply.github.com> Date: Thu, 25 Jul 2024 16:33:36 +0200 Subject: [PATCH 06/36] refactor options, refactor build / assets --- .../src/feed.ts | 113 +++++++++--------- .../src/index.ts | 1 + .../src/options.ts | 21 +++- .../src/plugin-content-blog.d.ts | 7 +- .../_blog tests/custom-atom.css} | 0 .../_blog tests/custom-atom.xslt} | 4 +- .../_dogfooding/_blog tests/custom-rss.css | 76 ++++++++++++ .../_dogfooding/_blog tests/custom-rss.xslt | 6 +- .../_dogfooding/_blog tests/rss-feed.css | 0 .../_dogfooding/_blog tests}/rss-feed.xslt | 4 +- website/_dogfooding/dogfooding.config.js | 8 +- website/blog/custom-atom.css | 76 ++++++++++++ website/blog/custom-atom.xslt | 65 ++++++++++ .../blog/rss-feed.css | 2 +- .../rss-feed.xslt} | 6 +- website/docusaurus.config.js | 5 +- 16 files changed, 308 insertions(+), 86 deletions(-) rename website/{static/xslt-stylesheet.css => _dogfooding/_blog tests/custom-atom.css} (100%) rename website/{static/custom-atom.stylesheet.xslt => _dogfooding/_blog tests/custom-atom.xslt} (97%) create mode 100644 website/_dogfooding/_blog tests/custom-rss.css rename packages/docusaurus-plugin-content-blog/assets/atom-feed.xslt => website/_dogfooding/_blog tests/custom-rss.xslt (96%) rename packages/docusaurus-plugin-content-blog/assets/atom-feed.stylesheet.css => website/_dogfooding/_blog tests/rss-feed.css (100%) rename {packages/docusaurus-plugin-content-blog/assets => website/_dogfooding/_blog tests}/rss-feed.xslt (96%) create mode 100644 website/blog/custom-atom.css create mode 100644 website/blog/custom-atom.xslt rename packages/docusaurus-plugin-content-blog/assets/rss-feed.stylesheet.css => website/blog/rss-feed.css (97%) rename website/{static/custom-rss.stylesheet.xslt => blog/rss-feed.xslt} (95%) diff --git a/packages/docusaurus-plugin-content-blog/src/feed.ts b/packages/docusaurus-plugin-content-blog/src/feed.ts index 8c5e57ab352b..0ff1f3400737 100644 --- a/packages/docusaurus-plugin-content-blog/src/feed.ts +++ b/packages/docusaurus-plugin-content-blog/src/feed.ts @@ -7,12 +7,12 @@ import path from 'path'; import fs from 'fs-extra'; -import logger from '@docusaurus/logger'; import {Feed, type Author as FeedAuthor} from 'feed'; import * as srcset from 'srcset'; import {normalizeUrl, readOutputHTMLFile} from '@docusaurus/utils'; import {blogPostContainerID} from '@docusaurus/utils-common'; import {load as cheerioLoad} from 'cheerio'; +import type {BlogContentPaths} from './types'; import type {DocusaurusConfig} from '@docusaurus/types'; import type { FeedType, @@ -20,7 +20,6 @@ import type { Author, BlogPost, BlogFeedItem, - XslParams, } from '@docusaurus/plugin-content-blog'; async function generateBlogFeed({ @@ -174,99 +173,78 @@ async function defaultCreateFeedItems({ async function addXmlStyleSheet({ feedDetails, generatePath, - stylesheet, + xslPath, + contentPaths, }: { feedDetails: string[]; generatePath: string; - stylesheet: string; + xslPath: string; + contentPaths: BlogContentPaths; }) { - const DEFAULT_RSS_FEED = 'rss-feed.xslt'; - const DEFAULT_ATOM_FEED = 'atom-feed.xslt'; - if (!feedDetails[0]) { return feedDetails; } + const {contentPath} = contentPaths; + console.log('contentPaths:', contentPath); if (feedDetails[1] === 'rss.xml') { - let xsltLink = ``; - - if (stylesheet) { - xsltLink = ``; - } + const fileName = path.parse(xslPath).name; + const xsltLink = ``; feedDetails[0] = feedDetails[0]?.replace( '', xsltLink, ); + const defaultRssXsltPath = path.join(contentPath, `./${fileName}.xslt`); + const defaultCssPath = path.join(contentPath, `./${fileName}.css`); - const rssXsltSourceFilePath = path.join( - __dirname, - '../assets/rss-feed.xslt', - ); - const rssStylesheetSourceFilePath = path.join( - __dirname, - '../assets/rss-feed.stylesheet.css', + const rssXsltDestinationFilePath = path.join( + generatePath, + `${fileName}.xslt`, ); - - const rssXsltDestinationFilePath = path.join(generatePath, 'rss-feed.xslt'); const rssStylesheetDestinationFilePath = path.join( generatePath, - 'rss-feed.stylesheet.css', + `${fileName}.css`, ); // output rss xslt file to website - const xsltContent = await fs.readFile(rssXsltSourceFilePath, 'utf8'); + const xsltContent = await fs.readFile(defaultRssXsltPath, 'utf8'); await fs.outputFile(rssXsltDestinationFilePath, xsltContent, 'utf-8'); // output rss stylesheet to website - const stylesheetContent = await fs.readFile( - rssStylesheetSourceFilePath, - 'utf8', - ); + const stylesheetContent = await fs.readFile(defaultCssPath, 'utf8'); await fs.outputFile( rssStylesheetDestinationFilePath, stylesheetContent, 'utf-8', ); } else if (feedDetails[1] === 'atom.xml') { - let xsltLink = ``; - - if (stylesheet) { - xsltLink = ``; - } + const fileName = path.parse(xslPath).name; + const xsltLink = ``; feedDetails[0] = feedDetails[0]?.replace( '', xsltLink, ); - const atomXsltSourceFilePath = path.join( - __dirname, - '../assets/atom-feed.xslt', - ); - const atomStylesheetSourceFilePath = path.join( - __dirname, - '../assets/atom-feed.stylesheet.css', - ); + const defaultAtomXsltPath = path.join(contentPath, `./${fileName}.xslt`); + const defaultCssPath = path.join(contentPath, `./${fileName}.css`); const atomXsltDestinationFilePath = path.join( generatePath, - 'atom-feed.xslt', + `${fileName}.xslt`, ); const atomStylesheetDestinationFilePath = path.join( generatePath, - 'atom-feed.stylesheet.css', + `${fileName}.css`, ); // output rss xslt file to website - const xsltContent = await fs.readFile(atomXsltSourceFilePath, 'utf8'); + const xsltContent = await fs.readFile(defaultAtomXsltPath, 'utf8'); await fs.outputFile(atomXsltDestinationFilePath, xsltContent, 'utf-8'); // output rss stylesheet to website - const stylesheetContent = await fs.readFile( - atomStylesheetSourceFilePath, - 'utf8', - ); + const stylesheetContent = await fs.readFile(defaultCssPath, 'utf8'); await fs.outputFile( atomStylesheetDestinationFilePath, stylesheetContent, @@ -281,12 +259,18 @@ async function createBlogFeedFile({ feed, feedType, generatePath, - xslParams, + xsl, + atom, + rss, + contentPaths, }: { feed: Feed; feedType: FeedType; generatePath: string; - xslParams?: XslParams; + xsl: boolean; + atom: string; + rss: string; + contentPaths: BlogContentPaths; }) { let feedDetails = (() => { switch (feedType) { @@ -301,14 +285,20 @@ async function createBlogFeedFile({ } })(); try { - if (xslParams?.enable) { + if (xsl) { + console.log( + 'generatePath:', + `${generatePath}/`, + // `${path.basename(generatePath)}/`, + atom, + rss, + ); + feedDetails = await addXmlStyleSheet({ feedDetails, generatePath, - stylesheet: - feedDetails[1] === 'atom.xml' - ? xslParams.atomStylesheet - : xslParams.rssStylesheet, + xslPath: feedDetails[1] === 'atom.xml' ? atom : rss, + contentPaths, }); } @@ -317,8 +307,7 @@ async function createBlogFeedFile({ feedDetails[0], ); } catch (err) { - logger.error(`Generating ${feedType} feed failed.`); - throw err; + throw new Error(`Error creating feed file: ${feedType}`, {cause: err}); } } @@ -335,12 +324,14 @@ export async function createBlogFeedFiles({ siteConfig, outDir, locale, + contentPaths, }: { blogPosts: BlogPost[]; options: PluginOptions; siteConfig: DocusaurusConfig; outDir: string; locale: string; + contentPaths: BlogContentPaths; }): Promise { const blogPosts = allBlogPosts.filter(shouldBeInFeed); @@ -356,6 +347,11 @@ export async function createBlogFeedFiles({ if (!feed || !feedTypes) { return; } + // console.log('PLUGIN ID ====:', options.id); + // console.log('feedTypes ====:', feedTypes); + // console.log('xslParams:', options.feedOptions.xsl); + // console.log('xslParams:', options.feedOptions.atomStylesheet); + // console.log('xslParams:', options.feedOptions.rssStylesheet); await Promise.all( feedTypes.map((feedType) => @@ -363,7 +359,10 @@ export async function createBlogFeedFiles({ feed, feedType, generatePath: path.join(outDir, options.routeBasePath), - xslParams: options.feedOptions.xsl, + xsl: options.feedOptions.xsl, + atom: options.feedOptions.atomStylesheet, + rss: options.feedOptions.rssStylesheet, + contentPaths, }), ), ); diff --git a/packages/docusaurus-plugin-content-blog/src/index.ts b/packages/docusaurus-plugin-content-blog/src/index.ts index d5ca869b4a1d..d1d75bc718b6 100644 --- a/packages/docusaurus-plugin-content-blog/src/index.ts +++ b/packages/docusaurus-plugin-content-blog/src/index.ts @@ -473,6 +473,7 @@ export default async function pluginContentBlog( outDir, siteConfig, locale: currentLocale, + contentPaths, }); }, diff --git a/packages/docusaurus-plugin-content-blog/src/options.ts b/packages/docusaurus-plugin-content-blog/src/options.ts index 7fdcd9c06741..c154306ac3c4 100644 --- a/packages/docusaurus-plugin-content-blog/src/options.ts +++ b/packages/docusaurus-plugin-content-blog/src/options.ts @@ -22,7 +22,14 @@ import type { import type {OptionValidationContext} from '@docusaurus/types'; export const DEFAULT_OPTIONS: PluginOptions = { - feedOptions: {type: ['rss', 'atom'], copyright: '', limit: 20}, + feedOptions: { + type: ['rss', 'atom'], + copyright: '', + limit: 20, + xsl: false, + atomStylesheet: 'atom-feed.xslt', + rssStylesheet: 'rss-feed.xslt', + }, beforeDefaultRehypePlugins: [], beforeDefaultRemarkPlugins: [], admonitions: true, @@ -111,11 +118,13 @@ const PluginOptionSchema = Joi.object({ ) .allow(null) .default(DEFAULT_OPTIONS.feedOptions.type), - xsl: Joi.object({ - enable: Joi.boolean(), - atomStylesheet: Joi.string(), - rssStylesheet: Joi.string(), - }), + xsl: Joi.boolean().default(DEFAULT_OPTIONS.feedOptions.xsl), + atomStylesheet: Joi.string().default( + DEFAULT_OPTIONS.feedOptions.atomStylesheet, + ), + rssStylesheet: Joi.string().default( + DEFAULT_OPTIONS.feedOptions.rssStylesheet, + ), title: Joi.string().allow(''), description: Joi.string().allow(''), // Only add default value when user actually wants a feed (type is not null) diff --git a/packages/docusaurus-plugin-content-blog/src/plugin-content-blog.d.ts b/packages/docusaurus-plugin-content-blog/src/plugin-content-blog.d.ts index 63723f1870ad..ec6bfeae8c7c 100644 --- a/packages/docusaurus-plugin-content-blog/src/plugin-content-blog.d.ts +++ b/packages/docusaurus-plugin-content-blog/src/plugin-content-blog.d.ts @@ -258,7 +258,8 @@ yarn workspace v1.22.19image` is a collocated image path, this entry will be the export type FeedType = 'rss' | 'atom' | 'json'; export type XslParams = { - enable: boolean; + /** Enable xsl stylesheet */ + xsl: boolean; rssStylesheet: string; atomStylesheet: string; }; @@ -266,7 +267,7 @@ yarn workspace v1.22.19image` is a collocated image path, this entry will be the /** * Normalized feed options used within code. */ - export type FeedOptions = { + export type FeedOptions = XslParams & { /** If `null`, no feed is generated. */ type?: FeedType[] | null; /** Title of generated feed. */ @@ -281,8 +282,6 @@ yarn workspace v1.22.19image` is a collocated image path, this entry will be the createFeedItems?: CreateFeedItemsFn; /** Limits the feed to the specified number of posts, false|null for all */ limit?: number | false | null; - /** Enable xsl stylesheet */ - xsl?: XslParams; }; type DefaultCreateFeedItemsParams = { diff --git a/website/static/xslt-stylesheet.css b/website/_dogfooding/_blog tests/custom-atom.css similarity index 100% rename from website/static/xslt-stylesheet.css rename to website/_dogfooding/_blog tests/custom-atom.css diff --git a/website/static/custom-atom.stylesheet.xslt b/website/_dogfooding/_blog tests/custom-atom.xslt similarity index 97% rename from website/static/custom-atom.stylesheet.xslt rename to website/_dogfooding/_blog tests/custom-atom.xslt index 3f37d7419c43..80406b153124 100644 --- a/website/static/custom-atom.stylesheet.xslt +++ b/website/_dogfooding/_blog tests/custom-atom.xslt @@ -8,7 +8,7 @@ Atom Feed | <xsl:value-of select="atom:feed/atom:title" /> - +
@@ -62,4 +62,4 @@ - \ No newline at end of file + diff --git a/website/_dogfooding/_blog tests/custom-rss.css b/website/_dogfooding/_blog tests/custom-rss.css new file mode 100644 index 000000000000..c016178d9007 --- /dev/null +++ b/website/_dogfooding/_blog tests/custom-rss.css @@ -0,0 +1,76 @@ +/** + * 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. + */ + +* { + color: #0d1137; +} + +main { + flex: 1 0 auto; + width: 100%; + margin: 4rem auto; + padding: 1.5 rem; + max-width: 800px; + /* stylelint-disable-next-line font-family-name-quotes */ + font-family: system-ui, -apple-system, Segoe UI, Roboto, Ubuntu, Cantarell; +} + +.info { + display: block; + margin: 3rem 0; + padding: 2rem 3rem; + border: 1px solid dodgerblue; + border-left-width: 0.5rem; + border-radius: 0.4rem; + background-color: #e52165; +} + +.rss-icon { + height: 3.8rem; + width: 3.8rem; + margin-right: 1rem; +} + +.flex { + display: flex; +} + +.items-start { + align-items: flex-start; +} + +.pb-7 { + padding-bottom: 3rem; +} + +a { + color: #005aff; + text-decoration: none; +} + +h1 { + text-wrap: balance; + font-size: 3.8rem; + line-height: 1; + font-weight: 800; + margin-bottom: 4rem; +} + +h2 { + font-size: 3rem; + line-height: 1.2; + font-weight: 700; + margin-bottom: 3rem; +} + +h2:not(:first-child) { + margin-top: 5.8rem; +} + +.italic { + font-style: italic; +} diff --git a/packages/docusaurus-plugin-content-blog/assets/atom-feed.xslt b/website/_dogfooding/_blog tests/custom-rss.xslt similarity index 96% rename from packages/docusaurus-plugin-content-blog/assets/atom-feed.xslt rename to website/_dogfooding/_blog tests/custom-rss.xslt index d619961df098..80406b153124 100644 --- a/packages/docusaurus-plugin-content-blog/assets/atom-feed.xslt +++ b/website/_dogfooding/_blog tests/custom-rss.xslt @@ -8,7 +8,7 @@ Atom Feed | <xsl:value-of select="atom:feed/atom:title" /> - +
@@ -35,7 +35,7 @@ - Atom Feed Preview + Custom Atom Feed Preview

@@ -62,4 +62,4 @@ - \ No newline at end of file + diff --git a/packages/docusaurus-plugin-content-blog/assets/atom-feed.stylesheet.css b/website/_dogfooding/_blog tests/rss-feed.css similarity index 100% rename from packages/docusaurus-plugin-content-blog/assets/atom-feed.stylesheet.css rename to website/_dogfooding/_blog tests/rss-feed.css diff --git a/packages/docusaurus-plugin-content-blog/assets/rss-feed.xslt b/website/_dogfooding/_blog tests/rss-feed.xslt similarity index 96% rename from packages/docusaurus-plugin-content-blog/assets/rss-feed.xslt rename to website/_dogfooding/_blog tests/rss-feed.xslt index c8a4c85780f1..3698dadf4e94 100644 --- a/packages/docusaurus-plugin-content-blog/assets/rss-feed.xslt +++ b/website/_dogfooding/_blog tests/rss-feed.xslt @@ -8,7 +8,7 @@ RSS Feed | <xsl:value-of select="rss/channel/title" /> - +
@@ -63,4 +63,4 @@ - \ No newline at end of file + diff --git a/website/_dogfooding/dogfooding.config.js b/website/_dogfooding/dogfooding.config.js index 7b5cf84164f8..144e67c69858 100644 --- a/website/_dogfooding/dogfooding.config.js +++ b/website/_dogfooding/dogfooding.config.js @@ -67,11 +67,9 @@ const dogfoodingPluginInstances = [ type: 'all', title: 'Docusaurus Tests Blog', copyright: `Copyright © ${new Date().getFullYear()} Facebook, Inc.`, - xsl: { - enable: true, - rssStylesheet: 'custom-rss.stylesheet.xslt', - atomStylesheet: 'custom-atom.stylesheet.xslt', - }, + // xsl: true, + // rssStylesheet: 'custom-rss.xslt', + // atomStylesheet: 'custom-atom.xslt', }, readingTime: ({content, frontMatter, defaultReadingTime}) => frontMatter.hide_reading_time diff --git a/website/blog/custom-atom.css b/website/blog/custom-atom.css new file mode 100644 index 000000000000..c016178d9007 --- /dev/null +++ b/website/blog/custom-atom.css @@ -0,0 +1,76 @@ +/** + * 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. + */ + +* { + color: #0d1137; +} + +main { + flex: 1 0 auto; + width: 100%; + margin: 4rem auto; + padding: 1.5 rem; + max-width: 800px; + /* stylelint-disable-next-line font-family-name-quotes */ + font-family: system-ui, -apple-system, Segoe UI, Roboto, Ubuntu, Cantarell; +} + +.info { + display: block; + margin: 3rem 0; + padding: 2rem 3rem; + border: 1px solid dodgerblue; + border-left-width: 0.5rem; + border-radius: 0.4rem; + background-color: #e52165; +} + +.rss-icon { + height: 3.8rem; + width: 3.8rem; + margin-right: 1rem; +} + +.flex { + display: flex; +} + +.items-start { + align-items: flex-start; +} + +.pb-7 { + padding-bottom: 3rem; +} + +a { + color: #005aff; + text-decoration: none; +} + +h1 { + text-wrap: balance; + font-size: 3.8rem; + line-height: 1; + font-weight: 800; + margin-bottom: 4rem; +} + +h2 { + font-size: 3rem; + line-height: 1.2; + font-weight: 700; + margin-bottom: 3rem; +} + +h2:not(:first-child) { + margin-top: 5.8rem; +} + +.italic { + font-style: italic; +} diff --git a/website/blog/custom-atom.xslt b/website/blog/custom-atom.xslt new file mode 100644 index 000000000000..80406b153124 --- /dev/null +++ b/website/blog/custom-atom.xslt @@ -0,0 +1,65 @@ + + + + + + + + + Atom Feed | <xsl:value-of select="atom:feed/atom:title" /> + + + +
+
+
+ This is an Atom feed. Subscribe by copying the URL from the address + bar into your newsreader. Visit About Feeds to learn more + and get started. It’s free.
+

+
+ + + + + + + + + + +
+ Custom Atom Feed Preview

+

+ +

+

Description:

+
+

Recent Posts

+
+ +
+ + + +
Published on +
+
+ +
+
+
+
+
+ + +
+ +
diff --git a/packages/docusaurus-plugin-content-blog/assets/rss-feed.stylesheet.css b/website/blog/rss-feed.css similarity index 97% rename from packages/docusaurus-plugin-content-blog/assets/rss-feed.stylesheet.css rename to website/blog/rss-feed.css index 17d483670f0d..9e2b9043ec30 100644 --- a/packages/docusaurus-plugin-content-blog/assets/rss-feed.stylesheet.css +++ b/website/blog/rss-feed.css @@ -22,7 +22,7 @@ main { border: 1px solid dodgerblue; border-left-width: 0.5rem; border-radius: 0.4rem; - background-color: #edf5ff; + background-color: #000; } .rss-icon { diff --git a/website/static/custom-rss.stylesheet.xslt b/website/blog/rss-feed.xslt similarity index 95% rename from website/static/custom-rss.stylesheet.xslt rename to website/blog/rss-feed.xslt index 4159dab155d0..009985dabf8e 100644 --- a/website/static/custom-rss.stylesheet.xslt +++ b/website/blog/rss-feed.xslt @@ -8,7 +8,7 @@ RSS Feed | <xsl:value-of select="rss/channel/title" /> - +
@@ -35,7 +35,7 @@ - Custom RSS Feed Preview + RSS Feed Preview

@@ -63,4 +63,4 @@ - \ No newline at end of file + diff --git a/website/docusaurus.config.js b/website/docusaurus.config.js index 6ef97f69580b..5347f2a6e598 100644 --- a/website/docusaurus.config.js +++ b/website/docusaurus.config.js @@ -420,9 +420,8 @@ module.exports = async function createConfigAsync() { feedOptions: { type: 'all', copyright: `Copyright © ${new Date().getFullYear()} Facebook, Inc.`, - xsl: { - enable: true - } + xsl: true, + atomStylesheet: 'custom-atom.xslt', }, blogSidebarCount: 'ALL', blogSidebarTitle: 'All our posts', From 1daded2261f1788ce1e62eff1522be99c6f92cbb Mon Sep 17 00:00:00 2001 From: ozakione <29860391+OzakIOne@users.noreply.github.com> Date: Thu, 25 Jul 2024 22:00:20 +0200 Subject: [PATCH 07/36] refactor assets location --- .../assets/atom.css | 76 +++++++++++++++++++ .../assets/atom.xslt | 65 ++++++++++++++++ .../assets/rss.css | 2 +- .../assets/rss.xslt | 2 +- .../src/feed.ts | 26 +++++-- .../src/options.ts | 12 +-- .../src/plugin-content-blog.d.ts | 4 +- website/_dogfooding/dogfooding.config.js | 4 +- website/docusaurus.config.js | 2 +- 9 files changed, 170 insertions(+), 23 deletions(-) create mode 100644 packages/docusaurus-plugin-content-blog/assets/atom.css create mode 100644 packages/docusaurus-plugin-content-blog/assets/atom.xslt rename website/blog/rss-feed.css => packages/docusaurus-plugin-content-blog/assets/rss.css (97%) rename website/blog/rss-feed.xslt => packages/docusaurus-plugin-content-blog/assets/rss.xslt (97%) diff --git a/packages/docusaurus-plugin-content-blog/assets/atom.css b/packages/docusaurus-plugin-content-blog/assets/atom.css new file mode 100644 index 000000000000..2d5975b1b3f8 --- /dev/null +++ b/packages/docusaurus-plugin-content-blog/assets/atom.css @@ -0,0 +1,76 @@ +/** + * 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. + */ + +* { + color: #0d1137; +} + +main { + flex: 1 0 auto; + width: 100%; + margin: 4rem auto; + padding: 1.5 rem; + max-width: 800px; + /* stylelint-disable-next-line font-family-name-quotes */ + font-family: system-ui, -apple-system, Segoe UI, Roboto, Ubuntu, Cantarell; +} + +.info { + display: block; + margin: 3rem 0; + padding: 2rem 3rem; + border: 1px solid dodgerblue; + border-left-width: 0.5rem; + border-radius: 0.4rem; + background-color: #edf5ff; +} + +.rss-icon { + height: 3.8rem; + width: 3.8rem; + margin-right: 1rem; +} + +.flex { + display: flex; +} + +.items-start { + align-items: flex-start; +} + +.pb-7 { + padding-bottom: 3rem; +} + +a { + color: #005aff; + text-decoration: none; +} + +h1 { + text-wrap: balance; + font-size: 3.8rem; + line-height: 1; + font-weight: 800; + margin-bottom: 4rem; +} + +h2 { + font-size: 3rem; + line-height: 1.2; + font-weight: 700; + margin-bottom: 3rem; +} + +h2:not(:first-child) { + margin-top: 5.8rem; +} + +.italic { + font-style: italic; +} diff --git a/packages/docusaurus-plugin-content-blog/assets/atom.xslt b/packages/docusaurus-plugin-content-blog/assets/atom.xslt new file mode 100644 index 000000000000..f62448953f59 --- /dev/null +++ b/packages/docusaurus-plugin-content-blog/assets/atom.xslt @@ -0,0 +1,65 @@ + + + + + + + + + Atom Feed | <xsl:value-of select="atom:feed/atom:title" /> + + + +
+
+
+ This is an Atom feed. Subscribe by copying the URL from the address + bar into your newsreader. Visit About Feeds to learn more + and get started. It’s free.
+

+
+ + + + + + + + + + +
+ Custom Atom Feed Preview

+

+ +

+

Description:

+
+

Recent Posts

+
+ +
+ + + +
Published on +
+
+ +
+
+
+
+
+ + +
+ +
diff --git a/website/blog/rss-feed.css b/packages/docusaurus-plugin-content-blog/assets/rss.css similarity index 97% rename from website/blog/rss-feed.css rename to packages/docusaurus-plugin-content-blog/assets/rss.css index 9e2b9043ec30..17d483670f0d 100644 --- a/website/blog/rss-feed.css +++ b/packages/docusaurus-plugin-content-blog/assets/rss.css @@ -22,7 +22,7 @@ main { border: 1px solid dodgerblue; border-left-width: 0.5rem; border-radius: 0.4rem; - background-color: #000; + background-color: #edf5ff; } .rss-icon { diff --git a/website/blog/rss-feed.xslt b/packages/docusaurus-plugin-content-blog/assets/rss.xslt similarity index 97% rename from website/blog/rss-feed.xslt rename to packages/docusaurus-plugin-content-blog/assets/rss.xslt index 009985dabf8e..3d0db18eb509 100644 --- a/website/blog/rss-feed.xslt +++ b/packages/docusaurus-plugin-content-blog/assets/rss.xslt @@ -8,7 +8,7 @@ RSS Feed | <xsl:value-of select="rss/channel/title" /> - +
diff --git a/packages/docusaurus-plugin-content-blog/src/feed.ts b/packages/docusaurus-plugin-content-blog/src/feed.ts index 0ff1f3400737..5e5d765e30d3 100644 --- a/packages/docusaurus-plugin-content-blog/src/feed.ts +++ b/packages/docusaurus-plugin-content-blog/src/feed.ts @@ -189,14 +189,19 @@ async function addXmlStyleSheet({ if (feedDetails[1] === 'rss.xml') { const fileName = path.parse(xslPath).name; + const isDefault = xslPath === 'rss.xslt'; + const directoryPath = isDefault + ? path.join(__dirname, '../assets/') + : contentPath; const xsltLink = ``; feedDetails[0] = feedDetails[0]?.replace( '', xsltLink, ); - const defaultRssXsltPath = path.join(contentPath, `./${fileName}.xslt`); - const defaultCssPath = path.join(contentPath, `./${fileName}.css`); + + const defaultRssXsltPath = path.join(directoryPath, `${fileName}.xslt`); + const defaultCssPath = path.join(directoryPath, `${fileName}.css`); const rssXsltDestinationFilePath = path.join( generatePath, @@ -220,6 +225,11 @@ async function addXmlStyleSheet({ ); } else if (feedDetails[1] === 'atom.xml') { const fileName = path.parse(xslPath).name; + const isDefault = xslPath === 'rss.xslt'; + const directoryPath = isDefault + ? path.join(__dirname, '../assets/') + : contentPath; + const xsltLink = ``; feedDetails[0] = feedDetails[0]?.replace( @@ -227,8 +237,8 @@ async function addXmlStyleSheet({ xsltLink, ); - const defaultAtomXsltPath = path.join(contentPath, `./${fileName}.xslt`); - const defaultCssPath = path.join(contentPath, `./${fileName}.css`); + const defaultAtomXsltPath = path.join(directoryPath, `${fileName}.xslt`); + const defaultCssPath = path.join(directoryPath, `${fileName}.css`); const atomXsltDestinationFilePath = path.join( generatePath, @@ -350,8 +360,8 @@ export async function createBlogFeedFiles({ // console.log('PLUGIN ID ====:', options.id); // console.log('feedTypes ====:', feedTypes); // console.log('xslParams:', options.feedOptions.xsl); - // console.log('xslParams:', options.feedOptions.atomStylesheet); - // console.log('xslParams:', options.feedOptions.rssStylesheet); + // console.log('xslParams:', options.feedOptions.atomXslt); + // console.log('xslParams:', options.feedOptions.rssXslt); await Promise.all( feedTypes.map((feedType) => @@ -360,8 +370,8 @@ export async function createBlogFeedFiles({ feedType, generatePath: path.join(outDir, options.routeBasePath), xsl: options.feedOptions.xsl, - atom: options.feedOptions.atomStylesheet, - rss: options.feedOptions.rssStylesheet, + atom: options.feedOptions.atomXslt, + rss: options.feedOptions.rssXslt, contentPaths, }), ), diff --git a/packages/docusaurus-plugin-content-blog/src/options.ts b/packages/docusaurus-plugin-content-blog/src/options.ts index c154306ac3c4..0d67c5ce12cb 100644 --- a/packages/docusaurus-plugin-content-blog/src/options.ts +++ b/packages/docusaurus-plugin-content-blog/src/options.ts @@ -27,8 +27,8 @@ export const DEFAULT_OPTIONS: PluginOptions = { copyright: '', limit: 20, xsl: false, - atomStylesheet: 'atom-feed.xslt', - rssStylesheet: 'rss-feed.xslt', + atomXslt: 'atom.xslt', + rssXslt: 'rss.xslt', }, beforeDefaultRehypePlugins: [], beforeDefaultRemarkPlugins: [], @@ -119,12 +119,8 @@ const PluginOptionSchema = Joi.object({ .allow(null) .default(DEFAULT_OPTIONS.feedOptions.type), xsl: Joi.boolean().default(DEFAULT_OPTIONS.feedOptions.xsl), - atomStylesheet: Joi.string().default( - DEFAULT_OPTIONS.feedOptions.atomStylesheet, - ), - rssStylesheet: Joi.string().default( - DEFAULT_OPTIONS.feedOptions.rssStylesheet, - ), + atomXslt: Joi.string().default(DEFAULT_OPTIONS.feedOptions.atomXslt), + rssXslt: Joi.string().default(DEFAULT_OPTIONS.feedOptions.rssXslt), title: Joi.string().allow(''), description: Joi.string().allow(''), // Only add default value when user actually wants a feed (type is not null) diff --git a/packages/docusaurus-plugin-content-blog/src/plugin-content-blog.d.ts b/packages/docusaurus-plugin-content-blog/src/plugin-content-blog.d.ts index ec6bfeae8c7c..b9ea8fbd5bd5 100644 --- a/packages/docusaurus-plugin-content-blog/src/plugin-content-blog.d.ts +++ b/packages/docusaurus-plugin-content-blog/src/plugin-content-blog.d.ts @@ -260,8 +260,8 @@ yarn workspace v1.22.19image` is a collocated image path, this entry will be the export type XslParams = { /** Enable xsl stylesheet */ xsl: boolean; - rssStylesheet: string; - atomStylesheet: string; + rssXslt: string; + atomXslt: string; }; /** diff --git a/website/_dogfooding/dogfooding.config.js b/website/_dogfooding/dogfooding.config.js index 144e67c69858..23d204e59b73 100644 --- a/website/_dogfooding/dogfooding.config.js +++ b/website/_dogfooding/dogfooding.config.js @@ -68,8 +68,8 @@ const dogfoodingPluginInstances = [ title: 'Docusaurus Tests Blog', copyright: `Copyright © ${new Date().getFullYear()} Facebook, Inc.`, // xsl: true, - // rssStylesheet: 'custom-rss.xslt', - // atomStylesheet: 'custom-atom.xslt', + // rssXslt: 'custom-rss.xslt', + // atomXslt: 'custom-atom.xslt', }, readingTime: ({content, frontMatter, defaultReadingTime}) => frontMatter.hide_reading_time diff --git a/website/docusaurus.config.js b/website/docusaurus.config.js index 5347f2a6e598..8fe0e0799a1c 100644 --- a/website/docusaurus.config.js +++ b/website/docusaurus.config.js @@ -421,7 +421,7 @@ module.exports = async function createConfigAsync() { type: 'all', copyright: `Copyright © ${new Date().getFullYear()} Facebook, Inc.`, xsl: true, - atomStylesheet: 'custom-atom.xslt', + atomXslt: 'custom-atom.xslt', }, blogSidebarCount: 'ALL', blogSidebarTitle: 'All our posts', From c79902bbb8d9da1f12849282553154fe6c759ebe Mon Sep 17 00:00:00 2001 From: ozakione <29860391+OzakIOne@users.noreply.github.com> Date: Thu, 25 Jul 2024 23:34:18 +0200 Subject: [PATCH 08/36] more refactor --- .../src/feed.ts | 132 +++++------------- .../src/options.ts | 4 +- .../src/plugin-content-blog.d.ts | 2 +- website/blog/custom-rss.css | 76 ++++++++++ website/blog/custom-rss.xslt | 65 +++++++++ website/docusaurus.config.js | 5 +- 6 files changed, 182 insertions(+), 102 deletions(-) create mode 100644 website/blog/custom-rss.css create mode 100644 website/blog/custom-rss.xslt diff --git a/packages/docusaurus-plugin-content-blog/src/feed.ts b/packages/docusaurus-plugin-content-blog/src/feed.ts index 5e5d765e30d3..fc5079ac4a1b 100644 --- a/packages/docusaurus-plugin-content-blog/src/feed.ts +++ b/packages/docusaurus-plugin-content-blog/src/feed.ts @@ -184,83 +184,34 @@ async function addXmlStyleSheet({ if (!feedDetails[0]) { return feedDetails; } - const {contentPath} = contentPaths; - console.log('contentPaths:', contentPath); - - if (feedDetails[1] === 'rss.xml') { - const fileName = path.parse(xslPath).name; - const isDefault = xslPath === 'rss.xslt'; - const directoryPath = isDefault - ? path.join(__dirname, '../assets/') - : contentPath; - const xsltLink = ``; - - feedDetails[0] = feedDetails[0]?.replace( - '', - xsltLink, - ); - - const defaultRssXsltPath = path.join(directoryPath, `${fileName}.xslt`); - const defaultCssPath = path.join(directoryPath, `${fileName}.css`); - - const rssXsltDestinationFilePath = path.join( - generatePath, - `${fileName}.xslt`, - ); - const rssStylesheetDestinationFilePath = path.join( - generatePath, - `${fileName}.css`, - ); - - // output rss xslt file to website - const xsltContent = await fs.readFile(defaultRssXsltPath, 'utf8'); - await fs.outputFile(rssXsltDestinationFilePath, xsltContent, 'utf-8'); - - // output rss stylesheet to website - const stylesheetContent = await fs.readFile(defaultCssPath, 'utf8'); - await fs.outputFile( - rssStylesheetDestinationFilePath, - stylesheetContent, - 'utf-8', - ); - } else if (feedDetails[1] === 'atom.xml') { - const fileName = path.parse(xslPath).name; - const isDefault = xslPath === 'rss.xslt'; - const directoryPath = isDefault - ? path.join(__dirname, '../assets/') - : contentPath; - - const xsltLink = ``; - - feedDetails[0] = feedDetails[0]?.replace( - '', - xsltLink, - ); - const defaultAtomXsltPath = path.join(directoryPath, `${fileName}.xslt`); - const defaultCssPath = path.join(directoryPath, `${fileName}.css`); + const {contentPath} = contentPaths; + const fileName = path.parse(xslPath).name; + console.log(xslPath); + const isDefault = xslPath === 'rss.xslt' || xslPath === 'atom.xslt'; + console.log('isDefault:', isDefault); + const directoryPath = isDefault + ? path.join(__dirname, '../assets/') + : contentPath; + const xsltLink = ``; + + feedDetails[0] = feedDetails[0]?.replace( + '', + xsltLink, + ); - const atomXsltDestinationFilePath = path.join( - generatePath, - `${fileName}.xslt`, - ); - const atomStylesheetDestinationFilePath = path.join( - generatePath, - `${fileName}.css`, - ); + const xsltPath = path.join(directoryPath, `${fileName}.xslt`); + const cssPath = path.join(directoryPath, `${fileName}.css`); + const xsltGeneratePath = path.join(generatePath, `${fileName}.xslt`); + const cssGeneratePath = path.join(generatePath, `${fileName}.css`); - // output rss xslt file to website - const xsltContent = await fs.readFile(defaultAtomXsltPath, 'utf8'); - await fs.outputFile(atomXsltDestinationFilePath, xsltContent, 'utf-8'); + // output xslt file to website + const xsltContent = await fs.readFile(xsltPath, 'utf8'); + await fs.outputFile(xsltGeneratePath, xsltContent, 'utf-8'); - // output rss stylesheet to website - const stylesheetContent = await fs.readFile(defaultCssPath, 'utf8'); - await fs.outputFile( - atomStylesheetDestinationFilePath, - stylesheetContent, - 'utf-8', - ); - } + // output stylesheet to website + const stylesheetContent = await fs.readFile(cssPath, 'utf8'); + await fs.outputFile(cssGeneratePath, stylesheetContent, 'utf-8'); return feedDetails; } @@ -269,17 +220,17 @@ async function createBlogFeedFile({ feed, feedType, generatePath, - xsl, - atom, - rss, + xslt, + atomXslt, + rssXslt, contentPaths, }: { feed: Feed; feedType: FeedType; generatePath: string; - xsl: boolean; - atom: string; - rss: string; + xslt: boolean; + atomXslt: string; + rssXslt: string; contentPaths: BlogContentPaths; }) { let feedDetails = (() => { @@ -295,19 +246,11 @@ async function createBlogFeedFile({ } })(); try { - if (xsl) { - console.log( - 'generatePath:', - `${generatePath}/`, - // `${path.basename(generatePath)}/`, - atom, - rss, - ); - + if (xslt) { feedDetails = await addXmlStyleSheet({ feedDetails, generatePath, - xslPath: feedDetails[1] === 'atom.xml' ? atom : rss, + xslPath: feedDetails[1] === 'atom.xml' ? atomXslt : rssXslt, contentPaths, }); } @@ -357,11 +300,6 @@ export async function createBlogFeedFiles({ if (!feed || !feedTypes) { return; } - // console.log('PLUGIN ID ====:', options.id); - // console.log('feedTypes ====:', feedTypes); - // console.log('xslParams:', options.feedOptions.xsl); - // console.log('xslParams:', options.feedOptions.atomXslt); - // console.log('xslParams:', options.feedOptions.rssXslt); await Promise.all( feedTypes.map((feedType) => @@ -369,9 +307,9 @@ export async function createBlogFeedFiles({ feed, feedType, generatePath: path.join(outDir, options.routeBasePath), - xsl: options.feedOptions.xsl, - atom: options.feedOptions.atomXslt, - rss: options.feedOptions.rssXslt, + xslt: options.feedOptions.xslt, + atomXslt: options.feedOptions.atomXslt, + rssXslt: options.feedOptions.rssXslt, contentPaths, }), ), diff --git a/packages/docusaurus-plugin-content-blog/src/options.ts b/packages/docusaurus-plugin-content-blog/src/options.ts index 0d67c5ce12cb..b46f0c36ffc4 100644 --- a/packages/docusaurus-plugin-content-blog/src/options.ts +++ b/packages/docusaurus-plugin-content-blog/src/options.ts @@ -26,7 +26,7 @@ export const DEFAULT_OPTIONS: PluginOptions = { type: ['rss', 'atom'], copyright: '', limit: 20, - xsl: false, + xslt: false, atomXslt: 'atom.xslt', rssXslt: 'rss.xslt', }, @@ -118,7 +118,7 @@ const PluginOptionSchema = Joi.object({ ) .allow(null) .default(DEFAULT_OPTIONS.feedOptions.type), - xsl: Joi.boolean().default(DEFAULT_OPTIONS.feedOptions.xsl), + xslt: Joi.boolean().default(DEFAULT_OPTIONS.feedOptions.xslt), atomXslt: Joi.string().default(DEFAULT_OPTIONS.feedOptions.atomXslt), rssXslt: Joi.string().default(DEFAULT_OPTIONS.feedOptions.rssXslt), title: Joi.string().allow(''), diff --git a/packages/docusaurus-plugin-content-blog/src/plugin-content-blog.d.ts b/packages/docusaurus-plugin-content-blog/src/plugin-content-blog.d.ts index b9ea8fbd5bd5..6ddc3a3360e6 100644 --- a/packages/docusaurus-plugin-content-blog/src/plugin-content-blog.d.ts +++ b/packages/docusaurus-plugin-content-blog/src/plugin-content-blog.d.ts @@ -259,7 +259,7 @@ yarn workspace v1.22.19image` is a collocated image path, this entry will be the export type XslParams = { /** Enable xsl stylesheet */ - xsl: boolean; + xslt: boolean; rssXslt: string; atomXslt: string; }; diff --git a/website/blog/custom-rss.css b/website/blog/custom-rss.css new file mode 100644 index 000000000000..c016178d9007 --- /dev/null +++ b/website/blog/custom-rss.css @@ -0,0 +1,76 @@ +/** + * 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. + */ + +* { + color: #0d1137; +} + +main { + flex: 1 0 auto; + width: 100%; + margin: 4rem auto; + padding: 1.5 rem; + max-width: 800px; + /* stylelint-disable-next-line font-family-name-quotes */ + font-family: system-ui, -apple-system, Segoe UI, Roboto, Ubuntu, Cantarell; +} + +.info { + display: block; + margin: 3rem 0; + padding: 2rem 3rem; + border: 1px solid dodgerblue; + border-left-width: 0.5rem; + border-radius: 0.4rem; + background-color: #e52165; +} + +.rss-icon { + height: 3.8rem; + width: 3.8rem; + margin-right: 1rem; +} + +.flex { + display: flex; +} + +.items-start { + align-items: flex-start; +} + +.pb-7 { + padding-bottom: 3rem; +} + +a { + color: #005aff; + text-decoration: none; +} + +h1 { + text-wrap: balance; + font-size: 3.8rem; + line-height: 1; + font-weight: 800; + margin-bottom: 4rem; +} + +h2 { + font-size: 3rem; + line-height: 1.2; + font-weight: 700; + margin-bottom: 3rem; +} + +h2:not(:first-child) { + margin-top: 5.8rem; +} + +.italic { + font-style: italic; +} diff --git a/website/blog/custom-rss.xslt b/website/blog/custom-rss.xslt new file mode 100644 index 000000000000..c258f34d5a42 --- /dev/null +++ b/website/blog/custom-rss.xslt @@ -0,0 +1,65 @@ + + + + + + + + + Atom Feed | <xsl:value-of select="atom:feed/atom:title" /> + + + +
+
+
+ This is an Atom feed. Subscribe by copying the URL from the address + bar into your newsreader. Visit About Feeds to learn more + and get started. It’s free.
+

+
+ + + + + + + + + + +
+ Custom Atom Feed Preview

+

+ +

+

Description:

+
+

Recent Posts

+
+ +
+ + + +
Published on +
+
+ +
+
+
+
+
+ + +
+ +
diff --git a/website/docusaurus.config.js b/website/docusaurus.config.js index 8fe0e0799a1c..54a0eb21f9ab 100644 --- a/website/docusaurus.config.js +++ b/website/docusaurus.config.js @@ -420,8 +420,9 @@ module.exports = async function createConfigAsync() { feedOptions: { type: 'all', copyright: `Copyright © ${new Date().getFullYear()} Facebook, Inc.`, - xsl: true, - atomXslt: 'custom-atom.xslt', + xslt: true, + // atomXslt: 'custom-atom.xslt', + rssXslt: 'custom-rss.xslt', }, blogSidebarCount: 'ALL', blogSidebarTitle: 'All our posts', From 545491633f3b1ce201d4b849fce67c022855749e Mon Sep 17 00:00:00 2001 From: ozakione <29860391+OzakIOne@users.noreply.github.com> Date: Thu, 25 Jul 2024 23:39:23 +0200 Subject: [PATCH 09/36] refactor --- .../docusaurus-plugin-content-blog/src/feed.ts | 15 ++++----------- 1 file changed, 4 insertions(+), 11 deletions(-) diff --git a/packages/docusaurus-plugin-content-blog/src/feed.ts b/packages/docusaurus-plugin-content-blog/src/feed.ts index fc5079ac4a1b..0de3fb66188d 100644 --- a/packages/docusaurus-plugin-content-blog/src/feed.ts +++ b/packages/docusaurus-plugin-content-blog/src/feed.ts @@ -20,6 +20,7 @@ import type { Author, BlogPost, BlogFeedItem, + FeedOptions, } from '@docusaurus/plugin-content-blog'; async function generateBlogFeed({ @@ -187,9 +188,7 @@ async function addXmlStyleSheet({ const {contentPath} = contentPaths; const fileName = path.parse(xslPath).name; - console.log(xslPath); const isDefault = xslPath === 'rss.xslt' || xslPath === 'atom.xslt'; - console.log('isDefault:', isDefault); const directoryPath = isDefault ? path.join(__dirname, '../assets/') : contentPath; @@ -220,17 +219,13 @@ async function createBlogFeedFile({ feed, feedType, generatePath, - xslt, - atomXslt, - rssXslt, + feedOptions: {atomXslt, rssXslt, xslt}, contentPaths, }: { feed: Feed; feedType: FeedType; generatePath: string; - xslt: boolean; - atomXslt: string; - rssXslt: string; + feedOptions: FeedOptions; contentPaths: BlogContentPaths; }) { let feedDetails = (() => { @@ -307,9 +302,7 @@ export async function createBlogFeedFiles({ feed, feedType, generatePath: path.join(outDir, options.routeBasePath), - xslt: options.feedOptions.xslt, - atomXslt: options.feedOptions.atomXslt, - rssXslt: options.feedOptions.rssXslt, + feedOptions: options.feedOptions, contentPaths, }), ), From e611d069e375d87e67a7a389827827759b4c17ce Mon Sep 17 00:00:00 2001 From: ozakione <29860391+OzakIOne@users.noreply.github.com> Date: Fri, 26 Jul 2024 17:20:28 +0200 Subject: [PATCH 10/36] fix tests --- .../__tests__/__snapshots__/feed.test.ts.snap | 1118 +++-------------- .../src/__tests__/feed.test.ts | 20 +- .../src/__tests__/options.test.ts | 29 +- 3 files changed, 212 insertions(+), 955 deletions(-) diff --git a/packages/docusaurus-plugin-content-blog/src/__tests__/__snapshots__/feed.test.ts.snap b/packages/docusaurus-plugin-content-blog/src/__tests__/__snapshots__/feed.test.ts.snap index 6ff7800263bd..9e6fb76e6b71 100644 --- a/packages/docusaurus-plugin-content-blog/src/__tests__/__snapshots__/feed.test.ts.snap +++ b/packages/docusaurus-plugin-content-blog/src/__tests__/__snapshots__/feed.test.ts.snap @@ -558,134 +558,6 @@ exports[`atom has feed item for each post 1`] = `
  • list3
  • Normal Text Italics Text Bold Text

    -

    link image

    ]]> - - - <![CDATA[Complex Slug]]> - https://docusaurus.io/myBaseUrl/blog/hey/my super path/héllô - - 2020-08-16T00:00:00.000Z - - complex url slug

    ]]>
    - - -
    - - <![CDATA[Simple Slug]]> - https://docusaurus.io/myBaseUrl/blog/simple/slug - - 2020-08-15T00:00:00.000Z - - simple url slug

    ]]>
    - - Sébastien Lorber - https://sebastienlorber.com - -
    - - <![CDATA[some heading]]> - https://docusaurus.io/myBaseUrl/blog/heading-as-title - - 2019-01-02T00:00:00.000Z - - - <![CDATA[date-matter]]> - https://docusaurus.io/myBaseUrl/blog/date-matter - - 2019-01-01T00:00:00.000Z - - date inside front matter

    ]]>
    - -
    - - <![CDATA[Happy 1st Birthday Slash! (translated)]]> - https://docusaurus.io/myBaseUrl/blog/2018/12/14/Happy-First-Birthday-Slash - - 2018-12-14T00:00:00.000Z - - Happy birthday! (translated)

    ]]>
    - - Yangshun Tay (translated) - - - Sébastien Lorber (translated) - lorber.sebastien@gmail.com - -
    -", -] -`; - -exports[`atom has xslt files for feed 1`] = ` -[ - " - - https://docusaurus.io/myBaseUrl/blog - Hello Blog - 2023-07-23T00:00:00.000Z - https://github.com/jpmonette/feed - - Hello Blog - https://docusaurus.io/myBaseUrl/image/favicon.ico - Copyright - - <![CDATA[test links]]> - https://docusaurus.io/myBaseUrl/blog/blog-with-links - - 2023-07-23T00:00:00.000Z - - absolute full url

    -

    absolute pathname

    -

    relative pathname

    -

    md link

    -

    anchor

    -

    relative pathname + anchor

    -

    -

    - -]]>
    -
    - - <![CDATA[MDX Blog Sample with require calls]]> - https://docusaurus.io/myBaseUrl/blog/mdx-require-blog-post - - 2021-03-06T00:00:00.000Z - - Test MDX with require calls

    - - - - -]]>
    -
    - - <![CDATA[Full Blog Sample]]> - https://docusaurus.io/myBaseUrl/blog/mdx-blog-post - - 2021-03-05T00:00:00.000Z - - HTML Heading 1 -

    HTML Heading 2

    -

    HTML Paragraph

    - - -

    Import DOM

    -

    Heading 1

    -

    Heading 2

    -

    Heading 3

    -

    Heading 4

    -
    Heading 5
    -
      -
    • list1
    • -
    • list2
    • -
    • list3
    • -
    -
      -
    • list1
    • -
    • list2
    • -
    • list3
    • -
    -

    Normal Text Italics Text Bold Text

    link image

    ]]>
    @@ -938,6 +810,102 @@ exports[`json filters to the first two entries using limit 1`] = ` ] `; +exports[`json has custom xslt files for feed 1`] = ` +[ + "{ + "version": "https://jsonfeed.org/version/1", + "title": "Hello Blog", + "home_page_url": "https://docusaurus.io/myBaseUrl/blog", + "description": "Hello Blog", + "items": [ + { + "id": "https://docusaurus.io/myBaseUrl/blog/blog-with-links", + "content_html": "

    absolute full url

    /n

    absolute pathname

    /n

    relative pathname

    /n

    md link

    /n

    anchor

    /n

    relative pathname + anchor

    /n

    /n

    \\"\\"

    /n/n", + "url": "https://docusaurus.io/myBaseUrl/blog/blog-with-links", + "title": "test links", + "summary": "absolute full url", + "date_modified": "2023-07-23T00:00:00.000Z", + "tags": [] + }, + { + "id": "https://docusaurus.io/myBaseUrl/blog/mdx-require-blog-post", + "content_html": "

    Test MDX with require calls

    /n/n/n/n/n", + "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", + "tags": [] + }, + { + "id": "https://docusaurus.io/myBaseUrl/blog/mdx-blog-post", + "content_html": "

    HTML Heading 1

    /n

    HTML Heading 2

    /n

    HTML Paragraph

    /n/n/n

    Import DOM

    /n

    Heading 1

    /n

    Heading 2

    /n

    Heading 3

    /n

    Heading 4

    /n
    Heading 5
    /n
      /n
    • list1
    • /n
    • list2
    • /n
    • list3
    • /n
    /n
      /n
    • list1
    • /n
    • list2
    • /n
    • list3
    • /n
    /n

    Normal Text Italics Text Bold Text

    /n

    link \\"image\\"

    ", + "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", + "tags": [] + }, + { + "id": "https://docusaurus.io/myBaseUrl/blog/hey/my super path/héllô", + "content_html": "

    complex url slug

    ", + "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", + "tags": [ + "date", + "complex" + ] + }, + { + "id": "https://docusaurus.io/myBaseUrl/blog/simple/slug", + "content_html": "

    simple url slug

    ", + "url": "https://docusaurus.io/myBaseUrl/blog/simple/slug", + "title": "Simple Slug", + "summary": "simple url slug", + "date_modified": "2020-08-15T00:00:00.000Z", + "author": { + "name": "Sébastien Lorber", + "url": "https://sebastienlorber.com" + }, + "tags": [] + }, + { + "id": "https://docusaurus.io/myBaseUrl/blog/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", + "tags": [] + }, + { + "id": "https://docusaurus.io/myBaseUrl/blog/date-matter", + "content_html": "

    date inside front matter

    ", + "url": "https://docusaurus.io/myBaseUrl/blog/date-matter", + "title": "date-matter", + "summary": "date inside front matter", + "date_modified": "2019-01-01T00:00:00.000Z", + "tags": [ + "date" + ] + }, + { + "id": "https://docusaurus.io/myBaseUrl/blog/2018/12/14/Happy-First-Birthday-Slash", + "content_html": "

    Happy birthday! (translated)

    ", + "url": "https://docusaurus.io/myBaseUrl/blog/2018/12/14/Happy-First-Birthday-Slash", + "title": "Happy 1st Birthday Slash! (translated)", + "summary": "Happy birthday! (translated)", + "date_modified": "2018-12-14T00:00:00.000Z", + "author": { + "name": "Yangshun Tay (translated)" + }, + "tags": [] + } + ] +}", +] +`; + exports[`json has feed item for each post - with trailing slash 1`] = ` [ "{ @@ -1037,7 +1005,7 @@ exports[`json has feed item for each post - with trailing slash 1`] = ` ] `; -exports[`json has custom xslt files for feed 1`] = ` +exports[`json has feed item for each post 1`] = ` [ "{ "version": "https://jsonfeed.org/version/1", @@ -1126,487 +1094,17 @@ exports[`json has custom xslt files for feed 1`] = ` "author": { "name": "Yangshun Tay (translated)" }, - "tags": [] + "tags": [ + "inlineTag", + "Global Tag label (en)" + ] } ] }", ] `; -exports[`json has feed item for each post 1`] = ` -[ - " - - - - - - - - RSS Feed | <xsl:value-of select="rss/channel/title" /> - - - -
    -
    -
    - This is an RSS feed. Subscribe by copying the URL from the address - bar into your newsreader. Visit About Feeds to learn more - and get started. It’s free.
    -

    -
    - - - - - - - - - - -
    - RSS Feed Preview

    -

    - -

    -

    Description:

    -
    -

    Recent Posts

    -
    - -
    - - - -
    Published on -
    -
    - -
    -
    -
    -
    -
    - - -
    - -
    ", - "/** - * 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. - */ - -main { - flex: 1 0 auto; - width: 100%; - margin: 4rem auto; - padding: 1.5 rem; - max-width: 800px; - /* stylelint-disable-next-line font-family-name-quotes */ - font-family: system-ui, -apple-system, Segoe UI, Roboto, Ubuntu, Cantarell; -} - -.info { - display: block; - margin: 3rem 0; - padding: 2rem 3rem; - border: 1px solid dodgerblue; - border-left-width: 0.5rem; - border-radius: 0.4rem; - background-color: #edf5ff; -} - -.rss-icon { - height: 3.8rem; - width: 3.8rem; - margin-right: 1rem; -} - -.flex { - display: flex; -} - -.items-start { - align-items: flex-start; -} - -.pb-7 { - padding-bottom: 3rem; -} - -a { - color: #005aff; - text-decoration: none; -} - -h1 { - text-wrap: balance; - font-size: 3.8rem; - line-height: 1; - font-weight: 800; - margin-bottom: 4rem; -} - -h2 { - font-size: 3rem; - line-height: 1.2; - font-weight: 700; - margin-bottom: 3rem; -} - -h2:not(:first-child) { - margin-top: 5.8rem; -} - -.italic { - font-style: italic; -} -", - "{ - "version": "https://jsonfeed.org/version/1", - "title": "Hello Blog", - "home_page_url": "https://docusaurus.io/myBaseUrl/blog", - "description": "Hello Blog", - "items": [ - { - "id": "https://docusaurus.io/myBaseUrl/blog/blog-with-links", - "content_html": "

    absolute full url

    /n

    absolute pathname

    /n

    relative pathname

    /n

    md link

    /n

    anchor

    /n

    relative pathname + anchor

    /n

    /n

    \\"\\"

    /n/n", - "url": "https://docusaurus.io/myBaseUrl/blog/blog-with-links", - "title": "test links", - "summary": "absolute full url", - "date_modified": "2023-07-23T00:00:00.000Z", - "tags": [] - }, - { - "id": "https://docusaurus.io/myBaseUrl/blog/mdx-require-blog-post", - "content_html": "

    Test MDX with require calls

    /n/n/n/n/n", - "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", - "tags": [] - }, - { - "id": "https://docusaurus.io/myBaseUrl/blog/mdx-blog-post", - "content_html": "

    HTML Heading 1

    /n

    HTML Heading 2

    /n

    HTML Paragraph

    /n/n/n

    Import DOM

    /n

    Heading 1

    /n

    Heading 2

    /n

    Heading 3

    /n

    Heading 4

    /n
    Heading 5
    /n
      /n
    • list1
    • /n
    • list2
    • /n
    • list3
    • /n
    /n
      /n
    • list1
    • /n
    • list2
    • /n
    • list3
    • /n
    /n

    Normal Text Italics Text Bold Text

    /n

    link \\"image\\"

    ", - "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", - "tags": [] - }, - { - "id": "https://docusaurus.io/myBaseUrl/blog/hey/my super path/héllô", - "content_html": "

    complex url slug

    ", - "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", - "tags": [ - "date", - "complex" - ] - }, - { - "id": "https://docusaurus.io/myBaseUrl/blog/simple/slug", - "content_html": "

    simple url slug

    ", - "url": "https://docusaurus.io/myBaseUrl/blog/simple/slug", - "title": "Simple Slug", - "summary": "simple url slug", - "date_modified": "2020-08-15T00:00:00.000Z", - "author": { - "name": "Sébastien Lorber", - "url": "https://sebastienlorber.com" - }, - "tags": [] - }, - { - "id": "https://docusaurus.io/myBaseUrl/blog/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", - "tags": [] - }, - { - "id": "https://docusaurus.io/myBaseUrl/blog/date-matter", - "content_html": "

    date inside front matter

    ", - "url": "https://docusaurus.io/myBaseUrl/blog/date-matter", - "title": "date-matter", - "summary": "date inside front matter", - "date_modified": "2019-01-01T00:00:00.000Z", - "tags": [ - "date" - ] - }, - { - "id": "https://docusaurus.io/myBaseUrl/blog/2018/12/14/Happy-First-Birthday-Slash", - "content_html": "

    Happy birthday! (translated)

    ", - "url": "https://docusaurus.io/myBaseUrl/blog/2018/12/14/Happy-First-Birthday-Slash", - "title": "Happy 1st Birthday Slash! (translated)", - "summary": "Happy birthday! (translated)", - "date_modified": "2018-12-14T00:00:00.000Z", - "author": { - "name": "Yangshun Tay (translated)" - }, - "tags": [] - } - ] -}", -] -`; - -exports[`json has xslt files for feed 1`] = ` -[ - " - - - - - - - - RSS Feed | <xsl:value-of select="rss/channel/title" /> - - - -
    -
    -
    - This is an RSS feed. Subscribe by copying the URL from the address - bar into your newsreader. Visit About Feeds to learn more - and get started. It’s free.
    -

    -
    - - - - - - - - - - -
    - RSS Feed Preview

    -

    - -

    -

    Description:

    -
    -

    Recent Posts

    -
    - -
    - - - -
    Published on -
    -
    - -
    -
    -
    -
    -
    - - -
    - -
    ", - "/** - * 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. - */ - -main { - flex: 1 0 auto; - width: 100%; - margin: 4rem auto; - padding: 1.5 rem; - max-width: 800px; - /* stylelint-disable-next-line font-family-name-quotes */ - font-family: system-ui, -apple-system, Segoe UI, Roboto, Ubuntu, Cantarell; -} - -.info { - display: block; - margin: 3rem 0; - padding: 2rem 3rem; - border: 1px solid dodgerblue; - border-left-width: 0.5rem; - border-radius: 0.4rem; - background-color: #edf5ff; -} - -.rss-icon { - height: 3.8rem; - width: 3.8rem; - margin-right: 1rem; -} - -.flex { - display: flex; -} - -.items-start { - align-items: flex-start; -} - -.pb-7 { - padding-bottom: 3rem; -} - -a { - color: #005aff; - text-decoration: none; -} - -h1 { - text-wrap: balance; - font-size: 3.8rem; - line-height: 1; - font-weight: 800; - margin-bottom: 4rem; -} - -h2 { - font-size: 3rem; - line-height: 1.2; - font-weight: 700; - margin-bottom: 3rem; -} - -h2:not(:first-child) { - margin-top: 5.8rem; -} - -.italic { - font-style: italic; -} -", - "{ - "version": "https://jsonfeed.org/version/1", - "title": "Hello Blog", - "home_page_url": "https://docusaurus.io/myBaseUrl/blog", - "description": "Hello Blog", - "items": [ - { - "id": "https://docusaurus.io/myBaseUrl/blog/blog-with-links", - "content_html": "

    absolute full url

    /n

    absolute pathname

    /n

    relative pathname

    /n

    md link

    /n

    anchor

    /n

    relative pathname + anchor

    /n

    /n

    \\"\\"

    /n/n", - "url": "https://docusaurus.io/myBaseUrl/blog/blog-with-links", - "title": "test links", - "summary": "absolute full url", - "date_modified": "2023-07-23T00:00:00.000Z", - "tags": [] - }, - { - "id": "https://docusaurus.io/myBaseUrl/blog/mdx-require-blog-post", - "content_html": "

    Test MDX with require calls

    /n/n/n/n/n", - "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", - "tags": [] - }, - { - "id": "https://docusaurus.io/myBaseUrl/blog/mdx-blog-post", - "content_html": "

    HTML Heading 1

    /n

    HTML Heading 2

    /n

    HTML Paragraph

    /n/n/n

    Import DOM

    /n

    Heading 1

    /n

    Heading 2

    /n

    Heading 3

    /n

    Heading 4

    /n
    Heading 5
    /n
      /n
    • list1
    • /n
    • list2
    • /n
    • list3
    • /n
    /n
      /n
    • list1
    • /n
    • list2
    • /n
    • list3
    • /n
    /n

    Normal Text Italics Text Bold Text

    /n

    link \\"image\\"

    ", - "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", - "tags": [] - }, - { - "id": "https://docusaurus.io/myBaseUrl/blog/hey/my super path/héllô", - "content_html": "

    complex url slug

    ", - "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", - "tags": [ - "date", - "complex" - ] - }, - { - "id": "https://docusaurus.io/myBaseUrl/blog/simple/slug", - "content_html": "

    simple url slug

    ", - "url": "https://docusaurus.io/myBaseUrl/blog/simple/slug", - "title": "Simple Slug", - "summary": "simple url slug", - "date_modified": "2020-08-15T00:00:00.000Z", - "author": { - "name": "Sébastien Lorber", - "url": "https://sebastienlorber.com" - }, - "tags": [] - }, - { - "id": "https://docusaurus.io/myBaseUrl/blog/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", - "tags": [] - }, - { - "id": "https://docusaurus.io/myBaseUrl/blog/date-matter", - "content_html": "

    date inside front matter

    ", - "url": "https://docusaurus.io/myBaseUrl/blog/date-matter", - "title": "date-matter", - "summary": "date inside front matter", - "date_modified": "2019-01-01T00:00:00.000Z", - "tags": [ - "date" - ] - }, - { - "id": "https://docusaurus.io/myBaseUrl/blog/2018/12/14/Happy-First-Birthday-Slash", - "content_html": "

    Happy birthday! (translated)

    ", - "url": "https://docusaurus.io/myBaseUrl/blog/2018/12/14/Happy-First-Birthday-Slash", - "title": "Happy 1st Birthday Slash! (translated)", - "summary": "Happy birthday! (translated)", - "date_modified": "2018-12-14T00:00:00.000Z", - "author": { - "name": "Yangshun Tay (translated)" - }, - "tags": [ - "inlineTag", - "Global Tag label (en)" - ] - } - ] -}", -] -`; - -exports[`json has xslt files for feed 1`] = ` +exports[`json has xslt files for feed 1`] = ` [ "{ "version": "https://jsonfeed.org/version/1", @@ -1741,182 +1239,60 @@ exports[`rss filters to the first two entries 1`] = ` https://docusaurus.io/myBaseUrl/blog/mdx-require-blog-post Sat, 06 Mar 2021 00:00:00 GMT - Test MDX with require calls

    - - - - -]]>
    - - -", -] -`; - -exports[`rss filters to the first two entries using limit 1`] = ` -[ - " - - - Hello Blog - https://docusaurus.io/myBaseUrl/blog - Hello Blog - Sun, 23 Jul 2023 00:00:00 GMT - https://validator.w3.org/feed/docs/rss2.html - https://github.com/jpmonette/feed - en - Copyright - - <![CDATA[test links]]> - https://docusaurus.io/myBaseUrl/blog/blog-with-links - https://docusaurus.io/myBaseUrl/blog/blog-with-links - Sun, 23 Jul 2023 00:00:00 GMT - - absolute full url

    -

    absolute pathname

    -

    relative pathname

    -

    md link

    -

    anchor

    -

    relative pathname + anchor

    -

    -

    - -]]>
    -
    - - <![CDATA[MDX Blog Sample with require calls]]> - https://docusaurus.io/myBaseUrl/blog/mdx-require-blog-post - https://docusaurus.io/myBaseUrl/blog/mdx-require-blog-post - Sat, 06 Mar 2021 00:00:00 GMT - - Test MDX with require calls

    - - - - -]]>
    -
    -
    -
    ", -] -`; - -exports[`rss has feed item for each post - with trailing slash 1`] = ` -[ - " - - - Hello Blog - https://docusaurus.io/myBaseUrl/blog/ - Hello Blog - Sun, 23 Jul 2023 00:00:00 GMT - https://validator.w3.org/feed/docs/rss2.html - https://github.com/jpmonette/feed - en - Copyright - - <![CDATA[test links]]> - https://docusaurus.io/myBaseUrl/blog/blog-with-links/ - https://docusaurus.io/myBaseUrl/blog/blog-with-links/ - Sun, 23 Jul 2023 00:00:00 GMT - - absolute full url

    -

    absolute pathname

    -

    relative pathname

    -

    md link

    -

    anchor

    -

    relative pathname + anchor

    -

    -

    - -]]>
    -
    - - <![CDATA[MDX Blog Sample with require calls]]> - https://docusaurus.io/myBaseUrl/blog/mdx-require-blog-post/ - https://docusaurus.io/myBaseUrl/blog/mdx-require-blog-post/ - Sat, 06 Mar 2021 00:00:00 GMT - - Test MDX with require calls

    - - - - -]]>
    -
    - - <![CDATA[Full Blog Sample]]> - https://docusaurus.io/myBaseUrl/blog/mdx-blog-post/ - https://docusaurus.io/myBaseUrl/blog/mdx-blog-post/ - Fri, 05 Mar 2021 00:00:00 GMT - - HTML Heading 1 -

    HTML Heading 2

    -

    HTML Paragraph

    - - -

    Import DOM

    -

    Heading 1

    -

    Heading 2

    -

    Heading 3

    -

    Heading 4

    -
    Heading 5
    -
      -
    • list1
    • -
    • list2
    • -
    • list3
    • -
    -
      -
    • list1
    • -
    • list2
    • -
    • list3
    • -
    -

    Normal Text Italics Text Bold Text

    -

    link image

    ]]>
    -
    - - <![CDATA[Complex Slug]]> - https://docusaurus.io/myBaseUrl/blog/hey/my super path/héllô/ - https://docusaurus.io/myBaseUrl/blog/hey/my super path/héllô/ - Sun, 16 Aug 2020 00:00:00 GMT - - complex url slug

    ]]>
    - date - complex -
    - - <![CDATA[Simple Slug]]> - https://docusaurus.io/myBaseUrl/blog/simple/slug/ - https://docusaurus.io/myBaseUrl/blog/simple/slug/ - Sat, 15 Aug 2020 00:00:00 GMT - - simple url slug

    ]]>
    -
    - - <![CDATA[some heading]]> - https://docusaurus.io/myBaseUrl/blog/heading-as-title/ - https://docusaurus.io/myBaseUrl/blog/heading-as-title/ - Wed, 02 Jan 2019 00:00:00 GMT + Test MDX with require calls

    + + + + +]]>
    +
    +
    ", +] +`; + +exports[`rss filters to the first two entries using limit 1`] = ` +[ + " + + + Hello Blog + https://docusaurus.io/myBaseUrl/blog + Hello Blog + Sun, 23 Jul 2023 00:00:00 GMT + https://validator.w3.org/feed/docs/rss2.html + https://github.com/jpmonette/feed + en + Copyright - <![CDATA[date-matter]]> - https://docusaurus.io/myBaseUrl/blog/date-matter/ - https://docusaurus.io/myBaseUrl/blog/date-matter/ - Tue, 01 Jan 2019 00:00:00 GMT - - date inside front matter

    ]]>
    - date + <![CDATA[test links]]> + https://docusaurus.io/myBaseUrl/blog/blog-with-links + https://docusaurus.io/myBaseUrl/blog/blog-with-links + Sun, 23 Jul 2023 00:00:00 GMT + + absolute full url

    +

    absolute pathname

    +

    relative pathname

    +

    md link

    +

    anchor

    +

    relative pathname + anchor

    +

    +

    + +]]>
    - <![CDATA[Happy 1st Birthday Slash! (translated)]]> - https://docusaurus.io/myBaseUrl/blog/2018/12/14/Happy-First-Birthday-Slash/ - https://docusaurus.io/myBaseUrl/blog/2018/12/14/Happy-First-Birthday-Slash/ - Fri, 14 Dec 2018 00:00:00 GMT - - Happy birthday! (translated)

    ]]>
    - lorber.sebastien@gmail.com (Sébastien Lorber (translated)) - inlineTag - Global Tag label (en) + <![CDATA[MDX Blog Sample with require calls]]> + https://docusaurus.io/myBaseUrl/blog/mdx-require-blog-post + https://docusaurus.io/myBaseUrl/blog/mdx-require-blog-post + Sat, 06 Mar 2021 00:00:00 GMT + + Test MDX with require calls

    + + + + +]]>
    ", @@ -2182,151 +1558,13 @@ h2:not(:first-child) { ] `; -exports[`rss has feed item for each post 1`] = ` +exports[`rss has feed item for each post - with trailing slash 1`] = ` [ - " - - - - - - - - Atom Feed | <xsl:value-of select="atom:feed/atom:title" /> - - - -
    -
    -
    - This is an Atom feed. Subscribe by copying the URL from the address - bar into your newsreader. Visit About Feeds to learn more - and get started. It’s free.
    -

    -
    - - - - - - - - - - -
    - Atom Feed Preview

    -

    - -

    -

    Description:

    -
    -

    Recent Posts

    -
    - -
    - - - -
    Published on -
    -
    - -
    -
    -
    -
    -
    - - -
    - -
    ", - "/** - * 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. - */ - -main { - flex: 1 0 auto; - width: 100%; - margin: 4rem auto; - padding: 1.5 rem; - max-width: 800px; - /* stylelint-disable-next-line font-family-name-quotes */ - font-family: system-ui, -apple-system, Segoe UI, Roboto, Ubuntu, Cantarell; -} - -.info { - display: block; - margin: 3rem 0; - padding: 2rem 3rem; - border: 1px solid dodgerblue; - border-left-width: 0.5rem; - border-radius: 0.4rem; - background-color: #edf5ff; -} - -.rss-icon { - height: 3.8rem; - width: 3.8rem; - margin-right: 1rem; -} - -.flex { - display: flex; -} - -.items-start { - align-items: flex-start; -} - -.pb-7 { - padding-bottom: 3rem; -} - -a { - color: #005aff; - text-decoration: none; -} - -h1 { - text-wrap: balance; - font-size: 3.8rem; - line-height: 1; - font-weight: 800; - margin-bottom: 4rem; -} - -h2 { - font-size: 3rem; - line-height: 1.2; - font-weight: 700; - margin-bottom: 3rem; -} - -h2:not(:first-child) { - margin-top: 5.8rem; -} - -.italic { - font-style: italic; -} -", " Hello Blog - https://docusaurus.io/myBaseUrl/blog + https://docusaurus.io/myBaseUrl/blog/ Hello Blog Sun, 23 Jul 2023 00:00:00 GMT https://validator.w3.org/feed/docs/rss2.html @@ -2335,15 +1573,15 @@ h2:not(:first-child) { Copyright <![CDATA[test links]]> - https://docusaurus.io/myBaseUrl/blog/blog-with-links - https://docusaurus.io/myBaseUrl/blog/blog-with-links + https://docusaurus.io/myBaseUrl/blog/blog-with-links/ + https://docusaurus.io/myBaseUrl/blog/blog-with-links/ Sun, 23 Jul 2023 00:00:00 GMT absolute full url

    absolute pathname

    relative pathname

    md link

    -

    anchor

    +

    anchor

    relative pathname + anchor

    @@ -2352,8 +1590,8 @@ h2:not(:first-child) {
    <![CDATA[MDX Blog Sample with require calls]]> - https://docusaurus.io/myBaseUrl/blog/mdx-require-blog-post - https://docusaurus.io/myBaseUrl/blog/mdx-require-blog-post + https://docusaurus.io/myBaseUrl/blog/mdx-require-blog-post/ + https://docusaurus.io/myBaseUrl/blog/mdx-require-blog-post/ Sat, 06 Mar 2021 00:00:00 GMT Test MDX with require calls

    @@ -2365,8 +1603,8 @@ h2:not(:first-child) {
    <![CDATA[Full Blog Sample]]> - https://docusaurus.io/myBaseUrl/blog/mdx-blog-post - https://docusaurus.io/myBaseUrl/blog/mdx-blog-post + https://docusaurus.io/myBaseUrl/blog/mdx-blog-post/ + https://docusaurus.io/myBaseUrl/blog/mdx-blog-post/ Fri, 05 Mar 2021 00:00:00 GMT HTML Heading 1 @@ -2376,10 +1614,10 @@ h2:not(:first-child) {

    Import DOM

    Heading 1

    -

    Heading 2

    -

    Heading 3

    -

    Heading 4

    -
    Heading 5
    +

    Heading 2

    +

    Heading 3

    +

    Heading 4

    +
    Heading 5
    • list1
    • list2
    • @@ -2395,8 +1633,8 @@ h2:not(:first-child) { <![CDATA[Complex Slug]]> - https://docusaurus.io/myBaseUrl/blog/hey/my super path/héllô - https://docusaurus.io/myBaseUrl/blog/hey/my super path/héllô + https://docusaurus.io/myBaseUrl/blog/hey/my super path/héllô/ + https://docusaurus.io/myBaseUrl/blog/hey/my super path/héllô/ Sun, 16 Aug 2020 00:00:00 GMT complex url slug

      ]]>
      @@ -2405,22 +1643,22 @@ h2:not(:first-child) {
      <![CDATA[Simple Slug]]> - https://docusaurus.io/myBaseUrl/blog/simple/slug - https://docusaurus.io/myBaseUrl/blog/simple/slug + https://docusaurus.io/myBaseUrl/blog/simple/slug/ + https://docusaurus.io/myBaseUrl/blog/simple/slug/ Sat, 15 Aug 2020 00:00:00 GMT simple url slug

      ]]>
      <![CDATA[some heading]]> - https://docusaurus.io/myBaseUrl/blog/heading-as-title - https://docusaurus.io/myBaseUrl/blog/heading-as-title + https://docusaurus.io/myBaseUrl/blog/heading-as-title/ + https://docusaurus.io/myBaseUrl/blog/heading-as-title/ Wed, 02 Jan 2019 00:00:00 GMT <![CDATA[date-matter]]> - https://docusaurus.io/myBaseUrl/blog/date-matter - https://docusaurus.io/myBaseUrl/blog/date-matter + https://docusaurus.io/myBaseUrl/blog/date-matter/ + https://docusaurus.io/myBaseUrl/blog/date-matter/ Tue, 01 Jan 2019 00:00:00 GMT date inside front matter

      ]]>
      @@ -2428,21 +1666,23 @@ h2:not(:first-child) {
      <![CDATA[Happy 1st Birthday Slash! (translated)]]> - https://docusaurus.io/myBaseUrl/blog/2018/12/14/Happy-First-Birthday-Slash - https://docusaurus.io/myBaseUrl/blog/2018/12/14/Happy-First-Birthday-Slash + https://docusaurus.io/myBaseUrl/blog/2018/12/14/Happy-First-Birthday-Slash/ + https://docusaurus.io/myBaseUrl/blog/2018/12/14/Happy-First-Birthday-Slash/ Fri, 14 Dec 2018 00:00:00 GMT Happy birthday! (translated)

      ]]>
      lorber.sebastien@gmail.com (Sébastien Lorber (translated)) + inlineTag + Global Tag label (en)
      ", ] `; -exports[`rss has xslt files for feed 1`] = ` +exports[`rss has feed item for each post 1`] = ` [ - " + " Hello Blog diff --git a/packages/docusaurus-plugin-content-blog/src/__tests__/feed.test.ts b/packages/docusaurus-plugin-content-blog/src/__tests__/feed.test.ts index 6fe86b7b2187..608078c637f8 100644 --- a/packages/docusaurus-plugin-content-blog/src/__tests__/feed.test.ts +++ b/packages/docusaurus-plugin-content-blog/src/__tests__/feed.test.ts @@ -51,11 +51,8 @@ async function testGenerateFeeds( context: LoadContext, options: PluginOptions, ): Promise { - const blogPosts = await generateBlogPosts( - getBlogContentPaths(context.siteDir), - context, - options, - ); + const contentPaths = getBlogContentPaths(context.siteDir); + const blogPosts = await generateBlogPosts(contentPaths, context, options); await createBlogFeedFiles({ blogPosts, @@ -63,6 +60,7 @@ async function testGenerateFeeds( siteConfig: context.siteConfig, outDir: context.outDir, locale: 'en', + contentPaths, }); } @@ -330,9 +328,7 @@ describe.each(['atom', 'rss', 'json'])('%s', (feedType) => { feedOptions: { type: [feedType], copyright: 'Copyright', - xsl: { - enable: true, - }, + xslt: true, }, readingTime: ({content, defaultReadingTime}) => defaultReadingTime({content}), @@ -375,11 +371,9 @@ describe.each(['atom', 'rss', 'json'])('%s', (feedType) => { feedOptions: { type: [feedType], copyright: 'Copyright', - xsl: { - enable: true, - rssStylesheet: 'custom-rss.stylesheet.xsl', - atomStylesheet: 'custom-atom.stylesheet.xsl', - }, + xslt: true, + rssXslt: 'custom-rss.stylesheet.xsl', + atomXslt: 'custom-atom.stylesheet.xsl', }, readingTime: ({content, defaultReadingTime}) => defaultReadingTime({content}), diff --git a/packages/docusaurus-plugin-content-blog/src/__tests__/options.test.ts b/packages/docusaurus-plugin-content-blog/src/__tests__/options.test.ts index 050e2a016023..b27c7d8ede20 100644 --- a/packages/docusaurus-plugin-content-blog/src/__tests__/options.test.ts +++ b/packages/docusaurus-plugin-content-blog/src/__tests__/options.test.ts @@ -38,7 +38,13 @@ describe('validateOptions', () => { it('accepts correctly defined user options', () => { const userOptions: Options = { ...defaultOptions, - feedOptions: {type: 'rss' as const, title: 'myTitle'}, + feedOptions: { + type: 'rss' as const, + title: 'myTitle', + xslt: false, + atomXslt: 'atom.xslt', + rssXslt: 'rss.xslt', + }, path: 'not_blog', routeBasePath: '/myBlog', postsPerPage: 5, @@ -48,7 +54,15 @@ describe('validateOptions', () => { }; expect(testValidate(userOptions)).toEqual({ ...userOptions, - feedOptions: {type: ['rss'], title: 'myTitle', copyright: '', limit: 20}, + feedOptions: { + type: ['rss'], + title: 'myTitle', + copyright: '', + limit: 20, + xslt: false, + atomXslt: 'atom.xslt', + rssXslt: 'rss.xslt', + }, }); }); @@ -108,7 +122,13 @@ describe('validateOptions', () => { }), ).toEqual({ ...defaultOptions, - feedOptions: {type: null, limit: 20}, + feedOptions: { + type: null, + limit: 20, + xslt: false, + rssXslt: 'rss.xslt', + atomXslt: 'atom.xslt', + }, }); }); @@ -132,6 +152,9 @@ describe('validateOptions', () => { title: 'title', copyright: '', limit: 20, + xslt: false, + rssXslt: 'rss.xslt', + atomXslt: 'atom.xslt', }, }); }); From 76d198b90134209df773a714f2d052f23296b6d3 Mon Sep 17 00:00:00 2001 From: ozakione <29860391+OzakIOne@users.noreply.github.com> Date: Fri, 26 Jul 2024 18:23:14 +0200 Subject: [PATCH 11/36] fix custom test --- .../__fixtures__/website/blog/custom-atom.css | 76 ++++++ .../website/blog/custom-atom.xslt | 65 +++++ .../__fixtures__/website/blog/custom-rss.css | 76 ++++++ .../__fixtures__/website/blog/custom-rss.xslt | 65 +++++ .../__tests__/__snapshots__/feed.test.ts.snap | 227 +++++++++++++++--- .../src/__tests__/feed.test.ts | 18 +- 6 files changed, 487 insertions(+), 40 deletions(-) create mode 100644 packages/docusaurus-plugin-content-blog/src/__tests__/__fixtures__/website/blog/custom-atom.css create mode 100644 packages/docusaurus-plugin-content-blog/src/__tests__/__fixtures__/website/blog/custom-atom.xslt create mode 100644 packages/docusaurus-plugin-content-blog/src/__tests__/__fixtures__/website/blog/custom-rss.css create mode 100644 packages/docusaurus-plugin-content-blog/src/__tests__/__fixtures__/website/blog/custom-rss.xslt diff --git a/packages/docusaurus-plugin-content-blog/src/__tests__/__fixtures__/website/blog/custom-atom.css b/packages/docusaurus-plugin-content-blog/src/__tests__/__fixtures__/website/blog/custom-atom.css new file mode 100644 index 000000000000..c016178d9007 --- /dev/null +++ b/packages/docusaurus-plugin-content-blog/src/__tests__/__fixtures__/website/blog/custom-atom.css @@ -0,0 +1,76 @@ +/** + * 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. + */ + +* { + color: #0d1137; +} + +main { + flex: 1 0 auto; + width: 100%; + margin: 4rem auto; + padding: 1.5 rem; + max-width: 800px; + /* stylelint-disable-next-line font-family-name-quotes */ + font-family: system-ui, -apple-system, Segoe UI, Roboto, Ubuntu, Cantarell; +} + +.info { + display: block; + margin: 3rem 0; + padding: 2rem 3rem; + border: 1px solid dodgerblue; + border-left-width: 0.5rem; + border-radius: 0.4rem; + background-color: #e52165; +} + +.rss-icon { + height: 3.8rem; + width: 3.8rem; + margin-right: 1rem; +} + +.flex { + display: flex; +} + +.items-start { + align-items: flex-start; +} + +.pb-7 { + padding-bottom: 3rem; +} + +a { + color: #005aff; + text-decoration: none; +} + +h1 { + text-wrap: balance; + font-size: 3.8rem; + line-height: 1; + font-weight: 800; + margin-bottom: 4rem; +} + +h2 { + font-size: 3rem; + line-height: 1.2; + font-weight: 700; + margin-bottom: 3rem; +} + +h2:not(:first-child) { + margin-top: 5.8rem; +} + +.italic { + font-style: italic; +} diff --git a/packages/docusaurus-plugin-content-blog/src/__tests__/__fixtures__/website/blog/custom-atom.xslt b/packages/docusaurus-plugin-content-blog/src/__tests__/__fixtures__/website/blog/custom-atom.xslt new file mode 100644 index 000000000000..80406b153124 --- /dev/null +++ b/packages/docusaurus-plugin-content-blog/src/__tests__/__fixtures__/website/blog/custom-atom.xslt @@ -0,0 +1,65 @@ + + + + + + + + + Atom Feed | <xsl:value-of select="atom:feed/atom:title" /> + + + +
      +
      +
      + This is an Atom feed. Subscribe by copying the URL from the address + bar into your newsreader. Visit About Feeds to learn more + and get started. It’s free.
      +

      +
      + + + + + + + + + + +
      + Custom Atom Feed Preview

      +

      + +

      +

      Description:

      +
      +

      Recent Posts

      +
      + +
      + + + +
      Published on +
      +
      + +
      +
      +
      +
      +
      + + +
      + +
      diff --git a/packages/docusaurus-plugin-content-blog/src/__tests__/__fixtures__/website/blog/custom-rss.css b/packages/docusaurus-plugin-content-blog/src/__tests__/__fixtures__/website/blog/custom-rss.css new file mode 100644 index 000000000000..c016178d9007 --- /dev/null +++ b/packages/docusaurus-plugin-content-blog/src/__tests__/__fixtures__/website/blog/custom-rss.css @@ -0,0 +1,76 @@ +/** + * 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. + */ + +* { + color: #0d1137; +} + +main { + flex: 1 0 auto; + width: 100%; + margin: 4rem auto; + padding: 1.5 rem; + max-width: 800px; + /* stylelint-disable-next-line font-family-name-quotes */ + font-family: system-ui, -apple-system, Segoe UI, Roboto, Ubuntu, Cantarell; +} + +.info { + display: block; + margin: 3rem 0; + padding: 2rem 3rem; + border: 1px solid dodgerblue; + border-left-width: 0.5rem; + border-radius: 0.4rem; + background-color: #e52165; +} + +.rss-icon { + height: 3.8rem; + width: 3.8rem; + margin-right: 1rem; +} + +.flex { + display: flex; +} + +.items-start { + align-items: flex-start; +} + +.pb-7 { + padding-bottom: 3rem; +} + +a { + color: #005aff; + text-decoration: none; +} + +h1 { + text-wrap: balance; + font-size: 3.8rem; + line-height: 1; + font-weight: 800; + margin-bottom: 4rem; +} + +h2 { + font-size: 3rem; + line-height: 1.2; + font-weight: 700; + margin-bottom: 3rem; +} + +h2:not(:first-child) { + margin-top: 5.8rem; +} + +.italic { + font-style: italic; +} diff --git a/packages/docusaurus-plugin-content-blog/src/__tests__/__fixtures__/website/blog/custom-rss.xslt b/packages/docusaurus-plugin-content-blog/src/__tests__/__fixtures__/website/blog/custom-rss.xslt new file mode 100644 index 000000000000..c258f34d5a42 --- /dev/null +++ b/packages/docusaurus-plugin-content-blog/src/__tests__/__fixtures__/website/blog/custom-rss.xslt @@ -0,0 +1,65 @@ + + + + + + + + + Atom Feed | <xsl:value-of select="atom:feed/atom:title" /> + + + +
      +
      +
      + This is an Atom feed. Subscribe by copying the URL from the address + bar into your newsreader. Visit About Feeds to learn more + and get started. It’s free.
      +

      +
      + + + + + + + + + + +
      + Custom Atom Feed Preview

      +

      + +

      +

      Description:

      +
      +

      Recent Posts

      +
      + +
      + + + +
      Published on +
      +
      + +
      +
      +
      +
      +
      + + +
      + +
      diff --git a/packages/docusaurus-plugin-content-blog/src/__tests__/__snapshots__/feed.test.ts.snap b/packages/docusaurus-plugin-content-blog/src/__tests__/__snapshots__/feed.test.ts.snap index 9e6fb76e6b71..92390ff1a966 100644 --- a/packages/docusaurus-plugin-content-blog/src/__tests__/__snapshots__/feed.test.ts.snap +++ b/packages/docusaurus-plugin-content-blog/src/__tests__/__snapshots__/feed.test.ts.snap @@ -104,7 +104,7 @@ exports[`atom has custom xslt files for feed 1`] = ` Atom Feed | <xsl:value-of select="atom:feed/atom:title" /> - +
      @@ -131,7 +131,7 @@ exports[`atom has custom xslt files for feed 1`] = ` - Atom Feed Preview + Custom Atom Feed Preview

      @@ -158,7 +158,8 @@ exports[`atom has custom xslt files for feed 1`] = ` -", + +", "/** * Copyright (c) Facebook, Inc. and its affiliates. * @@ -166,6 +167,10 @@ exports[`atom has custom xslt files for feed 1`] = ` * LICENSE file in the root directory of this source tree. */ +* { + color: #0d1137; +} + main { flex: 1 0 auto; width: 100%; @@ -183,7 +188,7 @@ main { border: 1px solid dodgerblue; border-left-width: 0.5rem; border-radius: 0.4rem; - background-color: #edf5ff; + background-color: #e52165; } .rss-icon { @@ -232,7 +237,7 @@ h2:not(:first-child) { font-style: italic; } ", - " + " https://docusaurus.io/myBaseUrl/blog Hello Blog @@ -353,6 +358,8 @@ h2:not(:first-child) { Sébastien Lorber (translated) lorber.sebastien@gmail.com + + ", ] @@ -812,6 +819,149 @@ exports[`json filters to the first two entries using limit 1`] = ` exports[`json has custom xslt files for feed 1`] = ` [ + " + + + + + + + + Atom Feed | <xsl:value-of select="atom:feed/atom:title" /> + + + +
      +
      +
      + This is an Atom feed. Subscribe by copying the URL from the address + bar into your newsreader. Visit About Feeds to learn more + and get started. It’s free.
      +

      +
      + + + + + + + + + + +
      + Custom Atom Feed Preview

      +

      + +

      +

      Description:

      +
      +

      Recent Posts

      +
      + +
      + + + +
      Published on +
      +
      + +
      +
      +
      +
      +
      + + +
      + +
      +", + "/** + * 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. + */ + +* { + color: #0d1137; +} + +main { + flex: 1 0 auto; + width: 100%; + margin: 4rem auto; + padding: 1.5 rem; + max-width: 800px; + /* stylelint-disable-next-line font-family-name-quotes */ + font-family: system-ui, -apple-system, Segoe UI, Roboto, Ubuntu, Cantarell; +} + +.info { + display: block; + margin: 3rem 0; + padding: 2rem 3rem; + border: 1px solid dodgerblue; + border-left-width: 0.5rem; + border-radius: 0.4rem; + background-color: #e52165; +} + +.rss-icon { + height: 3.8rem; + width: 3.8rem; + margin-right: 1rem; +} + +.flex { + display: flex; +} + +.items-start { + align-items: flex-start; +} + +.pb-7 { + padding-bottom: 3rem; +} + +a { + color: #005aff; + text-decoration: none; +} + +h1 { + text-wrap: balance; + font-size: 3.8rem; + line-height: 1; + font-weight: 800; + margin-bottom: 4rem; +} + +h2 { + font-size: 3rem; + line-height: 1.2; + font-weight: 700; + margin-bottom: 3rem; +} + +h2:not(:first-child) { + margin-top: 5.8rem; +} + +.italic { + font-style: italic; +} +", "{ "version": "https://jsonfeed.org/version/1", "title": "Hello Blog", @@ -899,7 +1049,10 @@ exports[`json has custom xslt files for feed 1`] = ` "author": { "name": "Yangshun Tay (translated)" }, - "tags": [] + "tags": [ + "inlineTag", + "Global Tag label (en)" + ] } ] }", @@ -1307,17 +1460,17 @@ exports[`rss has custom xslt files for feed 1`] = ` - + - RSS Feed | <xsl:value-of select="rss/channel/title" /> - + Atom Feed | <xsl:value-of select="atom:feed/atom:title" /> +
      - This is an RSS feed. Subscribe by copying the URL from the address + This is an Atom feed. Subscribe by copying the URL from the address bar into your newsreader. Visit About Feeds to learn more and get started. It’s free.

      @@ -1325,38 +1478,37 @@ exports[`rss has custom xslt files for feed 1`] = ` - - - - - - - - - + + + + + + + + +

      - RSS Feed Preview + Custom Atom Feed Preview

      - +

      -

      Description:

      +

      Description:

      Recent Posts

      - +
      - - + +
      Published on + select="substring(atom:updated, 0, 17)" />
      - +
      @@ -1366,7 +1518,8 @@ exports[`rss has custom xslt files for feed 1`] = ` -", + +", "/** * Copyright (c) Facebook, Inc. and its affiliates. * @@ -1374,6 +1527,10 @@ exports[`rss has custom xslt files for feed 1`] = ` * LICENSE file in the root directory of this source tree. */ +* { + color: #0d1137; +} + main { flex: 1 0 auto; width: 100%; @@ -1391,7 +1548,7 @@ main { border: 1px solid dodgerblue; border-left-width: 0.5rem; border-radius: 0.4rem; - background-color: #edf5ff; + background-color: #e52165; } .rss-icon { @@ -1440,7 +1597,7 @@ h2:not(:first-child) { font-style: italic; } ", - " + " Hello Blog @@ -1552,6 +1709,8 @@ h2:not(:first-child) { Happy birthday! (translated)

      ]]>
      lorber.sebastien@gmail.com (Sébastien Lorber (translated)) + inlineTag + Global Tag label (en)
      ", diff --git a/packages/docusaurus-plugin-content-blog/src/__tests__/feed.test.ts b/packages/docusaurus-plugin-content-blog/src/__tests__/feed.test.ts index 608078c637f8..6ef2f9e14334 100644 --- a/packages/docusaurus-plugin-content-blog/src/__tests__/feed.test.ts +++ b/packages/docusaurus-plugin-content-blog/src/__tests__/feed.test.ts @@ -307,17 +307,18 @@ describe.each(['atom', 'rss', 'json'])('%s', (feedType) => { baseUrl: '/myBaseUrl/', url: 'https://docusaurus.io', favicon: 'image/favicon.ico', + markdown, }; // Build is quite difficult to mock, so we built the blog beforehand and // copied the output to the fixture... await testGenerateFeeds( - { + fromPartial({ siteDir, siteConfig, i18n: DefaultI18N, outDir, - } as LoadContext, + }), { path: 'blog', routeBasePath: 'blog', @@ -333,6 +334,8 @@ describe.each(['atom', 'rss', 'json'])('%s', (feedType) => { readingTime: ({content, defaultReadingTime}) => defaultReadingTime({content}), truncateMarker: //, + onInlineTags: 'ignore', + onInlineAuthors: 'ignore', } as PluginOptions, ); @@ -350,17 +353,18 @@ describe.each(['atom', 'rss', 'json'])('%s', (feedType) => { baseUrl: '/myBaseUrl/', url: 'https://docusaurus.io', favicon: 'image/favicon.ico', + markdown, }; // Build is quite difficult to mock, so we built the blog beforehand and // copied the output to the fixture... await testGenerateFeeds( - { + fromPartial({ siteDir, siteConfig, i18n: DefaultI18N, outDir, - } as LoadContext, + }), { path: 'blog', routeBasePath: 'blog', @@ -372,12 +376,14 @@ describe.each(['atom', 'rss', 'json'])('%s', (feedType) => { type: [feedType], copyright: 'Copyright', xslt: true, - rssXslt: 'custom-rss.stylesheet.xsl', - atomXslt: 'custom-atom.stylesheet.xsl', + rssXslt: 'custom-rss.xslt', + atomXslt: 'custom-atom.xslt', }, readingTime: ({content, defaultReadingTime}) => defaultReadingTime({content}), truncateMarker: //, + onInlineTags: 'ignore', + onInlineAuthors: 'ignore', } as PluginOptions, ); From d59b38c9d153899c0b1b3be6c97458a832438fca Mon Sep 17 00:00:00 2001 From: ozakione <29860391+OzakIOne@users.noreply.github.com> Date: Fri, 26 Jul 2024 18:30:31 +0200 Subject: [PATCH 12/36] fix test --- .../src/__tests__/options.test.ts | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/packages/docusaurus-plugin-content-blog/src/__tests__/options.test.ts b/packages/docusaurus-plugin-content-blog/src/__tests__/options.test.ts index b27c7d8ede20..52f60e4e056a 100644 --- a/packages/docusaurus-plugin-content-blog/src/__tests__/options.test.ts +++ b/packages/docusaurus-plugin-content-blog/src/__tests__/options.test.ts @@ -111,7 +111,14 @@ describe('validateOptions', () => { }), ).toEqual({ ...defaultOptions, - feedOptions: {type: ['rss', 'atom', 'json'], copyright: '', limit: 20}, + feedOptions: { + type: ['rss', 'atom', 'json'], + copyright: '', + limit: 20, + xslt: false, + rssXslt: 'rss.xslt', + atomXslt: 'atom.xslt', + }, }); }); From 268906aee3b3137b596b76df082f7378b7836f2f Mon Sep 17 00:00:00 2001 From: ozakione <29860391+OzakIOne@users.noreply.github.com> Date: Fri, 26 Jul 2024 18:34:43 +0200 Subject: [PATCH 13/36] fix test --- .../__tests__/__snapshots__/feed.test.ts.snap | 427 +++++++++++++++++- .../src/__tests__/feed.test.ts | 2 + 2 files changed, 427 insertions(+), 2 deletions(-) diff --git a/packages/docusaurus-plugin-content-blog/src/__tests__/__snapshots__/feed.test.ts.snap b/packages/docusaurus-plugin-content-blog/src/__tests__/__snapshots__/feed.test.ts.snap index 92390ff1a966..de5e3b131595 100644 --- a/packages/docusaurus-plugin-content-blog/src/__tests__/__snapshots__/feed.test.ts.snap +++ b/packages/docusaurus-plugin-content-blog/src/__tests__/__snapshots__/feed.test.ts.snap @@ -627,7 +627,150 @@ exports[`atom has feed item for each post 1`] = ` exports[`atom has xslt files for feed 1`] = ` [ - " + " + + + + + + + + Atom Feed | <xsl:value-of select="atom:feed/atom:title" /> + + + +
      +
      +
      + This is an Atom feed. Subscribe by copying the URL from the address + bar into your newsreader. Visit About Feeds to learn more + and get started. It’s free.
      +

      +
      + + + + + + + + + + +
      + Custom Atom Feed Preview

      +

      + +

      +

      Description:

      +
      +

      Recent Posts

      +
      + +
      + + + +
      Published on +
      +
      + +
      +
      +
      +
      +
      + + +
      + +
      +", + "/** + * 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. + */ + +* { + color: #0d1137; +} + +main { + flex: 1 0 auto; + width: 100%; + margin: 4rem auto; + padding: 1.5 rem; + max-width: 800px; + /* stylelint-disable-next-line font-family-name-quotes */ + font-family: system-ui, -apple-system, Segoe UI, Roboto, Ubuntu, Cantarell; +} + +.info { + display: block; + margin: 3rem 0; + padding: 2rem 3rem; + border: 1px solid dodgerblue; + border-left-width: 0.5rem; + border-radius: 0.4rem; + background-color: #edf5ff; +} + +.rss-icon { + height: 3.8rem; + width: 3.8rem; + margin-right: 1rem; +} + +.flex { + display: flex; +} + +.items-start { + align-items: flex-start; +} + +.pb-7 { + padding-bottom: 3rem; +} + +a { + color: #005aff; + text-decoration: none; +} + +h1 { + text-wrap: balance; + font-size: 3.8rem; + line-height: 1; + font-weight: 800; + margin-bottom: 4rem; +} + +h2 { + font-size: 3rem; + line-height: 1.2; + font-weight: 700; + margin-bottom: 3rem; +} + +h2:not(:first-child) { + margin-top: 5.8rem; +} + +.italic { + font-style: italic; +} +", + " https://docusaurus.io/myBaseUrl/blog Hello Blog @@ -1259,6 +1402,146 @@ exports[`json has feed item for each post 1`] = ` exports[`json has xslt files for feed 1`] = ` [ + " + + + + + + + + RSS Feed | <xsl:value-of select="rss/channel/title" /> + + + +
      +
      +
      + This is an RSS feed. Subscribe by copying the URL from the address + bar into your newsreader. Visit About Feeds to learn more + and get started. It’s free.
      +

      +
      + + + + + + + + + + +
      + RSS Feed Preview

      +

      + +

      +

      Description:

      +
      +

      Recent Posts

      +
      + +
      + + + +
      Published on +
      +
      + +
      +
      +
      +
      +
      + + +
      + +
      +", + "/** + * 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. + */ + +main { + flex: 1 0 auto; + width: 100%; + margin: 4rem auto; + padding: 1.5 rem; + max-width: 800px; + /* stylelint-disable-next-line font-family-name-quotes */ + font-family: system-ui, -apple-system, Segoe UI, Roboto, Ubuntu, Cantarell; +} + +.info { + display: block; + margin: 3rem 0; + padding: 2rem 3rem; + border: 1px solid dodgerblue; + border-left-width: 0.5rem; + border-radius: 0.4rem; + background-color: #edf5ff; +} + +.rss-icon { + height: 3.8rem; + width: 3.8rem; + margin-right: 1rem; +} + +.flex { + display: flex; +} + +.items-start { + align-items: flex-start; +} + +.pb-7 { + padding-bottom: 3rem; +} + +a { + color: #005aff; + text-decoration: none; +} + +h1 { + text-wrap: balance; + font-size: 3.8rem; + line-height: 1; + font-weight: 800; + margin-bottom: 4rem; +} + +h2 { + font-size: 3rem; + line-height: 1.2; + font-weight: 700; + margin-bottom: 3rem; +} + +h2:not(:first-child) { + margin-top: 5.8rem; +} + +.italic { + font-style: italic; +} +", "{ "version": "https://jsonfeed.org/version/1", "title": "Hello Blog", @@ -1963,7 +2246,147 @@ exports[`rss has feed item for each post 1`] = ` exports[`rss has xslt files for feed 1`] = ` [ - " + " + + + + + + + + RSS Feed | <xsl:value-of select="rss/channel/title" /> + + + +
      +
      +
      + This is an RSS feed. Subscribe by copying the URL from the address + bar into your newsreader. Visit About Feeds to learn more + and get started. It’s free.
      +

      +
      + + + + + + + + + + +
      + RSS Feed Preview

      +

      + +

      +

      Description:

      +
      +

      Recent Posts

      +
      + +
      + + + +
      Published on +
      +
      + +
      +
      +
      +
      +
      + + +
      + +
      +", + "/** + * 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. + */ + +main { + flex: 1 0 auto; + width: 100%; + margin: 4rem auto; + padding: 1.5 rem; + max-width: 800px; + /* stylelint-disable-next-line font-family-name-quotes */ + font-family: system-ui, -apple-system, Segoe UI, Roboto, Ubuntu, Cantarell; +} + +.info { + display: block; + margin: 3rem 0; + padding: 2rem 3rem; + border: 1px solid dodgerblue; + border-left-width: 0.5rem; + border-radius: 0.4rem; + background-color: #edf5ff; +} + +.rss-icon { + height: 3.8rem; + width: 3.8rem; + margin-right: 1rem; +} + +.flex { + display: flex; +} + +.items-start { + align-items: flex-start; +} + +.pb-7 { + padding-bottom: 3rem; +} + +a { + color: #005aff; + text-decoration: none; +} + +h1 { + text-wrap: balance; + font-size: 3.8rem; + line-height: 1; + font-weight: 800; + margin-bottom: 4rem; +} + +h2 { + font-size: 3rem; + line-height: 1.2; + font-weight: 700; + margin-bottom: 3rem; +} + +h2:not(:first-child) { + margin-top: 5.8rem; +} + +.italic { + font-style: italic; +} +", + " Hello Blog diff --git a/packages/docusaurus-plugin-content-blog/src/__tests__/feed.test.ts b/packages/docusaurus-plugin-content-blog/src/__tests__/feed.test.ts index 6ef2f9e14334..3c9c1332b6fd 100644 --- a/packages/docusaurus-plugin-content-blog/src/__tests__/feed.test.ts +++ b/packages/docusaurus-plugin-content-blog/src/__tests__/feed.test.ts @@ -330,6 +330,8 @@ describe.each(['atom', 'rss', 'json'])('%s', (feedType) => { type: [feedType], copyright: 'Copyright', xslt: true, + rssXslt: 'rss.xslt', + atomXslt: 'atom.xslt', }, readingTime: ({content, defaultReadingTime}) => defaultReadingTime({content}), From be1f67cdf1c93a91e38f521e66fe0c074913e1b0 Mon Sep 17 00:00:00 2001 From: ozakione <29860391+OzakIOne@users.noreply.github.com> Date: Mon, 29 Jul 2024 15:38:45 +0200 Subject: [PATCH 14/36] feat: refactor in switch --- .../src/feed.ts | 90 +++++++++++-------- website/blog/custom-atom.css | 76 ---------------- website/blog/custom-atom.xslt | 65 -------------- website/blog/custom-rss.css | 76 ---------------- website/blog/custom-rss.xslt | 65 -------------- website/docusaurus.config.ts | 1 + 6 files changed, 53 insertions(+), 320 deletions(-) delete mode 100644 website/blog/custom-atom.css delete mode 100644 website/blog/custom-atom.xslt delete mode 100644 website/blog/custom-rss.css delete mode 100644 website/blog/custom-rss.xslt diff --git a/packages/docusaurus-plugin-content-blog/src/feed.ts b/packages/docusaurus-plugin-content-blog/src/feed.ts index 672a2d3c3928..268bdd5c9f86 100644 --- a/packages/docusaurus-plugin-content-blog/src/feed.ts +++ b/packages/docusaurus-plugin-content-blog/src/feed.ts @@ -183,51 +183,50 @@ async function defaultCreateFeedItems({ /** * @description addXmlStyleSheet appends a xsl stylesheet to the generated xml feed - * @param feedDetails array containing blog feed content and name of file + * @param feedDetails the feed content * @param generatePath path where the file would be copied in website + * @param xsltFile path to the xslt file + * @param contentPaths path to the content directory */ -async function addXmlStyleSheet({ +async function transformFeedWithStylesheet({ feedDetails, generatePath, - xslPath, - contentPaths, + xsltFile, + contentPaths: {contentPath}, }: { - feedDetails: string[]; + feedDetails: string; generatePath: string; - xslPath: string; + xsltFile: string; contentPaths: BlogContentPaths; }) { - if (!feedDetails[0]) { + // TODO idk why there is this check + if (!feedDetails) { return feedDetails; } - const {contentPath} = contentPaths; - const fileName = path.parse(xslPath).name; - const isDefault = xslPath === 'rss.xslt' || xslPath === 'atom.xslt'; + const fileName = path.parse(xsltFile).name; + const isDefault = xsltFile === 'rss.xslt' || xsltFile === 'atom.xslt'; const directoryPath = isDefault ? path.join(__dirname, '../assets/') : contentPath; - const xsltLink = ``; - feedDetails[0] = feedDetails[0]?.replace( + const xsltLink = ``; + const transformedFeed = feedDetails.replace( '', xsltLink, ); const xsltPath = path.join(directoryPath, `${fileName}.xslt`); - const cssPath = path.join(directoryPath, `${fileName}.css`); - const xsltGeneratePath = path.join(generatePath, `${fileName}.xslt`); - const cssGeneratePath = path.join(generatePath, `${fileName}.css`); - - // output xslt file to website const xsltContent = await fs.readFile(xsltPath, 'utf8'); + const xsltGeneratePath = path.join(generatePath, `${fileName}.xslt`); await fs.outputFile(xsltGeneratePath, xsltContent, 'utf-8'); - // output stylesheet to website + const cssPath = path.join(directoryPath, `${fileName}.css`); const stylesheetContent = await fs.readFile(cssPath, 'utf8'); + const cssGeneratePath = path.join(generatePath, `${fileName}.css`); await fs.outputFile(cssGeneratePath, stylesheetContent, 'utf-8'); - return feedDetails; + return transformedFeed; } async function createBlogFeedFile({ @@ -243,34 +242,49 @@ async function createBlogFeedFile({ feedOptions: FeedOptions; contentPaths: BlogContentPaths; }) { - let feedDetails = (() => { + const [feedContent, feedPath] = await (async () => { switch (feedType) { - case 'rss': - return [feed.rss2(), 'rss.xml']; + case 'rss': { + const rssFeed = feed.rss2(); + const outputPath = 'rss.xml'; + if (xslt) { + const xsltFeed = await transformFeedWithStylesheet({ + feedDetails: rssFeed, + generatePath, + xsltFile: rssXslt, + contentPaths, + }); + return [xsltFeed, outputPath]; + } + return [rssFeed, outputPath]; + } case 'json': return [feed.json1(), 'feed.json']; - case 'atom': - return [feed.atom1(), 'atom.xml']; + case 'atom': { + const atomFeed = feed.atom1(); + const outputPath = 'atom.xml'; + if (xslt) { + const xsltFeed = await transformFeedWithStylesheet({ + feedDetails: atomFeed, + generatePath, + xsltFile: atomXslt, + contentPaths, + }); + return [xsltFeed, outputPath]; + } + return [atomFeed, outputPath]; + } default: throw new Error(`Feed type ${feedType} not supported.`); } })(); - try { - if (xslt) { - feedDetails = await addXmlStyleSheet({ - feedDetails, - generatePath, - xslPath: feedDetails[1] === 'atom.xml' ? atomXslt : rssXslt, - contentPaths, - }); - } - await fs.outputFile( - path.join(generatePath, `${feedDetails[1]}`), - feedDetails[0], - ); + try { + await fs.outputFile(path.join(generatePath, feedPath), feedContent); } catch (err) { - throw new Error(`Error creating feed file: ${feedType}`, {cause: err}); + throw new Error(`Generating ${feedType} feed failed.`, { + cause: err as Error, + }); } } diff --git a/website/blog/custom-atom.css b/website/blog/custom-atom.css deleted file mode 100644 index c016178d9007..000000000000 --- a/website/blog/custom-atom.css +++ /dev/null @@ -1,76 +0,0 @@ -/** - * 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. - */ - -* { - color: #0d1137; -} - -main { - flex: 1 0 auto; - width: 100%; - margin: 4rem auto; - padding: 1.5 rem; - max-width: 800px; - /* stylelint-disable-next-line font-family-name-quotes */ - font-family: system-ui, -apple-system, Segoe UI, Roboto, Ubuntu, Cantarell; -} - -.info { - display: block; - margin: 3rem 0; - padding: 2rem 3rem; - border: 1px solid dodgerblue; - border-left-width: 0.5rem; - border-radius: 0.4rem; - background-color: #e52165; -} - -.rss-icon { - height: 3.8rem; - width: 3.8rem; - margin-right: 1rem; -} - -.flex { - display: flex; -} - -.items-start { - align-items: flex-start; -} - -.pb-7 { - padding-bottom: 3rem; -} - -a { - color: #005aff; - text-decoration: none; -} - -h1 { - text-wrap: balance; - font-size: 3.8rem; - line-height: 1; - font-weight: 800; - margin-bottom: 4rem; -} - -h2 { - font-size: 3rem; - line-height: 1.2; - font-weight: 700; - margin-bottom: 3rem; -} - -h2:not(:first-child) { - margin-top: 5.8rem; -} - -.italic { - font-style: italic; -} diff --git a/website/blog/custom-atom.xslt b/website/blog/custom-atom.xslt deleted file mode 100644 index 80406b153124..000000000000 --- a/website/blog/custom-atom.xslt +++ /dev/null @@ -1,65 +0,0 @@ - - - - - - - - - Atom Feed | <xsl:value-of select="atom:feed/atom:title" /> - - - -
      -
      -
      - This is an Atom feed. Subscribe by copying the URL from the address - bar into your newsreader. Visit About Feeds to learn more - and get started. It’s free.
      -

      -
      - - - - - - - - - - -
      - Custom Atom Feed Preview

      -

      - -

      -

      Description:

      -
      -

      Recent Posts

      -
      - -
      - - - -
      Published on -
      -
      - -
      -
      -
      -
      -
      - - -
      - -
      diff --git a/website/blog/custom-rss.css b/website/blog/custom-rss.css deleted file mode 100644 index c016178d9007..000000000000 --- a/website/blog/custom-rss.css +++ /dev/null @@ -1,76 +0,0 @@ -/** - * 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. - */ - -* { - color: #0d1137; -} - -main { - flex: 1 0 auto; - width: 100%; - margin: 4rem auto; - padding: 1.5 rem; - max-width: 800px; - /* stylelint-disable-next-line font-family-name-quotes */ - font-family: system-ui, -apple-system, Segoe UI, Roboto, Ubuntu, Cantarell; -} - -.info { - display: block; - margin: 3rem 0; - padding: 2rem 3rem; - border: 1px solid dodgerblue; - border-left-width: 0.5rem; - border-radius: 0.4rem; - background-color: #e52165; -} - -.rss-icon { - height: 3.8rem; - width: 3.8rem; - margin-right: 1rem; -} - -.flex { - display: flex; -} - -.items-start { - align-items: flex-start; -} - -.pb-7 { - padding-bottom: 3rem; -} - -a { - color: #005aff; - text-decoration: none; -} - -h1 { - text-wrap: balance; - font-size: 3.8rem; - line-height: 1; - font-weight: 800; - margin-bottom: 4rem; -} - -h2 { - font-size: 3rem; - line-height: 1.2; - font-weight: 700; - margin-bottom: 3rem; -} - -h2:not(:first-child) { - margin-top: 5.8rem; -} - -.italic { - font-style: italic; -} diff --git a/website/blog/custom-rss.xslt b/website/blog/custom-rss.xslt deleted file mode 100644 index c258f34d5a42..000000000000 --- a/website/blog/custom-rss.xslt +++ /dev/null @@ -1,65 +0,0 @@ - - - - - - - - - Atom Feed | <xsl:value-of select="atom:feed/atom:title" /> - - - -
      -
      -
      - This is an Atom feed. Subscribe by copying the URL from the address - bar into your newsreader. Visit About Feeds to learn more - and get started. It’s free.
      -

      -
      - - - - - - - - - - -
      - Custom Atom Feed Preview

      -

      - -

      -

      Description:

      -
      -

      Recent Posts

      -
      - -
      - - - -
      Published on -
      -
      - -
      -
      -
      -
      -
      - - -
      - -
      diff --git a/website/docusaurus.config.ts b/website/docusaurus.config.ts index 70d7fd33b78f..56d24ea441c7 100644 --- a/website/docusaurus.config.ts +++ b/website/docusaurus.config.ts @@ -488,6 +488,7 @@ export default async function createConfigAsync() { feedOptions: { type: 'all', copyright: `Copyright © ${new Date().getFullYear()} Facebook, Inc.`, + xslt: true, }, blogTitle: 'Docusaurus blog', blogDescription: 'Read blog posts about Docusaurus from the team', From 1f65318af37c4123da88c28306cedfc9dc9148ba Mon Sep 17 00:00:00 2001 From: ozakione <29860391+OzakIOne@users.noreply.github.com> Date: Mon, 29 Jul 2024 16:18:51 +0200 Subject: [PATCH 15/36] format & dogfood --- .../assets/atom.xslt | 34 ++++++++--------- .../assets/rss.xslt | 38 +++++++++---------- website/_dogfooding/dogfooding.config.ts | 6 +-- 3 files changed, 39 insertions(+), 39 deletions(-) diff --git a/packages/docusaurus-plugin-content-blog/assets/atom.xslt b/packages/docusaurus-plugin-content-blog/assets/atom.xslt index f62448953f59..448b2f2f0a1a 100644 --- a/packages/docusaurus-plugin-content-blog/assets/atom.xslt +++ b/packages/docusaurus-plugin-content-blog/assets/atom.xslt @@ -1,6 +1,6 @@ + xmlns:atom="http://www.w3.org/2005/Atom"> @@ -15,27 +15,27 @@
      This is an Atom feed. Subscribe by copying the URL from the address - bar into your newsreader. Visit About Feeds to learn more - and get started. It’s free.
      + bar into your newsreader. Visit About Feeds to + learn more and get started. It’s free.

      - - - - - - - - + xmlns:xlink="http://www.w3.org/1999/xlink" + viewBox="0 0 455.731 455.731" xml:space="preserve"> + + + + + + + +
      - Custom Atom Feed Preview

      + Custom Atom Feed Preview

      diff --git a/packages/docusaurus-plugin-content-blog/assets/rss.xslt b/packages/docusaurus-plugin-content-blog/assets/rss.xslt index 3d0db18eb509..e050f438f209 100644 --- a/packages/docusaurus-plugin-content-blog/assets/rss.xslt +++ b/packages/docusaurus-plugin-content-blog/assets/rss.xslt @@ -1,10 +1,10 @@ + xmlns:atom="http://www.w3.org/2005/Atom"> - + RSS Feed | <xsl:value-of select="rss/channel/title" /> @@ -15,27 +15,27 @@
      This is an RSS feed. Subscribe by copying the URL from the address - bar into your newsreader. Visit About Feeds to learn more - and get started. It’s free.
      + bar into your newsreader. Visit About Feeds to + learn more and get started. It’s free.

      - - - - - - - - - + xmlns:xlink="http://www.w3.org/1999/xlink" + viewBox="0 0 455.731 455.731" xml:space="preserve"> + + + + + + + + +
      - RSS Feed Preview

      + RSS Feed Preview

      diff --git a/website/_dogfooding/dogfooding.config.ts b/website/_dogfooding/dogfooding.config.ts index 4fece91ae348..9fb6c60665cd 100644 --- a/website/_dogfooding/dogfooding.config.ts +++ b/website/_dogfooding/dogfooding.config.ts @@ -88,9 +88,9 @@ export const dogfoodingPluginInstances: PluginConfig[] = [ type: 'all', title: 'Docusaurus Tests Blog', copyright: `Copyright © ${new Date().getFullYear()} Facebook, Inc.`, - // xsl: true, - // rssXslt: 'custom-rss.xslt', - // atomXslt: 'custom-atom.xslt', + xslt: true, + rssXslt: 'custom-rss.xslt', + atomXslt: 'custom-atom.xslt', }, readingTime: ({content, frontMatter, defaultReadingTime}) => frontMatter.hide_reading_time From 1653ed268e23b15e1223ce75fe2b64fee9f84087 Mon Sep 17 00:00:00 2001 From: ozakione <29860391+OzakIOne@users.noreply.github.com> Date: Mon, 29 Jul 2024 16:22:36 +0200 Subject: [PATCH 16/36] remove unused file --- website/_dogfooding/_blog tests/rss-feed.css | 72 ------------------- website/_dogfooding/_blog tests/rss-feed.xslt | 66 ----------------- 2 files changed, 138 deletions(-) delete mode 100644 website/_dogfooding/_blog tests/rss-feed.css delete mode 100644 website/_dogfooding/_blog tests/rss-feed.xslt diff --git a/website/_dogfooding/_blog tests/rss-feed.css b/website/_dogfooding/_blog tests/rss-feed.css deleted file mode 100644 index 17d483670f0d..000000000000 --- a/website/_dogfooding/_blog tests/rss-feed.css +++ /dev/null @@ -1,72 +0,0 @@ -/** - * 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. - */ - -main { - flex: 1 0 auto; - width: 100%; - margin: 4rem auto; - padding: 1.5 rem; - max-width: 800px; - /* stylelint-disable-next-line font-family-name-quotes */ - font-family: system-ui, -apple-system, Segoe UI, Roboto, Ubuntu, Cantarell; -} - -.info { - display: block; - margin: 3rem 0; - padding: 2rem 3rem; - border: 1px solid dodgerblue; - border-left-width: 0.5rem; - border-radius: 0.4rem; - background-color: #edf5ff; -} - -.rss-icon { - height: 3.8rem; - width: 3.8rem; - margin-right: 1rem; -} - -.flex { - display: flex; -} - -.items-start { - align-items: flex-start; -} - -.pb-7 { - padding-bottom: 3rem; -} - -a { - color: #005aff; - text-decoration: none; -} - -h1 { - text-wrap: balance; - font-size: 3.8rem; - line-height: 1; - font-weight: 800; - margin-bottom: 4rem; -} - -h2 { - font-size: 3rem; - line-height: 1.2; - font-weight: 700; - margin-bottom: 3rem; -} - -h2:not(:first-child) { - margin-top: 5.8rem; -} - -.italic { - font-style: italic; -} diff --git a/website/_dogfooding/_blog tests/rss-feed.xslt b/website/_dogfooding/_blog tests/rss-feed.xslt deleted file mode 100644 index 3698dadf4e94..000000000000 --- a/website/_dogfooding/_blog tests/rss-feed.xslt +++ /dev/null @@ -1,66 +0,0 @@ - - - - - - - - - RSS Feed | <xsl:value-of select="rss/channel/title" /> - - - -
      -
      -
      - This is an RSS feed. Subscribe by copying the URL from the address - bar into your newsreader. Visit About Feeds to learn more - and get started. It’s free.
      -

      -
      - - - - - - - - - - -
      - RSS Feed Preview

      -

      - -

      -

      Description:

      -
      -

      Recent Posts

      -
      - -
      - - - -
      Published on -
      -
      - -
      -
      -
      -
      -
      - - -
      - -
      From 7096afffb15f9cae3e8dfa6ccaa07071c145d23c Mon Sep 17 00:00:00 2001 From: ozakione <29860391+OzakIOne@users.noreply.github.com> Date: Tue, 30 Jul 2024 13:57:58 +0200 Subject: [PATCH 17/36] refactor options to object --- .../assets/atom.xslt | 2 +- .../docusaurus-plugin-content-blog/src/feed.ts | 10 +++++----- .../src/options.ts | 16 ++++++++++------ .../src/plugin-content-blog.d.ts | 15 +++++++++++---- website/_dogfooding/dogfooding.config.ts | 8 +++++--- website/docusaurus.config.ts | 4 +++- 6 files changed, 35 insertions(+), 20 deletions(-) diff --git a/packages/docusaurus-plugin-content-blog/assets/atom.xslt b/packages/docusaurus-plugin-content-blog/assets/atom.xslt index 448b2f2f0a1a..11ac5264071a 100644 --- a/packages/docusaurus-plugin-content-blog/assets/atom.xslt +++ b/packages/docusaurus-plugin-content-blog/assets/atom.xslt @@ -35,7 +35,7 @@
      - Custom Atom Feed Preview + Atom Feed Preview

      diff --git a/packages/docusaurus-plugin-content-blog/src/feed.ts b/packages/docusaurus-plugin-content-blog/src/feed.ts index 268bdd5c9f86..d4db1002f566 100644 --- a/packages/docusaurus-plugin-content-blog/src/feed.ts +++ b/packages/docusaurus-plugin-content-blog/src/feed.ts @@ -233,7 +233,7 @@ async function createBlogFeedFile({ feed, feedType, generatePath, - feedOptions: {atomXslt, rssXslt, xslt}, + feedOptions: {xslt}, contentPaths, }: { feed: Feed; @@ -247,11 +247,11 @@ async function createBlogFeedFile({ case 'rss': { const rssFeed = feed.rss2(); const outputPath = 'rss.xml'; - if (xslt) { + if (xslt.enabled) { const xsltFeed = await transformFeedWithStylesheet({ feedDetails: rssFeed, generatePath, - xsltFile: rssXslt, + xsltFile: xslt.rssXslt, contentPaths, }); return [xsltFeed, outputPath]; @@ -263,11 +263,11 @@ async function createBlogFeedFile({ case 'atom': { const atomFeed = feed.atom1(); const outputPath = 'atom.xml'; - if (xslt) { + if (xslt.enabled) { const xsltFeed = await transformFeedWithStylesheet({ feedDetails: atomFeed, generatePath, - xsltFile: atomXslt, + xsltFile: xslt.atomXslt, contentPaths, }); return [xsltFeed, outputPath]; diff --git a/packages/docusaurus-plugin-content-blog/src/options.ts b/packages/docusaurus-plugin-content-blog/src/options.ts index aa03605ea3b2..aae8a44cca61 100644 --- a/packages/docusaurus-plugin-content-blog/src/options.ts +++ b/packages/docusaurus-plugin-content-blog/src/options.ts @@ -27,9 +27,11 @@ export const DEFAULT_OPTIONS: PluginOptions = { type: ['rss', 'atom'], copyright: '', limit: 20, - xslt: false, - atomXslt: 'atom.xslt', - rssXslt: 'rss.xslt', + xslt: { + enabled: false, + atomXslt: 'atom.xslt', + rssXslt: 'rss.xslt', + }, }, beforeDefaultRehypePlugins: [], beforeDefaultRemarkPlugins: [], @@ -129,9 +131,11 @@ const PluginOptionSchema = Joi.object({ ) .allow(null) .default(DEFAULT_OPTIONS.feedOptions.type), - xslt: Joi.boolean().default(DEFAULT_OPTIONS.feedOptions.xslt), - atomXslt: Joi.string().default(DEFAULT_OPTIONS.feedOptions.atomXslt), - rssXslt: Joi.string().default(DEFAULT_OPTIONS.feedOptions.rssXslt), + xslt: Joi.object({ + enabled: Joi.boolean().default(DEFAULT_OPTIONS.feedOptions.xslt.enabled), + atomXslt: Joi.string().default(DEFAULT_OPTIONS.feedOptions.xslt.atomXslt), + rssXslt: Joi.string().default(DEFAULT_OPTIONS.feedOptions.xslt.rssXslt), + }).default(DEFAULT_OPTIONS.feedOptions.xslt), title: Joi.string().allow(''), description: Joi.string().allow(''), // Only add default value when user actually wants a feed (type is not null) diff --git a/packages/docusaurus-plugin-content-blog/src/plugin-content-blog.d.ts b/packages/docusaurus-plugin-content-blog/src/plugin-content-blog.d.ts index 43b5fd9ab2c5..1349002d5f8a 100644 --- a/packages/docusaurus-plugin-content-blog/src/plugin-content-blog.d.ts +++ b/packages/docusaurus-plugin-content-blog/src/plugin-content-blog.d.ts @@ -291,10 +291,12 @@ yarn workspace v1.22.19image` is a collocated image path, this entry will be the export type FeedType = 'rss' | 'atom' | 'json'; export type XslParams = { - /** Enable xsl stylesheet */ - xslt: boolean; - rssXslt: string; - atomXslt: string; + /** Enable xslt stylesheet */ + xslt: { + enabled: boolean; + rssXslt: string; + atomXslt: string; + }; }; /** @@ -491,6 +493,11 @@ yarn workspace v1.22.19image` is a collocated image path, this entry will be the { /** Type of feed to be generated. Use `null` to disable generation. */ type?: FeedOptions['type'] | 'all' | FeedType; + xslt?: { + enabled?: boolean; + rssXslt?: string; + atomXslt?: string; + }; } >; /** diff --git a/website/_dogfooding/dogfooding.config.ts b/website/_dogfooding/dogfooding.config.ts index 9fb6c60665cd..848b7872603f 100644 --- a/website/_dogfooding/dogfooding.config.ts +++ b/website/_dogfooding/dogfooding.config.ts @@ -88,9 +88,11 @@ export const dogfoodingPluginInstances: PluginConfig[] = [ type: 'all', title: 'Docusaurus Tests Blog', copyright: `Copyright © ${new Date().getFullYear()} Facebook, Inc.`, - xslt: true, - rssXslt: 'custom-rss.xslt', - atomXslt: 'custom-atom.xslt', + xslt: { + enabled: true, + rssXslt: 'custom-rss.xslt', + atomXslt: 'custom-atom.xslt', + }, }, readingTime: ({content, frontMatter, defaultReadingTime}) => frontMatter.hide_reading_time diff --git a/website/docusaurus.config.ts b/website/docusaurus.config.ts index 56d24ea441c7..d26322d84afd 100644 --- a/website/docusaurus.config.ts +++ b/website/docusaurus.config.ts @@ -488,7 +488,9 @@ export default async function createConfigAsync() { feedOptions: { type: 'all', copyright: `Copyright © ${new Date().getFullYear()} Facebook, Inc.`, - xslt: true, + xslt: { + enabled: true, + }, }, blogTitle: 'Docusaurus blog', blogDescription: 'Read blog posts about Docusaurus from the team', From dcc797f31c4a5ac6247816fa9963c37cf8cc78b1 Mon Sep 17 00:00:00 2001 From: ozakione <29860391+OzakIOne@users.noreply.github.com> Date: Tue, 30 Jul 2024 15:17:40 +0200 Subject: [PATCH 18/36] fix tests --- .../__fixtures__/website/blog/custom-rss.xslt | 25 +- .../__tests__/__snapshots__/feed.test.ts.snap | 380 +++--------------- .../src/__tests__/feed.test.ts | 17 +- .../src/__tests__/options.test.ts | 23 +- .../_dogfooding/_blog tests/custom-rss.xslt | 27 +- 5 files changed, 95 insertions(+), 377 deletions(-) diff --git a/packages/docusaurus-plugin-content-blog/src/__tests__/__fixtures__/website/blog/custom-rss.xslt b/packages/docusaurus-plugin-content-blog/src/__tests__/__fixtures__/website/blog/custom-rss.xslt index c258f34d5a42..4d793963cba1 100644 --- a/packages/docusaurus-plugin-content-blog/src/__tests__/__fixtures__/website/blog/custom-rss.xslt +++ b/packages/docusaurus-plugin-content-blog/src/__tests__/__fixtures__/website/blog/custom-rss.xslt @@ -7,16 +7,16 @@ - Atom Feed | <xsl:value-of select="atom:feed/atom:title" /> + RSS Feed | <xsl:value-of select="rss/channel/title" />
      - This is an Atom feed. Subscribe by copying the URL from the address - bar into your newsreader. Visit About Feeds to learn more - and get started. It’s free.
      + This is an RSS feed. Subscribe by copying the URL from the address + bar into your newsreader. Visit About Feeds to learn more + and get started. It’s free.

      - Custom Atom Feed Preview

      + Custom RSS Feed Preview

      - +

      -

      Description:

      +

      Description:

      Recent Posts

      - +
      - - + +
      Published on + select="substring(pubDate,0,17)" />
      - +
      diff --git a/packages/docusaurus-plugin-content-blog/src/__tests__/__snapshots__/feed.test.ts.snap b/packages/docusaurus-plugin-content-blog/src/__tests__/__snapshots__/feed.test.ts.snap index de5e3b131595..7ad1a8155da7 100644 --- a/packages/docusaurus-plugin-content-blog/src/__tests__/__snapshots__/feed.test.ts.snap +++ b/packages/docusaurus-plugin-content-blog/src/__tests__/__snapshots__/feed.test.ts.snap @@ -629,7 +629,7 @@ exports[`atom has xslt files for feed 1`] = ` [ " + xmlns:atom="http://www.w3.org/2005/Atom"> @@ -644,27 +644,27 @@ exports[`atom has xslt files for feed 1`] = `
      This is an Atom feed. Subscribe by copying the URL from the address - bar into your newsreader. Visit About Feeds to learn more - and get started. It’s free.
      + bar into your newsreader. Visit About Feeds to + learn more and get started. It’s free.

      - - - - - - - - + xmlns:xlink="http://www.w3.org/1999/xlink" + viewBox="0 0 455.731 455.731" xml:space="preserve"> + + + + + + + +
      - Custom Atom Feed Preview

      + Atom Feed Preview

      @@ -962,149 +962,6 @@ exports[`json filters to the first two entries using limit 1`] = ` exports[`json has custom xslt files for feed 1`] = ` [ - " - - - - - - - - Atom Feed | <xsl:value-of select="atom:feed/atom:title" /> - - - -
      -
      -
      - This is an Atom feed. Subscribe by copying the URL from the address - bar into your newsreader. Visit About Feeds to learn more - and get started. It’s free.
      -

      -
      - - - - - - - - - - -
      - Custom Atom Feed Preview

      -

      - -

      -

      Description:

      -
      -

      Recent Posts

      -
      - -
      - - - -
      Published on -
      -
      - -
      -
      -
      -
      -
      - - -
      - -
      -", - "/** - * 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. - */ - -* { - color: #0d1137; -} - -main { - flex: 1 0 auto; - width: 100%; - margin: 4rem auto; - padding: 1.5 rem; - max-width: 800px; - /* stylelint-disable-next-line font-family-name-quotes */ - font-family: system-ui, -apple-system, Segoe UI, Roboto, Ubuntu, Cantarell; -} - -.info { - display: block; - margin: 3rem 0; - padding: 2rem 3rem; - border: 1px solid dodgerblue; - border-left-width: 0.5rem; - border-radius: 0.4rem; - background-color: #e52165; -} - -.rss-icon { - height: 3.8rem; - width: 3.8rem; - margin-right: 1rem; -} - -.flex { - display: flex; -} - -.items-start { - align-items: flex-start; -} - -.pb-7 { - padding-bottom: 3rem; -} - -a { - color: #005aff; - text-decoration: none; -} - -h1 { - text-wrap: balance; - font-size: 3.8rem; - line-height: 1; - font-weight: 800; - margin-bottom: 4rem; -} - -h2 { - font-size: 3rem; - line-height: 1.2; - font-weight: 700; - margin-bottom: 3rem; -} - -h2:not(:first-child) { - margin-top: 5.8rem; -} - -.italic { - font-style: italic; -} -", "{ "version": "https://jsonfeed.org/version/1", "title": "Hello Blog", @@ -1402,146 +1259,6 @@ exports[`json has feed item for each post 1`] = ` exports[`json has xslt files for feed 1`] = ` [ - " - - - - - - - - RSS Feed | <xsl:value-of select="rss/channel/title" /> - - - -
      -
      -
      - This is an RSS feed. Subscribe by copying the URL from the address - bar into your newsreader. Visit About Feeds to learn more - and get started. It’s free.
      -

      -
      - - - - - - - - - - -
      - RSS Feed Preview

      -

      - -

      -

      Description:

      -
      -

      Recent Posts

      -
      - -
      - - - -
      Published on -
      -
      - -
      -
      -
      -
      -
      - - -
      - -
      -", - "/** - * 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. - */ - -main { - flex: 1 0 auto; - width: 100%; - margin: 4rem auto; - padding: 1.5 rem; - max-width: 800px; - /* stylelint-disable-next-line font-family-name-quotes */ - font-family: system-ui, -apple-system, Segoe UI, Roboto, Ubuntu, Cantarell; -} - -.info { - display: block; - margin: 3rem 0; - padding: 2rem 3rem; - border: 1px solid dodgerblue; - border-left-width: 0.5rem; - border-radius: 0.4rem; - background-color: #edf5ff; -} - -.rss-icon { - height: 3.8rem; - width: 3.8rem; - margin-right: 1rem; -} - -.flex { - display: flex; -} - -.items-start { - align-items: flex-start; -} - -.pb-7 { - padding-bottom: 3rem; -} - -a { - color: #005aff; - text-decoration: none; -} - -h1 { - text-wrap: balance; - font-size: 3.8rem; - line-height: 1; - font-weight: 800; - margin-bottom: 4rem; -} - -h2 { - font-size: 3rem; - line-height: 1.2; - font-weight: 700; - margin-bottom: 3rem; -} - -h2:not(:first-child) { - margin-top: 5.8rem; -} - -.italic { - font-style: italic; -} -", "{ "version": "https://jsonfeed.org/version/1", "title": "Hello Blog", @@ -1746,16 +1463,16 @@ exports[`rss has custom xslt files for feed 1`] = ` - Atom Feed | <xsl:value-of select="atom:feed/atom:title" /> + RSS Feed | <xsl:value-of select="rss/channel/title" />
      - This is an Atom feed. Subscribe by copying the URL from the address - bar into your newsreader. Visit About Feeds to learn more - and get started. It’s free.
      + This is an RSS feed. Subscribe by copying the URL from the address + bar into your newsreader. Visit About Feeds to learn more + and get started. It’s free.

      - Custom Atom Feed Preview

      + Custom RSS Feed Preview

      - +

      -

      Description:

      +

      Description:

      Recent Posts

      - +
      - - + +
      Published on + select="substring(pubDate,0,17)" />
      - +
      @@ -2248,11 +1966,11 @@ exports[`rss has xslt files for feed 1`] = ` [ " + xmlns:atom="http://www.w3.org/2005/Atom"> - + RSS Feed | <xsl:value-of select="rss/channel/title" /> @@ -2263,27 +1981,27 @@ exports[`rss has xslt files for feed 1`] = `
      This is an RSS feed. Subscribe by copying the URL from the address - bar into your newsreader. Visit About Feeds to learn more - and get started. It’s free.
      + bar into your newsreader. Visit About Feeds to + learn more and get started. It’s free.

      - - - - - - - - - + xmlns:xlink="http://www.w3.org/1999/xlink" + viewBox="0 0 455.731 455.731" xml:space="preserve"> + + + + + + + + +
      - RSS Feed Preview

      + RSS Feed Preview

      diff --git a/packages/docusaurus-plugin-content-blog/src/__tests__/feed.test.ts b/packages/docusaurus-plugin-content-blog/src/__tests__/feed.test.ts index 3c9c1332b6fd..c83122019ac0 100644 --- a/packages/docusaurus-plugin-content-blog/src/__tests__/feed.test.ts +++ b/packages/docusaurus-plugin-content-blog/src/__tests__/feed.test.ts @@ -94,6 +94,7 @@ describe.each(['atom', 'rss', 'json'])('%s', (feedType) => { feedOptions: { type: [feedType], copyright: 'Copyright', + xslt: {enabled: false}, }, readingTime: ({content, defaultReadingTime}) => defaultReadingTime({content}), @@ -137,6 +138,7 @@ describe.each(['atom', 'rss', 'json'])('%s', (feedType) => { feedOptions: { type: [feedType], copyright: 'Copyright', + xslt: {enabled: false}, }, readingTime: ({content, defaultReadingTime}) => defaultReadingTime({content}), @@ -192,6 +194,7 @@ describe.each(['atom', 'rss', 'json'])('%s', (feedType) => { ...rest, }); }, + xslt: {enabled: false}, }, readingTime: ({content, defaultReadingTime}) => defaultReadingTime({content}), @@ -238,6 +241,7 @@ describe.each(['atom', 'rss', 'json'])('%s', (feedType) => { type: [feedType], copyright: 'Copyright', limit: 2, + xslt: {enabled: false}, }, readingTime: ({content, defaultReadingTime}) => defaultReadingTime({content}), @@ -284,6 +288,7 @@ describe.each(['atom', 'rss', 'json'])('%s', (feedType) => { feedOptions: { type: [feedType], copyright: 'Copyright', + xslt: {enabled: false}, }, readingTime: ({content, defaultReadingTime}) => defaultReadingTime({content}), @@ -329,9 +334,7 @@ describe.each(['atom', 'rss', 'json'])('%s', (feedType) => { feedOptions: { type: [feedType], copyright: 'Copyright', - xslt: true, - rssXslt: 'rss.xslt', - atomXslt: 'atom.xslt', + xslt: {enabled: true, rssXslt: 'rss.xslt', atomXslt: 'atom.xslt'}, }, readingTime: ({content, defaultReadingTime}) => defaultReadingTime({content}), @@ -377,9 +380,11 @@ describe.each(['atom', 'rss', 'json'])('%s', (feedType) => { feedOptions: { type: [feedType], copyright: 'Copyright', - xslt: true, - rssXslt: 'custom-rss.xslt', - atomXslt: 'custom-atom.xslt', + xslt: { + enabled: true, + rssXslt: 'custom-rss.xslt', + atomXslt: 'custom-atom.xslt', + }, }, readingTime: ({content, defaultReadingTime}) => defaultReadingTime({content}), diff --git a/packages/docusaurus-plugin-content-blog/src/__tests__/options.test.ts b/packages/docusaurus-plugin-content-blog/src/__tests__/options.test.ts index 52f60e4e056a..63032123683c 100644 --- a/packages/docusaurus-plugin-content-blog/src/__tests__/options.test.ts +++ b/packages/docusaurus-plugin-content-blog/src/__tests__/options.test.ts @@ -41,9 +41,6 @@ describe('validateOptions', () => { feedOptions: { type: 'rss' as const, title: 'myTitle', - xslt: false, - atomXslt: 'atom.xslt', - rssXslt: 'rss.xslt', }, path: 'not_blog', routeBasePath: '/myBlog', @@ -59,9 +56,7 @@ describe('validateOptions', () => { title: 'myTitle', copyright: '', limit: 20, - xslt: false, - atomXslt: 'atom.xslt', - rssXslt: 'rss.xslt', + xslt: {enabled: false, atomXslt: 'atom.xslt', rssXslt: 'rss.xslt'}, }, }); }); @@ -115,9 +110,7 @@ describe('validateOptions', () => { type: ['rss', 'atom', 'json'], copyright: '', limit: 20, - xslt: false, - rssXslt: 'rss.xslt', - atomXslt: 'atom.xslt', + xslt: {enabled: false, atomXslt: 'atom.xslt', rssXslt: 'rss.xslt'}, }, }); }); @@ -132,9 +125,7 @@ describe('validateOptions', () => { feedOptions: { type: null, limit: 20, - xslt: false, - rssXslt: 'rss.xslt', - atomXslt: 'atom.xslt', + xslt: {enabled: false, atomXslt: 'atom.xslt', rssXslt: 'rss.xslt'}, }, }); }); @@ -159,9 +150,11 @@ describe('validateOptions', () => { title: 'title', copyright: '', limit: 20, - xslt: false, - rssXslt: 'rss.xslt', - atomXslt: 'atom.xslt', + xslt: { + enabled: false, + rssXslt: 'rss.xslt', + atomXslt: 'atom.xslt', + }, }, }); }); diff --git a/website/_dogfooding/_blog tests/custom-rss.xslt b/website/_dogfooding/_blog tests/custom-rss.xslt index 80406b153124..4d793963cba1 100644 --- a/website/_dogfooding/_blog tests/custom-rss.xslt +++ b/website/_dogfooding/_blog tests/custom-rss.xslt @@ -7,16 +7,16 @@ - Atom Feed | <xsl:value-of select="atom:feed/atom:title" /> - + RSS Feed | <xsl:value-of select="rss/channel/title" /> +
      - This is an Atom feed. Subscribe by copying the URL from the address - bar into your newsreader. Visit About Feeds to learn more - and get started. It’s free.
      + This is an RSS feed. Subscribe by copying the URL from the address + bar into your newsreader. Visit About Feeds to learn more + and get started. It’s free.

      - Custom Atom Feed Preview

      + Custom RSS Feed Preview

      - +

      -

      Description:

      +

      Description:

      Recent Posts

      - +
      - - + +
      Published on + select="substring(pubDate,0,17)" />
      - +
      From b25cb9f757bd243f9ee4b6687de9a46a667b120a Mon Sep 17 00:00:00 2001 From: sebastien Date: Thu, 1 Aug 2024 18:46:09 +0200 Subject: [PATCH 19/36] rename XslParams to FeedXSLTOptions --- .../src/plugin-content-blog.d.ts | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/packages/docusaurus-plugin-content-blog/src/plugin-content-blog.d.ts b/packages/docusaurus-plugin-content-blog/src/plugin-content-blog.d.ts index a4d77b3e33ef..1b0031c5c49b 100644 --- a/packages/docusaurus-plugin-content-blog/src/plugin-content-blog.d.ts +++ b/packages/docusaurus-plugin-content-blog/src/plugin-content-blog.d.ts @@ -316,19 +316,18 @@ declare module '@docusaurus/plugin-content-blog' { export type FeedType = 'rss' | 'atom' | 'json'; - export type XslParams = { - /** Enable xslt stylesheet */ - xslt: { - enabled: boolean; - rssXslt: string; - atomXslt: string; - }; + export type FeedXSLTOptions = { + enabled: boolean; + rssXslt: string; + atomXslt: string; }; /** * Normalized feed options used within code. */ - export type FeedOptions = XslParams & { + export type FeedOptions = { + /** Enable feeds xslt stylesheets */ + xslt?: FeedXSLTOptions; /** If `null`, no feed is generated. */ type?: FeedType[] | null; /** Title of generated feed. */ From 2500197cf8d10c5c1004438334d99180a7f5ad4e Mon Sep 17 00:00:00 2001 From: sebastien Date: Thu, 1 Aug 2024 18:52:47 +0200 Subject: [PATCH 20/36] type problem --- .../docusaurus-plugin-content-blog/src/plugin-content-blog.d.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/docusaurus-plugin-content-blog/src/plugin-content-blog.d.ts b/packages/docusaurus-plugin-content-blog/src/plugin-content-blog.d.ts index 1b0031c5c49b..cc16caa948a2 100644 --- a/packages/docusaurus-plugin-content-blog/src/plugin-content-blog.d.ts +++ b/packages/docusaurus-plugin-content-blog/src/plugin-content-blog.d.ts @@ -327,7 +327,7 @@ declare module '@docusaurus/plugin-content-blog' { */ export type FeedOptions = { /** Enable feeds xslt stylesheets */ - xslt?: FeedXSLTOptions; + xslt: FeedXSLTOptions; /** If `null`, no feed is generated. */ type?: FeedType[] | null; /** Title of generated feed. */ From 66f5b11190a4d9f93361063c073d0a8f0369074a Mon Sep 17 00:00:00 2001 From: sebastien Date: Fri, 2 Aug 2024 12:08:50 +0200 Subject: [PATCH 21/36] add proper feed xslt options + unit tests --- .../__snapshots__/options.test.ts.snap | 2 +- .../src/__tests__/options.test.ts | 238 +++++++++++++----- .../src/feed.ts | 8 +- .../src/options.ts | 135 +++++++--- .../src/plugin-content-blog.d.ts | 25 +- 5 files changed, 293 insertions(+), 115 deletions(-) diff --git a/packages/docusaurus-plugin-content-blog/src/__tests__/__snapshots__/options.test.ts.snap b/packages/docusaurus-plugin-content-blog/src/__tests__/__snapshots__/options.test.ts.snap index 4406ef7b72eb..ce4af321ff02 100644 --- a/packages/docusaurus-plugin-content-blog/src/__tests__/__snapshots__/options.test.ts.snap +++ b/packages/docusaurus-plugin-content-blog/src/__tests__/__snapshots__/options.test.ts.snap @@ -1,5 +1,5 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP -exports[`validateOptions throws Error in case of invalid feed type 1`] = `""feedOptions.type" does not match any of the allowed types"`; +exports[`validateOptions feed throws Error in case of invalid feed type 1`] = `""feedOptions.type" does not match any of the allowed types"`; exports[`validateOptions throws Error in case of invalid options 1`] = `""postsPerPage" must be greater than or equal to 1"`; diff --git a/packages/docusaurus-plugin-content-blog/src/__tests__/options.test.ts b/packages/docusaurus-plugin-content-blog/src/__tests__/options.test.ts index 63032123683c..31cd7f5575a6 100644 --- a/packages/docusaurus-plugin-content-blog/src/__tests__/options.test.ts +++ b/packages/docusaurus-plugin-content-blog/src/__tests__/options.test.ts @@ -6,8 +6,12 @@ */ import {normalizePluginOptions} from '@docusaurus/utils-validation'; -import {validateOptions, DEFAULT_OPTIONS} from '../options'; -import type {Options, PluginOptions} from '@docusaurus/plugin-content-blog'; +import {validateOptions, DEFAULT_OPTIONS, XSLTBuiltInPaths} from '../options'; +import type { + Options, + PluginOptions, + UserFeedOptions, +} from '@docusaurus/plugin-content-blog'; import type {Validate} from '@docusaurus/types'; function testValidate(options?: Options) { @@ -56,7 +60,7 @@ describe('validateOptions', () => { title: 'myTitle', copyright: '', limit: 20, - xslt: {enabled: false, atomXslt: 'atom.xslt', rssXslt: 'rss.xslt'}, + xslt: {rss: null, atom: null}, }, }); }); @@ -88,74 +92,182 @@ describe('validateOptions', () => { ).toThrowErrorMatchingSnapshot(); }); - it('throws Error in case of invalid feed type', () => { - expect(() => - testValidate({ + describe('feed', () => { + it('throws Error in case of invalid feed type', () => { + expect(() => + testValidate({ + feedOptions: { + // @ts-expect-error: test + type: 'none', + }, + }), + ).toThrowErrorMatchingSnapshot(); + }); + + it('converts all feed type to array with other feed type', () => { + expect( + testValidate({ + feedOptions: {type: 'all'}, + }), + ).toEqual({ + ...defaultOptions, feedOptions: { - // @ts-expect-error: test - type: 'none', + type: ['rss', 'atom', 'json'], + copyright: '', + limit: 20, + xslt: {rss: null, atom: null}, }, - }), - ).toThrowErrorMatchingSnapshot(); - }); - - it('converts all feed type to array with other feed type', () => { - expect( - testValidate({ - feedOptions: {type: 'all'}, - }), - ).toEqual({ - ...defaultOptions, - feedOptions: { - type: ['rss', 'atom', 'json'], - copyright: '', - limit: 20, - xslt: {enabled: false, atomXslt: 'atom.xslt', rssXslt: 'rss.xslt'}, - }, + }); }); - }); - it('accepts null type and return same', () => { - expect( - testValidate({ - feedOptions: {type: null}, - }), - ).toEqual({ - ...defaultOptions, - feedOptions: { - type: null, - limit: 20, - xslt: {enabled: false, atomXslt: 'atom.xslt', rssXslt: 'rss.xslt'}, - }, + it('accepts null feed type and return same', () => { + expect( + testValidate({ + feedOptions: {type: null}, + }), + ).toEqual({ + ...defaultOptions, + feedOptions: { + type: null, + limit: 20, + xslt: {rss: null, atom: null}, + }, + }); }); - }); - it('contains array with rss + atom for missing feed type', () => { - expect( - testValidate({ - feedOptions: {}, - }), - ).toEqual(defaultOptions); - }); + it('contains array with rss + atom for missing feed type', () => { + expect( + testValidate({ + feedOptions: {}, + }), + ).toEqual(defaultOptions); + }); - it('has array with rss + atom, title for missing feed type', () => { - expect( - testValidate({ - feedOptions: {title: 'title'}, - }), - ).toEqual({ - ...defaultOptions, - feedOptions: { - type: ['rss', 'atom'], - title: 'title', - copyright: '', - limit: 20, - xslt: { - enabled: false, - rssXslt: 'rss.xslt', - atomXslt: 'atom.xslt', + it('has array with rss + atom, title for missing feed type', () => { + expect( + testValidate({ + feedOptions: {title: 'title'}, + }), + ).toEqual({ + ...defaultOptions, + feedOptions: { + type: ['rss', 'atom'], + title: 'title', + copyright: '', + limit: 20, + xslt: {rss: null, atom: null}, }, - }, + }); + }); + + describe('feed xslt', () => { + function testXSLT(xslt: UserFeedOptions['xslt']) { + return testValidate({feedOptions: {xslt}}).feedOptions.xslt; + } + + it('accepts xlst: true', () => { + expect(testXSLT(true)).toEqual({ + rss: XSLTBuiltInPaths.rss, + atom: XSLTBuiltInPaths.atom, + }); + }); + + it('accepts xlst: false', () => { + expect(testXSLT(false)).toEqual({ + rss: null, + atom: null, + }); + }); + + it('accepts xlst: null', () => { + expect(testXSLT(null)).toEqual({ + rss: null, + atom: null, + }); + }); + + it('accepts xlst: undefined', () => { + expect(testXSLT(undefined)).toEqual({ + rss: null, + atom: null, + }); + }); + + it('accepts xlst: {rss: true}', () => { + expect(testXSLT({rss: true})).toEqual({ + rss: XSLTBuiltInPaths.rss, + atom: null, + }); + }); + + it('accepts xlst: {atom: true}', () => { + expect(testXSLT({atom: true})).toEqual({ + rss: null, + atom: XSLTBuiltInPaths.atom, + }); + }); + + it('accepts xlst: {rss: true, atom: true}', () => { + expect(testXSLT({rss: true, atom: true})).toEqual({ + rss: XSLTBuiltInPaths.rss, + atom: XSLTBuiltInPaths.atom, + }); + }); + + it('accepts xlst: {rss: "custom-path"}', () => { + expect(testXSLT({rss: 'custom-path'})).toEqual({ + rss: 'custom-path', + atom: null, + }); + }); + + it('accepts xlst: {rss: true, atom: "custom-path"}', () => { + expect(testXSLT({rss: true, atom: 'custom-path'})).toEqual({ + rss: XSLTBuiltInPaths.rss, + atom: 'custom-path', + }); + }); + + it('accepts xlst: {rss: null, atom: true}', () => { + expect(testXSLT({rss: null, atom: true})).toEqual({ + rss: null, + atom: XSLTBuiltInPaths.atom, + }); + }); + + it('accepts xlst: {rss: false, atom: null}', () => { + expect(testXSLT({rss: false, atom: null})).toEqual({ + rss: null, + atom: null, + }); + }); + + it('rejects xlst: 42', () => { + // @ts-expect-error: bad type + expect(() => testXSLT(42)).toThrowErrorMatchingInlineSnapshot( + `""feedOptions.xslt" must be one of [object, boolean]"`, + ); + }); + it('rejects xlst: []', () => { + // @ts-expect-error: bad type + expect(() => testXSLT([])).toThrowErrorMatchingInlineSnapshot( + `""feedOptions.xslt" must be one of [object, boolean]"`, + ); + }); + + it('rejects xlst: {rss: 42}', () => { + // @ts-expect-error: bad type + expect(() => testXSLT({rss: 42})).toThrowErrorMatchingInlineSnapshot( + `""feedOptions.xslt.rss" must be one of [string, boolean]"`, + ); + }); + + it('rejects xlst: {rss: []}', () => { + // @ts-expect-error: bad type + expect(() => testXSLT({rss: 42})).toThrowErrorMatchingInlineSnapshot( + `""feedOptions.xslt.rss" must be one of [string, boolean]"`, + ); + }); }); }); diff --git a/packages/docusaurus-plugin-content-blog/src/feed.ts b/packages/docusaurus-plugin-content-blog/src/feed.ts index d4db1002f566..daeeae72043f 100644 --- a/packages/docusaurus-plugin-content-blog/src/feed.ts +++ b/packages/docusaurus-plugin-content-blog/src/feed.ts @@ -247,11 +247,11 @@ async function createBlogFeedFile({ case 'rss': { const rssFeed = feed.rss2(); const outputPath = 'rss.xml'; - if (xslt.enabled) { + if (xslt.rss) { const xsltFeed = await transformFeedWithStylesheet({ feedDetails: rssFeed, generatePath, - xsltFile: xslt.rssXslt, + xsltFile: xslt.rss, contentPaths, }); return [xsltFeed, outputPath]; @@ -263,11 +263,11 @@ async function createBlogFeedFile({ case 'atom': { const atomFeed = feed.atom1(); const outputPath = 'atom.xml'; - if (xslt.enabled) { + if (xslt.atom) { const xsltFeed = await transformFeedWithStylesheet({ feedDetails: atomFeed, generatePath, - xsltFile: xslt.atomXslt, + xsltFile: xslt.atom, contentPaths, }); return [xsltFeed, outputPath]; diff --git a/packages/docusaurus-plugin-content-blog/src/options.ts b/packages/docusaurus-plugin-content-blog/src/options.ts index e551e07382b9..25b138b23929 100644 --- a/packages/docusaurus-plugin-content-blog/src/options.ts +++ b/packages/docusaurus-plugin-content-blog/src/options.ts @@ -19,6 +19,7 @@ import type { PluginOptions, Options, FeedType, + FeedXSLTOptions, } from '@docusaurus/plugin-content-blog'; import type {OptionValidationContext} from '@docusaurus/types'; @@ -28,9 +29,8 @@ export const DEFAULT_OPTIONS: PluginOptions = { copyright: '', limit: 20, xslt: { - enabled: false, - atomXslt: 'atom.xslt', - rssXslt: 'rss.xslt', + rss: null, + atom: null, }, }, beforeDefaultRehypePlugins: [], @@ -73,6 +73,98 @@ export const DEFAULT_OPTIONS: PluginOptions = { onInlineAuthors: 'warn', }; +// TODO +export const XSLTBuiltInPaths = { + rss: 'todo path RSS xslt', + atom: 'todo path Atom xslt', +}; + +function normalizeXsltOption( + option: string | null | boolean, + type: 'rss' | 'atom', +): string | null { + if (typeof option === 'string') { + return option; + } + if (option === true) { + return XSLTBuiltInPaths[type]; + } + return null; +} + +function createXLSTFilePathSchema(type: 'atom' | 'rss') { + return Joi.alternatives() + .try( + Joi.string().required(), + Joi.boolean() + .allow(null, () => undefined) + .custom((val) => { + console.log({val}); + return normalizeXsltOption(val, type); + }), + ) + .optional() + .default(null); +} + +const FeedXSLTOptionsSchema = Joi.alternatives() + .try( + Joi.object({ + rss: createXLSTFilePathSchema('rss'), + atom: createXLSTFilePathSchema('atom'), + }).required(), + Joi.boolean() + .allow(null, () => undefined) + .custom((val) => ({ + rss: normalizeXsltOption(val, 'rss'), + atom: normalizeXsltOption(val, 'atom'), + })), + ) + .optional() + .custom((val) => { + if (val === null) { + return { + rss: null, + atom: null, + }; + } + return val; + }) + .default(DEFAULT_OPTIONS.feedOptions.xslt); + +const FeedOptionsSchema = Joi.object({ + type: Joi.alternatives() + .try( + Joi.array().items(Joi.string().equal('rss', 'atom', 'json')), + Joi.alternatives().conditional( + Joi.string().equal('all', 'rss', 'atom', 'json'), + { + then: Joi.custom((val: FeedType | 'all') => + val === 'all' ? ['rss', 'atom', 'json'] : [val], + ), + }, + ), + ) + .allow(null) + .default(DEFAULT_OPTIONS.feedOptions.type), + xslt: FeedXSLTOptionsSchema, + title: Joi.string().allow(''), + description: Joi.string().allow(''), + // Only add default value when user actually wants a feed (type is not null) + copyright: Joi.when('type', { + is: Joi.any().valid(null), + then: Joi.string().optional(), + otherwise: Joi.string() + .allow('') + .default(DEFAULT_OPTIONS.feedOptions.copyright), + }), + language: Joi.string(), + createFeedItems: Joi.function(), + limit: Joi.alternatives() + .try(Joi.number(), Joi.valid(null), Joi.valid(false)) + .default(DEFAULT_OPTIONS.feedOptions.limit), +}).default(DEFAULT_OPTIONS.feedOptions); + const PluginOptionSchema = Joi.object({ path: Joi.string().default(DEFAULT_OPTIONS.path), archiveBasePath: Joi.string() @@ -125,42 +217,7 @@ const PluginOptionSchema = Joi.object({ beforeDefaultRehypePlugins: RehypePluginsSchema.default( DEFAULT_OPTIONS.beforeDefaultRehypePlugins, ), - feedOptions: Joi.object({ - type: Joi.alternatives() - .try( - Joi.array().items(Joi.string().equal('rss', 'atom', 'json')), - Joi.alternatives().conditional( - Joi.string().equal('all', 'rss', 'atom', 'json'), - { - then: Joi.custom((val: FeedType | 'all') => - val === 'all' ? ['rss', 'atom', 'json'] : [val], - ), - }, - ), - ) - .allow(null) - .default(DEFAULT_OPTIONS.feedOptions.type), - xslt: Joi.object({ - enabled: Joi.boolean().default(DEFAULT_OPTIONS.feedOptions.xslt.enabled), - atomXslt: Joi.string().default(DEFAULT_OPTIONS.feedOptions.xslt.atomXslt), - rssXslt: Joi.string().default(DEFAULT_OPTIONS.feedOptions.xslt.rssXslt), - }).default(DEFAULT_OPTIONS.feedOptions.xslt), - title: Joi.string().allow(''), - description: Joi.string().allow(''), - // Only add default value when user actually wants a feed (type is not null) - copyright: Joi.when('type', { - is: Joi.any().valid(null), - then: Joi.string().optional(), - otherwise: Joi.string() - .allow('') - .default(DEFAULT_OPTIONS.feedOptions.copyright), - }), - language: Joi.string(), - createFeedItems: Joi.function(), - limit: Joi.alternatives() - .try(Joi.number(), Joi.valid(null), Joi.valid(false)) - .default(DEFAULT_OPTIONS.feedOptions.limit), - }).default(DEFAULT_OPTIONS.feedOptions), + feedOptions: FeedOptionsSchema, authorsMapPath: Joi.string().default(DEFAULT_OPTIONS.authorsMapPath), readingTime: Joi.function().default(() => DEFAULT_OPTIONS.readingTime), sortPosts: Joi.string() diff --git a/packages/docusaurus-plugin-content-blog/src/plugin-content-blog.d.ts b/packages/docusaurus-plugin-content-blog/src/plugin-content-blog.d.ts index cc16caa948a2..6ad8b04a7406 100644 --- a/packages/docusaurus-plugin-content-blog/src/plugin-content-blog.d.ts +++ b/packages/docusaurus-plugin-content-blog/src/plugin-content-blog.d.ts @@ -317,9 +317,16 @@ declare module '@docusaurus/plugin-content-blog' { export type FeedType = 'rss' | 'atom' | 'json'; export type FeedXSLTOptions = { - enabled: boolean; - rssXslt: string; - atomXslt: string; + /** + * RSS XSLT file path, relative to the blog content folder. + * If null, no XSLT file is used and the feed will be displayed as raw XML. + */ + rss: string | null; + /** + * Atom XSLT file path, relative to the blog content folder. + * If null, no XSLT file is used and the feed will be displayed as raw XML. + */ + atom: string | null; }; /** @@ -524,11 +531,13 @@ declare module '@docusaurus/plugin-content-blog' { { /** Type of feed to be generated. Use `null` to disable generation. */ type?: FeedOptions['type'] | 'all' | FeedType; - xslt?: { - enabled?: boolean; - rssXslt?: string; - atomXslt?: string; - }; + xslt?: + | boolean + | null + | { + rss?: string | boolean | null; + atom?: string | boolean | null; + }; } >; /** From d46a07350c661e2c43d4bb507b3fd998af4accd0 Mon Sep 17 00:00:00 2001 From: sebastien Date: Fri, 2 Aug 2024 14:40:51 +0200 Subject: [PATCH 22/36] fix blog feed tests --- .../src/__tests__/feed.test.ts | 17 ++++++++--------- website/_dogfooding/dogfooding.config.ts | 5 ++--- website/docusaurus.config.ts | 4 +--- 3 files changed, 11 insertions(+), 15 deletions(-) diff --git a/packages/docusaurus-plugin-content-blog/src/__tests__/feed.test.ts b/packages/docusaurus-plugin-content-blog/src/__tests__/feed.test.ts index 2f1f7da3d19b..1f452f1f8ddc 100644 --- a/packages/docusaurus-plugin-content-blog/src/__tests__/feed.test.ts +++ b/packages/docusaurus-plugin-content-blog/src/__tests__/feed.test.ts @@ -106,7 +106,7 @@ describe.each(['atom', 'rss', 'json'])('%s', (feedType) => { feedOptions: { type: [feedType], copyright: 'Copyright', - xslt: {enabled: false}, + xslt: {atom: null, rss: null}, }, readingTime: ({content, defaultReadingTime}) => defaultReadingTime({content}), @@ -150,7 +150,7 @@ describe.each(['atom', 'rss', 'json'])('%s', (feedType) => { feedOptions: { type: [feedType], copyright: 'Copyright', - xslt: {enabled: false}, + xslt: {atom: null, rss: null}, }, readingTime: ({content, defaultReadingTime}) => defaultReadingTime({content}), @@ -206,7 +206,7 @@ describe.each(['atom', 'rss', 'json'])('%s', (feedType) => { ...rest, }); }, - xslt: {enabled: false}, + xslt: {atom: null, rss: null}, }, readingTime: ({content, defaultReadingTime}) => defaultReadingTime({content}), @@ -253,7 +253,7 @@ describe.each(['atom', 'rss', 'json'])('%s', (feedType) => { type: [feedType], copyright: 'Copyright', limit: 2, - xslt: {enabled: false}, + xslt: {atom: null, rss: null}, }, readingTime: ({content, defaultReadingTime}) => defaultReadingTime({content}), @@ -300,7 +300,7 @@ describe.each(['atom', 'rss', 'json'])('%s', (feedType) => { feedOptions: { type: [feedType], copyright: 'Copyright', - xslt: {enabled: false}, + xslt: {atom: null, rss: null}, }, readingTime: ({content, defaultReadingTime}) => defaultReadingTime({content}), @@ -346,7 +346,7 @@ describe.each(['atom', 'rss', 'json'])('%s', (feedType) => { feedOptions: { type: [feedType], copyright: 'Copyright', - xslt: {enabled: true, rssXslt: 'rss.xslt', atomXslt: 'atom.xslt'}, + xslt: {rss: 'rss.xslt', atom: 'atom.xslt'}, }, readingTime: ({content, defaultReadingTime}) => defaultReadingTime({content}), @@ -393,9 +393,8 @@ describe.each(['atom', 'rss', 'json'])('%s', (feedType) => { type: [feedType], copyright: 'Copyright', xslt: { - enabled: true, - rssXslt: 'custom-rss.xslt', - atomXslt: 'custom-atom.xslt', + rss: 'custom-rss.xslt', + atom: 'custom-atom.xslt', }, }, readingTime: ({content, defaultReadingTime}) => diff --git a/website/_dogfooding/dogfooding.config.ts b/website/_dogfooding/dogfooding.config.ts index 848b7872603f..b3abfd4d4d2c 100644 --- a/website/_dogfooding/dogfooding.config.ts +++ b/website/_dogfooding/dogfooding.config.ts @@ -89,9 +89,8 @@ export const dogfoodingPluginInstances: PluginConfig[] = [ title: 'Docusaurus Tests Blog', copyright: `Copyright © ${new Date().getFullYear()} Facebook, Inc.`, xslt: { - enabled: true, - rssXslt: 'custom-rss.xslt', - atomXslt: 'custom-atom.xslt', + rss: 'custom-rss.xslt', + atom: 'custom-atom.xslt', }, }, readingTime: ({content, frontMatter, defaultReadingTime}) => diff --git a/website/docusaurus.config.ts b/website/docusaurus.config.ts index d26322d84afd..56d24ea441c7 100644 --- a/website/docusaurus.config.ts +++ b/website/docusaurus.config.ts @@ -488,9 +488,7 @@ export default async function createConfigAsync() { feedOptions: { type: 'all', copyright: `Copyright © ${new Date().getFullYear()} Facebook, Inc.`, - xslt: { - enabled: true, - }, + xslt: true, }, blogTitle: 'Docusaurus blog', blogDescription: 'Read blog posts about Docusaurus from the team', From f2e06290ff0b1a694ecb1c1f457356708abf16b1 Mon Sep 17 00:00:00 2001 From: sebastien Date: Fri, 2 Aug 2024 14:43:29 +0200 Subject: [PATCH 23/36] Add xslt options to init templates --- .../templates/classic-typescript/docusaurus.config.ts | 4 ++++ .../create-docusaurus/templates/classic/docusaurus.config.js | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/packages/create-docusaurus/templates/classic-typescript/docusaurus.config.ts b/packages/create-docusaurus/templates/classic-typescript/docusaurus.config.ts index 4058eac59e23..ae7cbf502e05 100644 --- a/packages/create-docusaurus/templates/classic-typescript/docusaurus.config.ts +++ b/packages/create-docusaurus/templates/classic-typescript/docusaurus.config.ts @@ -42,6 +42,10 @@ const config: Config = { }, blog: { showReadingTime: true, + feedOptions: { + type: ['rss', 'atom'], + xslt: true, + }, // Please change this to your repo. // Remove this to remove the "edit this page" links. editUrl: diff --git a/packages/create-docusaurus/templates/classic/docusaurus.config.js b/packages/create-docusaurus/templates/classic/docusaurus.config.js index 7b8d5b1c7f11..d3b51858f497 100644 --- a/packages/create-docusaurus/templates/classic/docusaurus.config.js +++ b/packages/create-docusaurus/templates/classic/docusaurus.config.js @@ -48,6 +48,10 @@ const config = { }, blog: { showReadingTime: true, + feedOptions: { + type: ['rss', 'atom'], + xslt: true, + }, // Please change this to your repo. // Remove this to remove the "edit this page" links. editUrl: From 952da63f50a590d1a1ed4b83a2e44e71c818c9c7 Mon Sep 17 00:00:00 2001 From: sebastien Date: Fri, 2 Aug 2024 14:52:07 +0200 Subject: [PATCH 24/36] move xsl assets around --- .../{ => src}/assets/atom.css | 0 .../{assets/atom.xslt => src/assets/atom.xsl} | 61 ++++++++++++++----- .../{ => src}/assets/rss.css | 0 .../{assets/rss.xslt => src/assets/rss.xsl} | 60 ++++++++++++------ .../src/options.ts | 10 ++- 5 files changed, 92 insertions(+), 39 deletions(-) rename packages/docusaurus-plugin-content-blog/{ => src}/assets/atom.css (100%) rename packages/docusaurus-plugin-content-blog/{assets/atom.xslt => src/assets/atom.xsl} (51%) rename packages/docusaurus-plugin-content-blog/{ => src}/assets/rss.css (100%) rename packages/docusaurus-plugin-content-blog/{assets/rss.xslt => src/assets/rss.xsl} (51%) diff --git a/packages/docusaurus-plugin-content-blog/assets/atom.css b/packages/docusaurus-plugin-content-blog/src/assets/atom.css similarity index 100% rename from packages/docusaurus-plugin-content-blog/assets/atom.css rename to packages/docusaurus-plugin-content-blog/src/assets/atom.css diff --git a/packages/docusaurus-plugin-content-blog/assets/atom.xslt b/packages/docusaurus-plugin-content-blog/src/assets/atom.xsl similarity index 51% rename from packages/docusaurus-plugin-content-blog/assets/atom.xslt rename to packages/docusaurus-plugin-content-blog/src/assets/atom.xsl index 11ac5264071a..2bd08fbd8de6 100644 --- a/packages/docusaurus-plugin-content-blog/assets/atom.xslt +++ b/packages/docusaurus-plugin-content-blog/src/assets/atom.xsl @@ -1,13 +1,17 @@ - - + + - Atom Feed | <xsl:value-of select="atom:feed/atom:title" /> + Atom Feed | <xsl:value-of + select="atom:feed/atom:title" + /> @@ -15,22 +19,44 @@
      This is an Atom feed. Subscribe by copying the URL from the address - bar into your newsreader. Visit About Feeds to + bar into your newsreader. Visit About Feeds to learn more and get started. It’s free.

      - + - + - - - + C391.986,303.103,357.971,220.923,296.208,159.16z" + /> + + @@ -39,7 +65,9 @@

      -

      Description:

      +

      Description:

      Recent Posts

      @@ -49,7 +77,8 @@
      Published on + select="substring(atom:updated, 0, 17)" + />
      diff --git a/packages/docusaurus-plugin-content-blog/assets/rss.css b/packages/docusaurus-plugin-content-blog/src/assets/rss.css similarity index 100% rename from packages/docusaurus-plugin-content-blog/assets/rss.css rename to packages/docusaurus-plugin-content-blog/src/assets/rss.css diff --git a/packages/docusaurus-plugin-content-blog/assets/rss.xslt b/packages/docusaurus-plugin-content-blog/src/assets/rss.xsl similarity index 51% rename from packages/docusaurus-plugin-content-blog/assets/rss.xslt rename to packages/docusaurus-plugin-content-blog/src/assets/rss.xsl index e050f438f209..e060e1519d3f 100644 --- a/packages/docusaurus-plugin-content-blog/assets/rss.xslt +++ b/packages/docusaurus-plugin-content-blog/src/assets/rss.xsl @@ -1,6 +1,8 @@ - - + + @@ -15,22 +17,44 @@
      This is an RSS feed. Subscribe by copying the URL from the address - bar into your newsreader. Visit About Feeds to + bar into your newsreader. Visit About Feeds to learn more and get started. It’s free.

      - + - + - - - + C391.986,303.103,357.971,220.923,296.208,159.16z" + /> + + @@ -39,7 +63,9 @@

      -

      Description:

      +

      Description:

      Recent Posts

      @@ -49,11 +75,11 @@
      Published on + select="substring(pubDate,0,17)" + />
      - +
      diff --git a/packages/docusaurus-plugin-content-blog/src/options.ts b/packages/docusaurus-plugin-content-blog/src/options.ts index 25b138b23929..4f95b35db1d9 100644 --- a/packages/docusaurus-plugin-content-blog/src/options.ts +++ b/packages/docusaurus-plugin-content-blog/src/options.ts @@ -5,6 +5,7 @@ * LICENSE file in the root directory of this source tree. */ +import path from 'path'; import { Joi, RemarkPluginsSchema, @@ -75,8 +76,8 @@ export const DEFAULT_OPTIONS: PluginOptions = { // TODO export const XSLTBuiltInPaths = { - rss: 'todo path RSS xslt', - atom: 'todo path Atom xslt', + rss: path.resolve(__dirname, 'assets', 'rss.xsl'), + atom: path.resolve(__dirname, 'assets', 'atom.xsl'), }; function normalizeXsltOption( @@ -98,10 +99,7 @@ function createXLSTFilePathSchema(type: 'atom' | 'rss') { Joi.string().required(), Joi.boolean() .allow(null, () => undefined) - .custom((val) => { - console.log({val}); - return normalizeXsltOption(val, type); - }), + .custom((val) => normalizeXsltOption(val, type)), ) .optional() .default(null); From 988214daa0f81dbf15564884d45075aeaab0eaff Mon Sep 17 00:00:00 2001 From: sebastien Date: Fri, 2 Aug 2024 14:54:36 +0200 Subject: [PATCH 25/36] use .xsl extension (more common) instead of .xslt --- .../__tests__/__snapshots__/feed.test.ts.snap | 8 +-- .../src/__tests__/feed.test.ts | 6 +- .../src/feed.ts | 2 +- .../{custom-atom.xslt => custom-atom.xsl} | 57 ++++++++++++++----- .../{custom-rss.xslt => custom-rss.xsl} | 56 +++++++++++++----- 5 files changed, 92 insertions(+), 37 deletions(-) rename website/_dogfooding/_blog tests/{custom-atom.xslt => custom-atom.xsl} (53%) rename website/_dogfooding/_blog tests/{custom-rss.xslt => custom-rss.xsl} (54%) diff --git a/packages/docusaurus-plugin-content-blog/src/__tests__/__snapshots__/feed.test.ts.snap b/packages/docusaurus-plugin-content-blog/src/__tests__/__snapshots__/feed.test.ts.snap index 7ad1a8155da7..6966160fe117 100644 --- a/packages/docusaurus-plugin-content-blog/src/__tests__/__snapshots__/feed.test.ts.snap +++ b/packages/docusaurus-plugin-content-blog/src/__tests__/__snapshots__/feed.test.ts.snap @@ -237,7 +237,7 @@ h2:not(:first-child) { font-style: italic; } ", - " + " https://docusaurus.io/myBaseUrl/blog Hello Blog @@ -770,7 +770,7 @@ h2:not(:first-child) { font-style: italic; } ", - " + " https://docusaurus.io/myBaseUrl/blog Hello Blog @@ -1598,7 +1598,7 @@ h2:not(:first-child) { font-style: italic; } ", - " + " Hello Blog @@ -2104,7 +2104,7 @@ h2:not(:first-child) { font-style: italic; } ", - " + " Hello Blog diff --git a/packages/docusaurus-plugin-content-blog/src/__tests__/feed.test.ts b/packages/docusaurus-plugin-content-blog/src/__tests__/feed.test.ts index 1f452f1f8ddc..2d5d70b00b36 100644 --- a/packages/docusaurus-plugin-content-blog/src/__tests__/feed.test.ts +++ b/packages/docusaurus-plugin-content-blog/src/__tests__/feed.test.ts @@ -346,7 +346,7 @@ describe.each(['atom', 'rss', 'json'])('%s', (feedType) => { feedOptions: { type: [feedType], copyright: 'Copyright', - xslt: {rss: 'rss.xslt', atom: 'atom.xslt'}, + xslt: {rss: 'rss.xsl', atom: 'atom.xsl'}, }, readingTime: ({content, defaultReadingTime}) => defaultReadingTime({content}), @@ -393,8 +393,8 @@ describe.each(['atom', 'rss', 'json'])('%s', (feedType) => { type: [feedType], copyright: 'Copyright', xslt: { - rss: 'custom-rss.xslt', - atom: 'custom-atom.xslt', + rss: 'custom-rss.xsl', + atom: 'custom-atom.xsl', }, }, readingTime: ({content, defaultReadingTime}) => diff --git a/packages/docusaurus-plugin-content-blog/src/feed.ts b/packages/docusaurus-plugin-content-blog/src/feed.ts index daeeae72043f..b8a95116c929 100644 --- a/packages/docusaurus-plugin-content-blog/src/feed.ts +++ b/packages/docusaurus-plugin-content-blog/src/feed.ts @@ -205,7 +205,7 @@ async function transformFeedWithStylesheet({ } const fileName = path.parse(xsltFile).name; - const isDefault = xsltFile === 'rss.xslt' || xsltFile === 'atom.xslt'; + const isDefault = false; // xsltFile === 'rss.xslt' || xsltFile === 'atom.xslt'; const directoryPath = isDefault ? path.join(__dirname, '../assets/') : contentPath; diff --git a/website/_dogfooding/_blog tests/custom-atom.xslt b/website/_dogfooding/_blog tests/custom-atom.xsl similarity index 53% rename from website/_dogfooding/_blog tests/custom-atom.xslt rename to website/_dogfooding/_blog tests/custom-atom.xsl index 80406b153124..560d535302b5 100644 --- a/website/_dogfooding/_blog tests/custom-atom.xslt +++ b/website/_dogfooding/_blog tests/custom-atom.xsl @@ -1,5 +1,7 @@ - - + @@ -7,7 +9,9 @@ - Atom Feed | <xsl:value-of select="atom:feed/atom:title" /> + Atom Feed | <xsl:value-of + select="atom:feed/atom:title" + /> @@ -15,22 +19,44 @@
      This is an Atom feed. Subscribe by copying the URL from the address - bar into your newsreader. Visit About Feeds to learn more + bar into your newsreader. Visit About Feeds to learn more and get started. It’s free.

      - + viewBox="0 0 455.731 455.731" + xml:space="preserve"> - + - - - + C391.986,303.103,357.971,220.923,296.208,159.16z" + /> + + @@ -39,7 +65,9 @@

      -

      Description:

      +

      Description:

      Recent Posts

      @@ -49,7 +77,8 @@
      Published on + select="substring(atom:updated, 0, 17)" + />
      diff --git a/website/_dogfooding/_blog tests/custom-rss.xslt b/website/_dogfooding/_blog tests/custom-rss.xsl similarity index 54% rename from website/_dogfooding/_blog tests/custom-rss.xslt rename to website/_dogfooding/_blog tests/custom-rss.xsl index 4d793963cba1..dd868860c2d6 100644 --- a/website/_dogfooding/_blog tests/custom-rss.xslt +++ b/website/_dogfooding/_blog tests/custom-rss.xsl @@ -1,5 +1,7 @@ - - + @@ -15,22 +17,44 @@
      This is an RSS feed. Subscribe by copying the URL from the address - bar into your newsreader. Visit About Feeds to learn more + bar into your newsreader. Visit About Feeds to learn more and get started. It’s free.

      - + viewBox="0 0 455.731 455.731" + xml:space="preserve"> - + - - - + C391.986,303.103,357.971,220.923,296.208,159.16z" + /> + + @@ -39,7 +63,9 @@

      -

      Description:

      +

      Description:

      Recent Posts

      @@ -49,11 +75,11 @@
      Published on + select="substring(pubDate,0,17)" + />
      - +
      From 6092f1d3f84e563dc88d8ac6e1c0224737c64688 Mon Sep 17 00:00:00 2001 From: sebastien Date: Fri, 2 Aug 2024 14:54:56 +0200 Subject: [PATCH 26/36] use .xsl extension (more common) instead of .xslt --- website/_dogfooding/dogfooding.config.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/website/_dogfooding/dogfooding.config.ts b/website/_dogfooding/dogfooding.config.ts index b3abfd4d4d2c..d31bce0776d7 100644 --- a/website/_dogfooding/dogfooding.config.ts +++ b/website/_dogfooding/dogfooding.config.ts @@ -89,8 +89,8 @@ export const dogfoodingPluginInstances: PluginConfig[] = [ title: 'Docusaurus Tests Blog', copyright: `Copyright © ${new Date().getFullYear()} Facebook, Inc.`, xslt: { - rss: 'custom-rss.xslt', - atom: 'custom-atom.xslt', + rss: 'custom-rss.xsl', + atom: 'custom-atom.xsl', }, }, readingTime: ({content, frontMatter, defaultReadingTime}) => From 5f1dc945ec2d08cc8e96d2c05bcdf7d3cbe391af Mon Sep 17 00:00:00 2001 From: sebastien Date: Fri, 2 Aug 2024 16:10:34 +0200 Subject: [PATCH 27/36] use .xsl extension (more common) instead of .xslt --- .../{custom-atom.xslt => custom-atom.xsl} | 0 .../blog/{custom-rss.xslt => custom-rss.xsl} | 0 .../website/build-snap/blog/custom-atom.xsl | 65 ++++++++++++++++++ .../website/build-snap/blog/custom-rss.xsl | 66 +++++++++++++++++++ 4 files changed, 131 insertions(+) rename packages/docusaurus-plugin-content-blog/src/__tests__/__fixtures__/website/blog/{custom-atom.xslt => custom-atom.xsl} (100%) rename packages/docusaurus-plugin-content-blog/src/__tests__/__fixtures__/website/blog/{custom-rss.xslt => custom-rss.xsl} (100%) create mode 100644 packages/docusaurus-plugin-content-blog/src/__tests__/__fixtures__/website/build-snap/blog/custom-atom.xsl create mode 100644 packages/docusaurus-plugin-content-blog/src/__tests__/__fixtures__/website/build-snap/blog/custom-rss.xsl diff --git a/packages/docusaurus-plugin-content-blog/src/__tests__/__fixtures__/website/blog/custom-atom.xslt b/packages/docusaurus-plugin-content-blog/src/__tests__/__fixtures__/website/blog/custom-atom.xsl similarity index 100% rename from packages/docusaurus-plugin-content-blog/src/__tests__/__fixtures__/website/blog/custom-atom.xslt rename to packages/docusaurus-plugin-content-blog/src/__tests__/__fixtures__/website/blog/custom-atom.xsl diff --git a/packages/docusaurus-plugin-content-blog/src/__tests__/__fixtures__/website/blog/custom-rss.xslt b/packages/docusaurus-plugin-content-blog/src/__tests__/__fixtures__/website/blog/custom-rss.xsl similarity index 100% rename from packages/docusaurus-plugin-content-blog/src/__tests__/__fixtures__/website/blog/custom-rss.xslt rename to packages/docusaurus-plugin-content-blog/src/__tests__/__fixtures__/website/blog/custom-rss.xsl diff --git a/packages/docusaurus-plugin-content-blog/src/__tests__/__fixtures__/website/build-snap/blog/custom-atom.xsl b/packages/docusaurus-plugin-content-blog/src/__tests__/__fixtures__/website/build-snap/blog/custom-atom.xsl new file mode 100644 index 000000000000..80406b153124 --- /dev/null +++ b/packages/docusaurus-plugin-content-blog/src/__tests__/__fixtures__/website/build-snap/blog/custom-atom.xsl @@ -0,0 +1,65 @@ + + + + + + + + + Atom Feed | <xsl:value-of select="atom:feed/atom:title" /> + + + +
      +
      +
      + This is an Atom feed. Subscribe by copying the URL from the address + bar into your newsreader. Visit About Feeds to learn more + and get started. It’s free.
      +

      +
      + + + + + + + + + + +
      + Custom Atom Feed Preview

      +

      + +

      +

      Description:

      +
      +

      Recent Posts

      +
      + +
      + + + +
      Published on +
      +
      + +
      +
      +
      +
      +
      + + +
      + +
      diff --git a/packages/docusaurus-plugin-content-blog/src/__tests__/__fixtures__/website/build-snap/blog/custom-rss.xsl b/packages/docusaurus-plugin-content-blog/src/__tests__/__fixtures__/website/build-snap/blog/custom-rss.xsl new file mode 100644 index 000000000000..4d793963cba1 --- /dev/null +++ b/packages/docusaurus-plugin-content-blog/src/__tests__/__fixtures__/website/build-snap/blog/custom-rss.xsl @@ -0,0 +1,66 @@ + + + + + + + + + RSS Feed | <xsl:value-of select="rss/channel/title" /> + + + +
      +
      +
      + This is an RSS feed. Subscribe by copying the URL from the address + bar into your newsreader. Visit About Feeds to learn more + and get started. It’s free.
      +

      +
      + + + + + + + + + + +
      + Custom RSS Feed Preview

      +

      + +

      +

      Description:

      +
      +

      Recent Posts

      +
      + +
      + + + +
      Published on +
      +
      + +
      +
      +
      +
      +
      + + +
      + +
      From 81e80fdcfbae2cce41b37b3186c4b6d9cfe37cf8 Mon Sep 17 00:00:00 2001 From: sebastien Date: Fri, 2 Aug 2024 16:18:43 +0200 Subject: [PATCH 28/36] refactor feed xslt impl --- .../{src => }/assets/atom.css | 0 .../{src => }/assets/atom.xsl | 0 .../{src => }/assets/rss.css | 0 .../{src => }/assets/rss.xsl | 0 .../website/build-snap/blog/custom-atom.css | 76 +++++++ .../website/build-snap/blog/custom-rss.css | 76 +++++++ .../src/feed.ts | 192 +++++++++++------- .../src/options.ts | 5 +- 8 files changed, 270 insertions(+), 79 deletions(-) rename packages/docusaurus-plugin-content-blog/{src => }/assets/atom.css (100%) rename packages/docusaurus-plugin-content-blog/{src => }/assets/atom.xsl (100%) rename packages/docusaurus-plugin-content-blog/{src => }/assets/rss.css (100%) rename packages/docusaurus-plugin-content-blog/{src => }/assets/rss.xsl (100%) create mode 100644 packages/docusaurus-plugin-content-blog/src/__tests__/__fixtures__/website/build-snap/blog/custom-atom.css create mode 100644 packages/docusaurus-plugin-content-blog/src/__tests__/__fixtures__/website/build-snap/blog/custom-rss.css diff --git a/packages/docusaurus-plugin-content-blog/src/assets/atom.css b/packages/docusaurus-plugin-content-blog/assets/atom.css similarity index 100% rename from packages/docusaurus-plugin-content-blog/src/assets/atom.css rename to packages/docusaurus-plugin-content-blog/assets/atom.css diff --git a/packages/docusaurus-plugin-content-blog/src/assets/atom.xsl b/packages/docusaurus-plugin-content-blog/assets/atom.xsl similarity index 100% rename from packages/docusaurus-plugin-content-blog/src/assets/atom.xsl rename to packages/docusaurus-plugin-content-blog/assets/atom.xsl diff --git a/packages/docusaurus-plugin-content-blog/src/assets/rss.css b/packages/docusaurus-plugin-content-blog/assets/rss.css similarity index 100% rename from packages/docusaurus-plugin-content-blog/src/assets/rss.css rename to packages/docusaurus-plugin-content-blog/assets/rss.css diff --git a/packages/docusaurus-plugin-content-blog/src/assets/rss.xsl b/packages/docusaurus-plugin-content-blog/assets/rss.xsl similarity index 100% rename from packages/docusaurus-plugin-content-blog/src/assets/rss.xsl rename to packages/docusaurus-plugin-content-blog/assets/rss.xsl diff --git a/packages/docusaurus-plugin-content-blog/src/__tests__/__fixtures__/website/build-snap/blog/custom-atom.css b/packages/docusaurus-plugin-content-blog/src/__tests__/__fixtures__/website/build-snap/blog/custom-atom.css new file mode 100644 index 000000000000..c016178d9007 --- /dev/null +++ b/packages/docusaurus-plugin-content-blog/src/__tests__/__fixtures__/website/build-snap/blog/custom-atom.css @@ -0,0 +1,76 @@ +/** + * 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. + */ + +* { + color: #0d1137; +} + +main { + flex: 1 0 auto; + width: 100%; + margin: 4rem auto; + padding: 1.5 rem; + max-width: 800px; + /* stylelint-disable-next-line font-family-name-quotes */ + font-family: system-ui, -apple-system, Segoe UI, Roboto, Ubuntu, Cantarell; +} + +.info { + display: block; + margin: 3rem 0; + padding: 2rem 3rem; + border: 1px solid dodgerblue; + border-left-width: 0.5rem; + border-radius: 0.4rem; + background-color: #e52165; +} + +.rss-icon { + height: 3.8rem; + width: 3.8rem; + margin-right: 1rem; +} + +.flex { + display: flex; +} + +.items-start { + align-items: flex-start; +} + +.pb-7 { + padding-bottom: 3rem; +} + +a { + color: #005aff; + text-decoration: none; +} + +h1 { + text-wrap: balance; + font-size: 3.8rem; + line-height: 1; + font-weight: 800; + margin-bottom: 4rem; +} + +h2 { + font-size: 3rem; + line-height: 1.2; + font-weight: 700; + margin-bottom: 3rem; +} + +h2:not(:first-child) { + margin-top: 5.8rem; +} + +.italic { + font-style: italic; +} diff --git a/packages/docusaurus-plugin-content-blog/src/__tests__/__fixtures__/website/build-snap/blog/custom-rss.css b/packages/docusaurus-plugin-content-blog/src/__tests__/__fixtures__/website/build-snap/blog/custom-rss.css new file mode 100644 index 000000000000..c016178d9007 --- /dev/null +++ b/packages/docusaurus-plugin-content-blog/src/__tests__/__fixtures__/website/build-snap/blog/custom-rss.css @@ -0,0 +1,76 @@ +/** + * 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. + */ + +* { + color: #0d1137; +} + +main { + flex: 1 0 auto; + width: 100%; + margin: 4rem auto; + padding: 1.5 rem; + max-width: 800px; + /* stylelint-disable-next-line font-family-name-quotes */ + font-family: system-ui, -apple-system, Segoe UI, Roboto, Ubuntu, Cantarell; +} + +.info { + display: block; + margin: 3rem 0; + padding: 2rem 3rem; + border: 1px solid dodgerblue; + border-left-width: 0.5rem; + border-radius: 0.4rem; + background-color: #e52165; +} + +.rss-icon { + height: 3.8rem; + width: 3.8rem; + margin-right: 1rem; +} + +.flex { + display: flex; +} + +.items-start { + align-items: flex-start; +} + +.pb-7 { + padding-bottom: 3rem; +} + +a { + color: #005aff; + text-decoration: none; +} + +h1 { + text-wrap: balance; + font-size: 3.8rem; + line-height: 1; + font-weight: 800; + margin-bottom: 4rem; +} + +h2 { + font-size: 3rem; + line-height: 1.2; + font-weight: 700; + margin-bottom: 3rem; +} + +h2:not(:first-child) { + margin-top: 5.8rem; +} + +.italic { + font-style: italic; +} diff --git a/packages/docusaurus-plugin-content-blog/src/feed.ts b/packages/docusaurus-plugin-content-blog/src/feed.ts index b8a95116c929..96f252f23070 100644 --- a/packages/docusaurus-plugin-content-blog/src/feed.ts +++ b/packages/docusaurus-plugin-content-blog/src/feed.ts @@ -9,12 +9,17 @@ import path from 'path'; import fs from 'fs-extra'; import {Feed, type Author as FeedAuthor} from 'feed'; import * as srcset from 'srcset'; -import {normalizeUrl, readOutputHTMLFile} from '@docusaurus/utils'; +import { + getDataFilePath, + normalizeUrl, + readOutputHTMLFile, +} from '@docusaurus/utils'; import { blogPostContainerID, applyTrailingSlash, } from '@docusaurus/utils-common'; import {load as cheerioLoad} from 'cheerio'; +import logger from '@docusaurus/logger'; import type {BlogContentPaths} from './types'; import type {DocusaurusConfig, HtmlTags, LoadContext} from '@docusaurus/types'; import type { @@ -24,6 +29,7 @@ import type { BlogPost, BlogFeedItem, FeedOptions, + FeedXSLTOptions, } from '@docusaurus/plugin-content-blog'; async function generateBlogFeed({ @@ -181,59 +187,119 @@ async function defaultCreateFeedItems({ ); } -/** - * @description addXmlStyleSheet appends a xsl stylesheet to the generated xml feed - * @param feedDetails the feed content - * @param generatePath path where the file would be copied in website - * @param xsltFile path to the xslt file - * @param contentPaths path to the content directory - */ -async function transformFeedWithStylesheet({ - feedDetails, - generatePath, - xsltFile, - contentPaths: {contentPath}, +async function resolveXsltFilePaths({ + xsltFilePath, + contentPaths, }: { - feedDetails: string; - generatePath: string; - xsltFile: string; + xsltFilePath: string; contentPaths: BlogContentPaths; }) { - // TODO idk why there is this check - if (!feedDetails) { - return feedDetails; + const xsltAbsolutePath: string = path.isAbsolute(xsltFilePath) + ? xsltFilePath + : (await getDataFilePath({filePath: xsltFilePath, contentPaths})) ?? + path.resolve(contentPaths.contentPath, xsltFilePath); + + if (!(await fs.pathExists(xsltAbsolutePath))) { + throw new Error( + logger.interpolate`Blog feed XSLT file not found at path=${path.relative( + process.cwd(), + xsltAbsolutePath, + )}`, + ); } - const fileName = path.parse(xsltFile).name; - const isDefault = false; // xsltFile === 'rss.xslt' || xsltFile === 'atom.xslt'; - const directoryPath = isDefault - ? path.join(__dirname, '../assets/') - : contentPath; - - const xsltLink = ``; - const transformedFeed = feedDetails.replace( - '', - xsltLink, + const parsedPath = path.parse(xsltAbsolutePath); + const cssAbsolutePath = path.resolve( + parsedPath.dir, + `${parsedPath.name}.css`, ); + if (!(await fs.pathExists(xsltAbsolutePath))) { + throw new Error( + logger.interpolate`Blog feed XSLT file was found at path=${path.relative( + process.cwd(), + xsltAbsolutePath, + )} +But its expected co-located CSS file could not be found at path=${path.relative( + process.cwd(), + cssAbsolutePath, + )} +If you want to provide a custom XSLT file, you must provide a CSS file with the exact same name.`, + ); + } - const xsltPath = path.join(directoryPath, `${fileName}.xslt`); - const xsltContent = await fs.readFile(xsltPath, 'utf8'); - const xsltGeneratePath = path.join(generatePath, `${fileName}.xslt`); - await fs.outputFile(xsltGeneratePath, xsltContent, 'utf-8'); + return {xsltAbsolutePath, cssAbsolutePath}; +} - const cssPath = path.join(directoryPath, `${fileName}.css`); - const stylesheetContent = await fs.readFile(cssPath, 'utf8'); - const cssGeneratePath = path.join(generatePath, `${fileName}.css`); - await fs.outputFile(cssGeneratePath, stylesheetContent, 'utf-8'); +async function generateXsltFiles({ + xsltFilePath, + generatePath, + contentPaths, +}: { + xsltFilePath: string; + generatePath: string; + contentPaths: BlogContentPaths; +}) { + const {xsltAbsolutePath, cssAbsolutePath} = await resolveXsltFilePaths({ + xsltFilePath, + contentPaths, + }); + const xsltOutputPath = path.join( + generatePath, + path.basename(xsltAbsolutePath), + ); + const cssOutputPath = path.join(generatePath, path.basename(cssAbsolutePath)); + await fs.copy(xsltAbsolutePath, xsltOutputPath); + await fs.copy(cssAbsolutePath, cssOutputPath); +} - return transformedFeed; +// This modifies the XML feed content to add a relative href to the XSLT file +// Good enough for now: we probably don't need a full XML parser just for that +// See also https://darekkay.com/blog/rss-styling/ +function injectXslt({ + feedContent, + xsltFilePath, +}: { + feedContent: string; + xsltFilePath: string; +}) { + return feedContent.replace( + '', + ``, + ); } +const FeedConfigs: Record< + FeedType, + { + outputFileName: string; + getContent: (feed: Feed) => string; + getXsltFilePath: (xslt: FeedXSLTOptions) => string | null; + } +> = { + rss: { + outputFileName: 'rss.xml', + getContent: (feed) => feed.rss2(), + getXsltFilePath: (xslt) => xslt.rss, + }, + atom: { + outputFileName: 'atom.xml', + getContent: (feed) => feed.atom1(), + getXsltFilePath: (xslt) => xslt.atom, + }, + json: { + outputFileName: 'feed.json', + getContent: (feed) => feed.json1(), + getXsltFilePath: () => null, + }, +}; + async function createBlogFeedFile({ feed, feedType, generatePath, - feedOptions: {xslt}, + feedOptions, contentPaths, }: { feed: Feed; @@ -242,45 +308,19 @@ async function createBlogFeedFile({ feedOptions: FeedOptions; contentPaths: BlogContentPaths; }) { - const [feedContent, feedPath] = await (async () => { - switch (feedType) { - case 'rss': { - const rssFeed = feed.rss2(); - const outputPath = 'rss.xml'; - if (xslt.rss) { - const xsltFeed = await transformFeedWithStylesheet({ - feedDetails: rssFeed, - generatePath, - xsltFile: xslt.rss, - contentPaths, - }); - return [xsltFeed, outputPath]; - } - return [rssFeed, outputPath]; - } - case 'json': - return [feed.json1(), 'feed.json']; - case 'atom': { - const atomFeed = feed.atom1(); - const outputPath = 'atom.xml'; - if (xslt.atom) { - const xsltFeed = await transformFeedWithStylesheet({ - feedDetails: atomFeed, - generatePath, - xsltFile: xslt.atom, - contentPaths, - }); - return [xsltFeed, outputPath]; - } - return [atomFeed, outputPath]; - } - default: - throw new Error(`Feed type ${feedType} not supported.`); + try { + const feedConfig = FeedConfigs[feedType]; + + let feedContent = feedConfig.getContent(feed); + + const xsltFilePath = feedConfig.getXsltFilePath(feedOptions.xslt); + if (xsltFilePath) { + await generateXsltFiles({xsltFilePath, contentPaths, generatePath}); + feedContent = injectXslt({feedContent, xsltFilePath}); } - })(); - try { - await fs.outputFile(path.join(generatePath, feedPath), feedContent); + const outputPath = path.join(generatePath, feedConfig.outputFileName); + await fs.outputFile(outputPath, feedContent); } catch (err) { throw new Error(`Generating ${feedType} feed failed.`, { cause: err as Error, diff --git a/packages/docusaurus-plugin-content-blog/src/options.ts b/packages/docusaurus-plugin-content-blog/src/options.ts index 4f95b35db1d9..65b52ee31cf0 100644 --- a/packages/docusaurus-plugin-content-blog/src/options.ts +++ b/packages/docusaurus-plugin-content-blog/src/options.ts @@ -74,10 +74,9 @@ export const DEFAULT_OPTIONS: PluginOptions = { onInlineAuthors: 'warn', }; -// TODO export const XSLTBuiltInPaths = { - rss: path.resolve(__dirname, 'assets', 'rss.xsl'), - atom: path.resolve(__dirname, 'assets', 'atom.xsl'), + rss: path.resolve(__dirname, '..', 'assets', 'rss.xsl'), + atom: path.resolve(__dirname, '..', 'assets', 'atom.xsl'), }; function normalizeXsltOption( From 03647e265a3dae14a7f2f2af026551dc4f54c407 Mon Sep 17 00:00:00 2001 From: sebastien Date: Fri, 2 Aug 2024 16:44:30 +0200 Subject: [PATCH 29/36] capture blog tree snapshot --- .../package.json | 3 +- .../build-snap/blog/rss-feed.stylesheet.css | 68 -- .../__tests__/__snapshots__/feed.test.ts.snap | 918 +++++++----------- .../src/__tests__/feed.test.ts | 48 +- 4 files changed, 373 insertions(+), 664 deletions(-) delete mode 100644 packages/docusaurus-plugin-content-blog/src/__tests__/__fixtures__/website/build-snap/blog/rss-feed.stylesheet.css diff --git a/packages/docusaurus-plugin-content-blog/package.json b/packages/docusaurus-plugin-content-blog/package.json index 815413ff2cfd..ff88860d2ae4 100644 --- a/packages/docusaurus-plugin-content-blog/package.json +++ b/packages/docusaurus-plugin-content-blog/package.json @@ -59,6 +59,7 @@ "node": ">=18.0" }, "devDependencies": { - "@total-typescript/shoehorn": "^0.1.2" + "@total-typescript/shoehorn": "^0.1.2", + "tree-node-cli": "^1.6.0" } } diff --git a/packages/docusaurus-plugin-content-blog/src/__tests__/__fixtures__/website/build-snap/blog/rss-feed.stylesheet.css b/packages/docusaurus-plugin-content-blog/src/__tests__/__fixtures__/website/build-snap/blog/rss-feed.stylesheet.css deleted file mode 100644 index 2be936239e3b..000000000000 --- a/packages/docusaurus-plugin-content-blog/src/__tests__/__fixtures__/website/build-snap/blog/rss-feed.stylesheet.css +++ /dev/null @@ -1,68 +0,0 @@ -/** - * 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. - */ - -main { - flex: 1 0 auto; - width: 100%; - margin: 4rem auto; - padding: 1.5 rem; - max-width: 800px; - /* stylelint-disable-next-line font-family-name-quotes */ - font-family: system-ui, -apple-system, Segoe UI, Roboto, Ubuntu, Cantarell; -} - -.info { - display: block; - margin: 3rem 0; - padding: 2rem 3rem; - border: 1px solid dodgerblue; - border-left-width: 0.5rem; - border-radius: 0.4rem; - background-color: #edf5ff; -} - -.rss-icon { - height: 3.8rem; - width: 3.8rem; - margin-right: 1rem; -} - -.flex { - display: flex; -} - -.items-start { - align-items: flex-start; -} - -.pb-7 { - padding-bottom: 3rem; -} - -a { - color: #005aff; - text-decoration: none; -} - -h1 { - text-wrap: balance; - font-size: 3.8rem; - line-height: 1; - font-weight: 800; - margin-bottom: 4rem; -} - -h2 { - font-size: 3rem; - line-height: 1.2; - font-weight: 700; - margin-bottom: 3rem; -} - -h2:not(:first-child) { - margin-top: 5.8rem; -} diff --git a/packages/docusaurus-plugin-content-blog/src/__tests__/__snapshots__/feed.test.ts.snap b/packages/docusaurus-plugin-content-blog/src/__tests__/__snapshots__/feed.test.ts.snap index 6966160fe117..2c90688e2c56 100644 --- a/packages/docusaurus-plugin-content-blog/src/__tests__/__snapshots__/feed.test.ts.snap +++ b/packages/docusaurus-plugin-content-blog/src/__tests__/__snapshots__/feed.test.ts.snap @@ -94,150 +94,9 @@ exports[`atom filters to the first two entries using limit 1`] = ` exports[`atom has custom xslt files for feed 1`] = ` [ - " - - - - - - - - Atom Feed | <xsl:value-of select="atom:feed/atom:title" /> - - - -
      -
      -
      - This is an Atom feed. Subscribe by copying the URL from the address - bar into your newsreader. Visit About Feeds to learn more - and get started. It’s free.
      -

      -
      - - - - - - - - - - -
      - Custom Atom Feed Preview

      -

      - -

      -

      Description:

      -
      -

      Recent Posts

      -
      - -
      - - - -
      Published on -
      -
      - -
      -
      -
      -
      -
      - - -
      - -
      -", - "/** - * 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. - */ - -* { - color: #0d1137; -} - -main { - flex: 1 0 auto; - width: 100%; - margin: 4rem auto; - padding: 1.5 rem; - max-width: 800px; - /* stylelint-disable-next-line font-family-name-quotes */ - font-family: system-ui, -apple-system, Segoe UI, Roboto, Ubuntu, Cantarell; -} - -.info { - display: block; - margin: 3rem 0; - padding: 2rem 3rem; - border: 1px solid dodgerblue; - border-left-width: 0.5rem; - border-radius: 0.4rem; - background-color: #e52165; -} - -.rss-icon { - height: 3.8rem; - width: 3.8rem; - margin-right: 1rem; -} - -.flex { - display: flex; -} - -.items-start { - align-items: flex-start; -} - -.pb-7 { - padding-bottom: 3rem; -} - -a { - color: #005aff; - text-decoration: none; -} - -h1 { - text-wrap: balance; - font-size: 3.8rem; - line-height: 1; - font-weight: 800; - margin-bottom: 4rem; -} - -h2 { - font-size: 3rem; - line-height: 1.2; - font-weight: 700; - margin-bottom: 3rem; -} - -h2:not(:first-child) { - margin-top: 5.8rem; -} - -.italic { - font-style: italic; -} -", - " + [ + "/packages/docusaurus-plugin-content-blog/src/__tests__/__fixtures__/website/build-snap/blog/atom.xml", + " https://docusaurus.io/myBaseUrl/blog Hello Blog @@ -362,9 +221,63 @@ h2:not(:first-child) { ", + ], ] `; +exports[`atom has custom xslt files for feed: blog tree 1`] = ` +"blog +├── 2018 +│ └── 12 +│ └── 14 +│ └── Happy-First-Birthday-Slash +│ └── index.html +├── archive +│ └── index.html +├── atom.css +├── atom.xml +├── atom.xsl +├── blog-with-links +│ └── index.html +├── custom-atom.css +├── custom-atom.xsl +├── custom-rss.css +├── custom-rss.xsl +├── date-matter +│ └── index.html +├── feed.json +├── heading-as-title +│ └── index.html +├── hey +│ └── my super path +│ └── héllô +│ └── index.html +├── index.html +├── mdx-blog-post +│ └── index.html +├── mdx-require-blog-post +│ └── index.html +├── page +│ ├── 2 +│ │ └── index.html +│ └── 3 +│ └── index.html +├── rss.css +├── rss.xml +├── rss.xsl +├── simple +│ └── slug +│ └── index.html +├── tags +│ ├── complex +│ │ └── index.html +│ ├── date +│ │ └── index.html +│ └── index.html +└── unlisted + └── index.html" +`; + exports[`atom has feed item for each post - with trailing slash 1`] = ` [ " @@ -627,150 +540,9 @@ exports[`atom has feed item for each post 1`] = ` exports[`atom has xslt files for feed 1`] = ` [ - " - - - - - - - - Atom Feed | <xsl:value-of select="atom:feed/atom:title" /> - - - -
      -
      -
      - This is an Atom feed. Subscribe by copying the URL from the address - bar into your newsreader. Visit About Feeds to - learn more and get started. It’s free.
      -

      -
      - - - - - - - - - - -
      - Atom Feed Preview

      -

      - -

      -

      Description:

      -
      -

      Recent Posts

      -
      - -
      - - - -
      Published on -
      -
      - -
      -
      -
      -
      -
      - - -
      - -
      -", - "/** - * 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. - */ - -* { - color: #0d1137; -} - -main { - flex: 1 0 auto; - width: 100%; - margin: 4rem auto; - padding: 1.5 rem; - max-width: 800px; - /* stylelint-disable-next-line font-family-name-quotes */ - font-family: system-ui, -apple-system, Segoe UI, Roboto, Ubuntu, Cantarell; -} - -.info { - display: block; - margin: 3rem 0; - padding: 2rem 3rem; - border: 1px solid dodgerblue; - border-left-width: 0.5rem; - border-radius: 0.4rem; - background-color: #edf5ff; -} - -.rss-icon { - height: 3.8rem; - width: 3.8rem; - margin-right: 1rem; -} - -.flex { - display: flex; -} - -.items-start { - align-items: flex-start; -} - -.pb-7 { - padding-bottom: 3rem; -} - -a { - color: #005aff; - text-decoration: none; -} - -h1 { - text-wrap: balance; - font-size: 3.8rem; - line-height: 1; - font-weight: 800; - margin-bottom: 4rem; -} - -h2 { - font-size: 3rem; - line-height: 1.2; - font-weight: 700; - margin-bottom: 3rem; -} - -h2:not(:first-child) { - margin-top: 5.8rem; -} - -.italic { - font-style: italic; -} -", - " + [ + "/packages/docusaurus-plugin-content-blog/src/__tests__/__fixtures__/website/build-snap/blog/atom.xml", + " https://docusaurus.io/myBaseUrl/blog Hello Blog @@ -895,9 +667,63 @@ h2:not(:first-child) { ", + ], ] `; +exports[`atom has xslt files for feed: blog tree 1`] = ` +"blog +├── 2018 +│ └── 12 +│ └── 14 +│ └── Happy-First-Birthday-Slash +│ └── index.html +├── archive +│ └── index.html +├── atom.css +├── atom.xml +├── atom.xsl +├── blog-with-links +│ └── index.html +├── custom-atom.css +├── custom-atom.xsl +├── custom-rss.css +├── custom-rss.xsl +├── date-matter +│ └── index.html +├── feed.json +├── heading-as-title +│ └── index.html +├── hey +│ └── my super path +│ └── héllô +│ └── index.html +├── index.html +├── mdx-blog-post +│ └── index.html +├── mdx-require-blog-post +│ └── index.html +├── page +│ ├── 2 +│ │ └── index.html +│ └── 3 +│ └── index.html +├── rss.css +├── rss.xml +├── rss.xsl +├── simple +│ └── slug +│ └── index.html +├── tags +│ ├── complex +│ │ └── index.html +│ ├── date +│ │ └── index.html +│ └── index.html +└── unlisted + └── index.html" +`; + exports[`json filters to the first two entries 1`] = ` [ "{ @@ -962,7 +788,9 @@ exports[`json filters to the first two entries using limit 1`] = ` exports[`json has custom xslt files for feed 1`] = ` [ - "{ + [ + "/packages/docusaurus-plugin-content-blog/src/__tests__/__fixtures__/website/build-snap/blog/feed.json", + "{ "version": "https://jsonfeed.org/version/1", "title": "Hello Blog", "home_page_url": "https://docusaurus.io/myBaseUrl/blog", @@ -1056,9 +884,63 @@ exports[`json has custom xslt files for feed 1`] = ` } ] }", + ], ] `; +exports[`json has custom xslt files for feed: blog tree 1`] = ` +"blog +├── 2018 +│ └── 12 +│ └── 14 +│ └── Happy-First-Birthday-Slash +│ └── index.html +├── archive +│ └── index.html +├── atom.css +├── atom.xml +├── atom.xsl +├── blog-with-links +│ └── index.html +├── custom-atom.css +├── custom-atom.xsl +├── custom-rss.css +├── custom-rss.xsl +├── date-matter +│ └── index.html +├── feed.json +├── heading-as-title +│ └── index.html +├── hey +│ └── my super path +│ └── héllô +│ └── index.html +├── index.html +├── mdx-blog-post +│ └── index.html +├── mdx-require-blog-post +│ └── index.html +├── page +│ ├── 2 +│ │ └── index.html +│ └── 3 +│ └── index.html +├── rss.css +├── rss.xml +├── rss.xsl +├── simple +│ └── slug +│ └── index.html +├── tags +│ ├── complex +│ │ └── index.html +│ ├── date +│ │ └── index.html +│ └── index.html +└── unlisted + └── index.html" +`; + exports[`json has feed item for each post - with trailing slash 1`] = ` [ "{ @@ -1259,7 +1141,9 @@ exports[`json has feed item for each post 1`] = ` exports[`json has xslt files for feed 1`] = ` [ - "{ + [ + "/packages/docusaurus-plugin-content-blog/src/__tests__/__fixtures__/website/build-snap/blog/feed.json", + "{ "version": "https://jsonfeed.org/version/1", "title": "Hello Blog", "home_page_url": "https://docusaurus.io/myBaseUrl/blog", @@ -1353,9 +1237,63 @@ exports[`json has xslt files for feed 1`] = ` } ] }", + ], ] `; +exports[`json has xslt files for feed: blog tree 1`] = ` +"blog +├── 2018 +│ └── 12 +│ └── 14 +│ └── Happy-First-Birthday-Slash +│ └── index.html +├── archive +│ └── index.html +├── atom.css +├── atom.xml +├── atom.xsl +├── blog-with-links +│ └── index.html +├── custom-atom.css +├── custom-atom.xsl +├── custom-rss.css +├── custom-rss.xsl +├── date-matter +│ └── index.html +├── feed.json +├── heading-as-title +│ └── index.html +├── hey +│ └── my super path +│ └── héllô +│ └── index.html +├── index.html +├── mdx-blog-post +│ └── index.html +├── mdx-require-blog-post +│ └── index.html +├── page +│ ├── 2 +│ │ └── index.html +│ └── 3 +│ └── index.html +├── rss.css +├── rss.xml +├── rss.xsl +├── simple +│ └── slug +│ └── index.html +├── tags +│ ├── complex +│ │ └── index.html +│ ├── date +│ │ └── index.html +│ └── index.html +└── unlisted + └── index.html" +`; + exports[`rss filters to the first two entries 1`] = ` [ " @@ -1454,151 +1392,9 @@ exports[`rss filters to the first two entries using limit 1`] = ` exports[`rss has custom xslt files for feed 1`] = ` [ - " - - - - - - - - RSS Feed | <xsl:value-of select="rss/channel/title" /> - - - -
      -
      -
      - This is an RSS feed. Subscribe by copying the URL from the address - bar into your newsreader. Visit About Feeds to learn more - and get started. It’s free.
      -

      -
      - - - - - - - - - - -
      - Custom RSS Feed Preview

      -

      - -

      -

      Description:

      -
      -

      Recent Posts

      -
      - -
      - - - -
      Published on -
      -
      - -
      -
      -
      -
      -
      - - -
      - -
      -", - "/** - * 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. - */ - -* { - color: #0d1137; -} - -main { - flex: 1 0 auto; - width: 100%; - margin: 4rem auto; - padding: 1.5 rem; - max-width: 800px; - /* stylelint-disable-next-line font-family-name-quotes */ - font-family: system-ui, -apple-system, Segoe UI, Roboto, Ubuntu, Cantarell; -} - -.info { - display: block; - margin: 3rem 0; - padding: 2rem 3rem; - border: 1px solid dodgerblue; - border-left-width: 0.5rem; - border-radius: 0.4rem; - background-color: #e52165; -} - -.rss-icon { - height: 3.8rem; - width: 3.8rem; - margin-right: 1rem; -} - -.flex { - display: flex; -} - -.items-start { - align-items: flex-start; -} - -.pb-7 { - padding-bottom: 3rem; -} - -a { - color: #005aff; - text-decoration: none; -} - -h1 { - text-wrap: balance; - font-size: 3.8rem; - line-height: 1; - font-weight: 800; - margin-bottom: 4rem; -} - -h2 { - font-size: 3rem; - line-height: 1.2; - font-weight: 700; - margin-bottom: 3rem; -} - -h2:not(:first-child) { - margin-top: 5.8rem; -} - -.italic { - font-style: italic; -} -", - " + [ + "/packages/docusaurus-plugin-content-blog/src/__tests__/__fixtures__/website/build-snap/blog/rss.xml", + " Hello Blog @@ -1715,9 +1511,63 @@ h2:not(:first-child) { ", + ], ] `; +exports[`rss has custom xslt files for feed: blog tree 1`] = ` +"blog +├── 2018 +│ └── 12 +│ └── 14 +│ └── Happy-First-Birthday-Slash +│ └── index.html +├── archive +│ └── index.html +├── atom.css +├── atom.xml +├── atom.xsl +├── blog-with-links +│ └── index.html +├── custom-atom.css +├── custom-atom.xsl +├── custom-rss.css +├── custom-rss.xsl +├── date-matter +│ └── index.html +├── feed.json +├── heading-as-title +│ └── index.html +├── hey +│ └── my super path +│ └── héllô +│ └── index.html +├── index.html +├── mdx-blog-post +│ └── index.html +├── mdx-require-blog-post +│ └── index.html +├── page +│ ├── 2 +│ │ └── index.html +│ └── 3 +│ └── index.html +├── rss.css +├── rss.xml +├── rss.xsl +├── simple +│ └── slug +│ └── index.html +├── tags +│ ├── complex +│ │ └── index.html +│ ├── date +│ │ └── index.html +│ └── index.html +└── unlisted + └── index.html" +`; + exports[`rss has feed item for each post - with trailing slash 1`] = ` [ " @@ -1964,147 +1814,9 @@ exports[`rss has feed item for each post 1`] = ` exports[`rss has xslt files for feed 1`] = ` [ - " - - - - - - - - RSS Feed | <xsl:value-of select="rss/channel/title" /> - - - -
      -
      -
      - This is an RSS feed. Subscribe by copying the URL from the address - bar into your newsreader. Visit About Feeds to - learn more and get started. It’s free.
      -

      -
      - - - - - - - - - - -
      - RSS Feed Preview

      -

      - -

      -

      Description:

      -
      -

      Recent Posts

      -
      - -
      - - - -
      Published on -
      -
      - -
      -
      -
      -
      -
      - - -
      - -
      -", - "/** - * 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. - */ - -main { - flex: 1 0 auto; - width: 100%; - margin: 4rem auto; - padding: 1.5 rem; - max-width: 800px; - /* stylelint-disable-next-line font-family-name-quotes */ - font-family: system-ui, -apple-system, Segoe UI, Roboto, Ubuntu, Cantarell; -} - -.info { - display: block; - margin: 3rem 0; - padding: 2rem 3rem; - border: 1px solid dodgerblue; - border-left-width: 0.5rem; - border-radius: 0.4rem; - background-color: #edf5ff; -} - -.rss-icon { - height: 3.8rem; - width: 3.8rem; - margin-right: 1rem; -} - -.flex { - display: flex; -} - -.items-start { - align-items: flex-start; -} - -.pb-7 { - padding-bottom: 3rem; -} - -a { - color: #005aff; - text-decoration: none; -} - -h1 { - text-wrap: balance; - font-size: 3.8rem; - line-height: 1; - font-weight: 800; - margin-bottom: 4rem; -} - -h2 { - font-size: 3rem; - line-height: 1.2; - font-weight: 700; - margin-bottom: 3rem; -} - -h2:not(:first-child) { - margin-top: 5.8rem; -} - -.italic { - font-style: italic; -} -", - " + [ + "/packages/docusaurus-plugin-content-blog/src/__tests__/__fixtures__/website/build-snap/blog/rss.xml", + " Hello Blog @@ -2221,5 +1933,59 @@ h2:not(:first-child) { ", + ], ] `; + +exports[`rss has xslt files for feed: blog tree 1`] = ` +"blog +├── 2018 +│ └── 12 +│ └── 14 +│ └── Happy-First-Birthday-Slash +│ └── index.html +├── archive +│ └── index.html +├── atom.css +├── atom.xml +├── atom.xsl +├── blog-with-links +│ └── index.html +├── custom-atom.css +├── custom-atom.xsl +├── custom-rss.css +├── custom-rss.xsl +├── date-matter +│ └── index.html +├── feed.json +├── heading-as-title +│ └── index.html +├── hey +│ └── my super path +│ └── héllô +│ └── index.html +├── index.html +├── mdx-blog-post +│ └── index.html +├── mdx-require-blog-post +│ └── index.html +├── page +│ ├── 2 +│ │ └── index.html +│ └── 3 +│ └── index.html +├── rss.css +├── rss.xml +├── rss.xsl +├── simple +│ └── slug +│ └── index.html +├── tags +│ ├── complex +│ │ └── index.html +│ ├── date +│ │ └── index.html +│ └── index.html +└── unlisted + └── index.html" +`; diff --git a/packages/docusaurus-plugin-content-blog/src/__tests__/feed.test.ts b/packages/docusaurus-plugin-content-blog/src/__tests__/feed.test.ts index 2d5d70b00b36..3cca6f94aaf9 100644 --- a/packages/docusaurus-plugin-content-blog/src/__tests__/feed.test.ts +++ b/packages/docusaurus-plugin-content-blog/src/__tests__/feed.test.ts @@ -10,13 +10,15 @@ import path from 'path'; import fs from 'fs-extra'; import {DEFAULT_PARSE_FRONT_MATTER} from '@docusaurus/utils'; import {fromPartial} from '@total-typescript/shoehorn'; -import {DEFAULT_OPTIONS} from '../options'; +import {normalizePluginOptions} from '@docusaurus/utils-validation'; +import tree from 'tree-node-cli'; +import {DEFAULT_OPTIONS, validateOptions} from '../options'; import {generateBlogPosts} from '../blogUtils'; import {createBlogFeedFiles} from '../feed'; import {getAuthorsMap} from '../authorsMap'; -import type {LoadContext, I18n} from '@docusaurus/types'; +import type {LoadContext, I18n, Validate} from '@docusaurus/types'; import type {BlogContentPaths} from '../types'; -import type {PluginOptions} from '@docusaurus/plugin-content-blog'; +import type {Options, PluginOptions} from '@docusaurus/plugin-content-blog'; const DefaultI18N: I18n = { currentLocale: 'en', @@ -50,8 +52,16 @@ function getBlogContentPaths(siteDir: string): BlogContentPaths { async function testGenerateFeeds( context: LoadContext, - options: PluginOptions, + optionsInput: Options, ): Promise { + const options = validateOptions({ + validate: normalizePluginOptions as Validate< + Options | undefined, + PluginOptions + >, + options: optionsInput, + }); + const contentPaths = getBlogContentPaths(context.siteDir); const authorsMap = await getAuthorsMap({ contentPaths, @@ -76,7 +86,7 @@ async function testGenerateFeeds( }); } -describe.each(['atom', 'rss', 'json'])('%s', (feedType) => { +describe.each(['atom', 'rss', 'json'] as const)('%s', (feedType) => { const fsMock = jest.spyOn(fs, 'outputFile').mockImplementation(() => {}); it('does not get generated without posts', async () => { @@ -113,7 +123,7 @@ describe.each(['atom', 'rss', 'json'])('%s', (feedType) => { truncateMarker: //, onInlineTags: 'ignore', onInlineAuthors: 'ignore', - } as PluginOptions, + }, ); expect(fsMock).toHaveBeenCalledTimes(0); @@ -157,7 +167,7 @@ describe.each(['atom', 'rss', 'json'])('%s', (feedType) => { truncateMarker: //, onInlineTags: 'ignore', onInlineAuthors: 'ignore', - } as PluginOptions, + }, ); expect( @@ -213,7 +223,7 @@ describe.each(['atom', 'rss', 'json'])('%s', (feedType) => { truncateMarker: //, onInlineTags: 'ignore', onInlineAuthors: 'ignore', - } as PluginOptions, + }, ); expect( @@ -260,7 +270,7 @@ describe.each(['atom', 'rss', 'json'])('%s', (feedType) => { truncateMarker: //, onInlineTags: 'ignore', onInlineAuthors: 'ignore', - } as PluginOptions, + }, ); expect( @@ -307,7 +317,7 @@ describe.each(['atom', 'rss', 'json'])('%s', (feedType) => { truncateMarker: //, onInlineTags: 'ignore', onInlineAuthors: 'ignore', - } as PluginOptions, + }, ); expect( @@ -346,19 +356,19 @@ describe.each(['atom', 'rss', 'json'])('%s', (feedType) => { feedOptions: { type: [feedType], copyright: 'Copyright', - xslt: {rss: 'rss.xsl', atom: 'atom.xsl'}, + xslt: true, }, readingTime: ({content, defaultReadingTime}) => defaultReadingTime({content}), truncateMarker: //, onInlineTags: 'ignore', onInlineAuthors: 'ignore', - } as PluginOptions, + }, ); - expect( - fsMock.mock.calls.map((call) => call[1] as string), - ).toMatchSnapshot(); + expect(tree(path.join(outDir, 'blog'))).toMatchSnapshot('blog tree'); + + expect(fsMock.mock.calls).toMatchSnapshot(); fsMock.mockClear(); }); @@ -402,12 +412,12 @@ describe.each(['atom', 'rss', 'json'])('%s', (feedType) => { truncateMarker: //, onInlineTags: 'ignore', onInlineAuthors: 'ignore', - } as PluginOptions, + }, ); - expect( - fsMock.mock.calls.map((call) => call[1] as string), - ).toMatchSnapshot(); + expect(tree(path.join(outDir, 'blog'))).toMatchSnapshot('blog tree'); + + expect(fsMock.mock.calls).toMatchSnapshot(); fsMock.mockClear(); }); }); From 7d2c181330538110fae80b640105c672f7045bd6 Mon Sep 17 00:00:00 2001 From: sebastien Date: Fri, 2 Aug 2024 16:50:30 +0200 Subject: [PATCH 30/36] add extra comment + missing build snap files --- .../website/build-snap/blog/atom.css | 76 +++++++++++++++ .../website/build-snap/blog/atom.xsl | 94 +++++++++++++++++++ .../website/build-snap/blog/rss.css | 72 ++++++++++++++ .../website/build-snap/blog/rss.xsl | 92 ++++++++++++++++++ .../src/plugin-content-blog.d.ts | 1 + 5 files changed, 335 insertions(+) create mode 100644 packages/docusaurus-plugin-content-blog/src/__tests__/__fixtures__/website/build-snap/blog/atom.css create mode 100644 packages/docusaurus-plugin-content-blog/src/__tests__/__fixtures__/website/build-snap/blog/atom.xsl create mode 100644 packages/docusaurus-plugin-content-blog/src/__tests__/__fixtures__/website/build-snap/blog/rss.css create mode 100644 packages/docusaurus-plugin-content-blog/src/__tests__/__fixtures__/website/build-snap/blog/rss.xsl diff --git a/packages/docusaurus-plugin-content-blog/src/__tests__/__fixtures__/website/build-snap/blog/atom.css b/packages/docusaurus-plugin-content-blog/src/__tests__/__fixtures__/website/build-snap/blog/atom.css new file mode 100644 index 000000000000..2d5975b1b3f8 --- /dev/null +++ b/packages/docusaurus-plugin-content-blog/src/__tests__/__fixtures__/website/build-snap/blog/atom.css @@ -0,0 +1,76 @@ +/** + * 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. + */ + +* { + color: #0d1137; +} + +main { + flex: 1 0 auto; + width: 100%; + margin: 4rem auto; + padding: 1.5 rem; + max-width: 800px; + /* stylelint-disable-next-line font-family-name-quotes */ + font-family: system-ui, -apple-system, Segoe UI, Roboto, Ubuntu, Cantarell; +} + +.info { + display: block; + margin: 3rem 0; + padding: 2rem 3rem; + border: 1px solid dodgerblue; + border-left-width: 0.5rem; + border-radius: 0.4rem; + background-color: #edf5ff; +} + +.rss-icon { + height: 3.8rem; + width: 3.8rem; + margin-right: 1rem; +} + +.flex { + display: flex; +} + +.items-start { + align-items: flex-start; +} + +.pb-7 { + padding-bottom: 3rem; +} + +a { + color: #005aff; + text-decoration: none; +} + +h1 { + text-wrap: balance; + font-size: 3.8rem; + line-height: 1; + font-weight: 800; + margin-bottom: 4rem; +} + +h2 { + font-size: 3rem; + line-height: 1.2; + font-weight: 700; + margin-bottom: 3rem; +} + +h2:not(:first-child) { + margin-top: 5.8rem; +} + +.italic { + font-style: italic; +} diff --git a/packages/docusaurus-plugin-content-blog/src/__tests__/__fixtures__/website/build-snap/blog/atom.xsl b/packages/docusaurus-plugin-content-blog/src/__tests__/__fixtures__/website/build-snap/blog/atom.xsl new file mode 100644 index 000000000000..2bd08fbd8de6 --- /dev/null +++ b/packages/docusaurus-plugin-content-blog/src/__tests__/__fixtures__/website/build-snap/blog/atom.xsl @@ -0,0 +1,94 @@ + + + + + + + + + Atom Feed | <xsl:value-of + select="atom:feed/atom:title" + /> + + + +
      +
      +
      + This is an Atom feed. Subscribe by copying the URL from the address + bar into your newsreader. Visit About Feeds to + learn more and get started. It’s free.
      +

      +
      + + + + + + + + + + +
      + Atom Feed Preview

      +

      + +

      +

      Description:

      +
      +

      Recent Posts

      +
      + +
      + + + +
      Published on +
      +
      + +
      +
      +
      +
      +
      + + +
      + +
      diff --git a/packages/docusaurus-plugin-content-blog/src/__tests__/__fixtures__/website/build-snap/blog/rss.css b/packages/docusaurus-plugin-content-blog/src/__tests__/__fixtures__/website/build-snap/blog/rss.css new file mode 100644 index 000000000000..17d483670f0d --- /dev/null +++ b/packages/docusaurus-plugin-content-blog/src/__tests__/__fixtures__/website/build-snap/blog/rss.css @@ -0,0 +1,72 @@ +/** + * 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. + */ + +main { + flex: 1 0 auto; + width: 100%; + margin: 4rem auto; + padding: 1.5 rem; + max-width: 800px; + /* stylelint-disable-next-line font-family-name-quotes */ + font-family: system-ui, -apple-system, Segoe UI, Roboto, Ubuntu, Cantarell; +} + +.info { + display: block; + margin: 3rem 0; + padding: 2rem 3rem; + border: 1px solid dodgerblue; + border-left-width: 0.5rem; + border-radius: 0.4rem; + background-color: #edf5ff; +} + +.rss-icon { + height: 3.8rem; + width: 3.8rem; + margin-right: 1rem; +} + +.flex { + display: flex; +} + +.items-start { + align-items: flex-start; +} + +.pb-7 { + padding-bottom: 3rem; +} + +a { + color: #005aff; + text-decoration: none; +} + +h1 { + text-wrap: balance; + font-size: 3.8rem; + line-height: 1; + font-weight: 800; + margin-bottom: 4rem; +} + +h2 { + font-size: 3rem; + line-height: 1.2; + font-weight: 700; + margin-bottom: 3rem; +} + +h2:not(:first-child) { + margin-top: 5.8rem; +} + +.italic { + font-style: italic; +} diff --git a/packages/docusaurus-plugin-content-blog/src/__tests__/__fixtures__/website/build-snap/blog/rss.xsl b/packages/docusaurus-plugin-content-blog/src/__tests__/__fixtures__/website/build-snap/blog/rss.xsl new file mode 100644 index 000000000000..e060e1519d3f --- /dev/null +++ b/packages/docusaurus-plugin-content-blog/src/__tests__/__fixtures__/website/build-snap/blog/rss.xsl @@ -0,0 +1,92 @@ + + + + + + + + + RSS Feed | <xsl:value-of select="rss/channel/title" /> + + + +
      +
      +
      + This is an RSS feed. Subscribe by copying the URL from the address + bar into your newsreader. Visit About Feeds to + learn more and get started. It’s free.
      +

      +
      + + + + + + + + + + +
      + RSS Feed Preview

      +

      + +

      +

      Description:

      +
      +

      Recent Posts

      +
      + +
      + + + +
      Published on +
      +
      + +
      +
      +
      +
      +
      + + +
      + +
      diff --git a/packages/docusaurus-plugin-content-blog/src/plugin-content-blog.d.ts b/packages/docusaurus-plugin-content-blog/src/plugin-content-blog.d.ts index 6ad8b04a7406..1bf1c12687b1 100644 --- a/packages/docusaurus-plugin-content-blog/src/plugin-content-blog.d.ts +++ b/packages/docusaurus-plugin-content-blog/src/plugin-content-blog.d.ts @@ -531,6 +531,7 @@ declare module '@docusaurus/plugin-content-blog' { { /** Type of feed to be generated. Use `null` to disable generation. */ type?: FeedOptions['type'] | 'all' | FeedType; + /** User-provided XSLT config for feeds, un-normalized */ xslt?: | boolean | null From d1a99ab74bda023fd386f1da1e7333a90e333d06 Mon Sep 17 00:00:00 2001 From: sebastien Date: Fri, 2 Aug 2024 16:53:13 +0200 Subject: [PATCH 31/36] cspell ignore .xsl --- .cspell.json | 1 + 1 file changed, 1 insertion(+) diff --git a/.cspell.json b/.cspell.json index 8fc5b569d4ae..82ebc2c41a41 100644 --- a/.cspell.json +++ b/.cspell.json @@ -32,6 +32,7 @@ "website/_dogfooding/_pages tests/diagrams.mdx", "*.xyz", "*.docx", + "*.xsl", "*.xslt", "*.gitignore", "versioned_docs", From 8c9e3747879a4d98a9a578b2ceb4d8acd175ebb8 Mon Sep 17 00:00:00 2001 From: sebastien Date: Fri, 2 Aug 2024 17:05:32 +0200 Subject: [PATCH 32/36] add xslt to project words --- project-words.txt | 2 ++ 1 file changed, 2 insertions(+) diff --git a/project-words.txt b/project-words.txt index 528d635318ee..8ff86be90d0e 100644 --- a/project-words.txt +++ b/project-words.txt @@ -412,6 +412,8 @@ webpackbar webstorm Wolcott Xplorer +xslt +XSLT XSOAR Yacop yangshun From c421e3ba3160b38fce1ed96ff51ceaf8ec8fb6d6 Mon Sep 17 00:00:00 2001 From: sebastien Date: Fri, 2 Aug 2024 17:06:53 +0200 Subject: [PATCH 33/36] fix bad spelling --- .../src/__tests__/options.test.ts | 30 +++++++++---------- .../src/options.ts | 6 ++-- 2 files changed, 18 insertions(+), 18 deletions(-) diff --git a/packages/docusaurus-plugin-content-blog/src/__tests__/options.test.ts b/packages/docusaurus-plugin-content-blog/src/__tests__/options.test.ts index 31cd7f5575a6..254d56b96b2a 100644 --- a/packages/docusaurus-plugin-content-blog/src/__tests__/options.test.ts +++ b/packages/docusaurus-plugin-content-blog/src/__tests__/options.test.ts @@ -165,104 +165,104 @@ describe('validateOptions', () => { return testValidate({feedOptions: {xslt}}).feedOptions.xslt; } - it('accepts xlst: true', () => { + it('accepts xslt: true', () => { expect(testXSLT(true)).toEqual({ rss: XSLTBuiltInPaths.rss, atom: XSLTBuiltInPaths.atom, }); }); - it('accepts xlst: false', () => { + it('accepts xslt: false', () => { expect(testXSLT(false)).toEqual({ rss: null, atom: null, }); }); - it('accepts xlst: null', () => { + it('accepts xslt: null', () => { expect(testXSLT(null)).toEqual({ rss: null, atom: null, }); }); - it('accepts xlst: undefined', () => { + it('accepts xslt: undefined', () => { expect(testXSLT(undefined)).toEqual({ rss: null, atom: null, }); }); - it('accepts xlst: {rss: true}', () => { + it('accepts xslt: {rss: true}', () => { expect(testXSLT({rss: true})).toEqual({ rss: XSLTBuiltInPaths.rss, atom: null, }); }); - it('accepts xlst: {atom: true}', () => { + it('accepts xslt: {atom: true}', () => { expect(testXSLT({atom: true})).toEqual({ rss: null, atom: XSLTBuiltInPaths.atom, }); }); - it('accepts xlst: {rss: true, atom: true}', () => { + it('accepts xslt: {rss: true, atom: true}', () => { expect(testXSLT({rss: true, atom: true})).toEqual({ rss: XSLTBuiltInPaths.rss, atom: XSLTBuiltInPaths.atom, }); }); - it('accepts xlst: {rss: "custom-path"}', () => { + it('accepts xslt: {rss: "custom-path"}', () => { expect(testXSLT({rss: 'custom-path'})).toEqual({ rss: 'custom-path', atom: null, }); }); - it('accepts xlst: {rss: true, atom: "custom-path"}', () => { + it('accepts xslt: {rss: true, atom: "custom-path"}', () => { expect(testXSLT({rss: true, atom: 'custom-path'})).toEqual({ rss: XSLTBuiltInPaths.rss, atom: 'custom-path', }); }); - it('accepts xlst: {rss: null, atom: true}', () => { + it('accepts xslt: {rss: null, atom: true}', () => { expect(testXSLT({rss: null, atom: true})).toEqual({ rss: null, atom: XSLTBuiltInPaths.atom, }); }); - it('accepts xlst: {rss: false, atom: null}', () => { + it('accepts xslt: {rss: false, atom: null}', () => { expect(testXSLT({rss: false, atom: null})).toEqual({ rss: null, atom: null, }); }); - it('rejects xlst: 42', () => { + it('rejects xslt: 42', () => { // @ts-expect-error: bad type expect(() => testXSLT(42)).toThrowErrorMatchingInlineSnapshot( `""feedOptions.xslt" must be one of [object, boolean]"`, ); }); - it('rejects xlst: []', () => { + it('rejects xslt: []', () => { // @ts-expect-error: bad type expect(() => testXSLT([])).toThrowErrorMatchingInlineSnapshot( `""feedOptions.xslt" must be one of [object, boolean]"`, ); }); - it('rejects xlst: {rss: 42}', () => { + it('rejects xslt: {rss: 42}', () => { // @ts-expect-error: bad type expect(() => testXSLT({rss: 42})).toThrowErrorMatchingInlineSnapshot( `""feedOptions.xslt.rss" must be one of [string, boolean]"`, ); }); - it('rejects xlst: {rss: []}', () => { + it('rejects xslt: {rss: []}', () => { // @ts-expect-error: bad type expect(() => testXSLT({rss: 42})).toThrowErrorMatchingInlineSnapshot( `""feedOptions.xslt.rss" must be one of [string, boolean]"`, diff --git a/packages/docusaurus-plugin-content-blog/src/options.ts b/packages/docusaurus-plugin-content-blog/src/options.ts index 65b52ee31cf0..e9d91d3bf449 100644 --- a/packages/docusaurus-plugin-content-blog/src/options.ts +++ b/packages/docusaurus-plugin-content-blog/src/options.ts @@ -92,7 +92,7 @@ function normalizeXsltOption( return null; } -function createXLSTFilePathSchema(type: 'atom' | 'rss') { +function createXSLTFilePathSchema(type: 'atom' | 'rss') { return Joi.alternatives() .try( Joi.string().required(), @@ -107,8 +107,8 @@ function createXLSTFilePathSchema(type: 'atom' | 'rss') { const FeedXSLTOptionsSchema = Joi.alternatives() .try( Joi.object({ - rss: createXLSTFilePathSchema('rss'), - atom: createXLSTFilePathSchema('atom'), + rss: createXSLTFilePathSchema('rss'), + atom: createXSLTFilePathSchema('atom'), }).required(), Joi.boolean() .allow(null, () => undefined) From cbb91f9c4ea076778f6570656814d1bb522a33f2 Mon Sep 17 00:00:00 2001 From: sebastien Date: Fri, 2 Aug 2024 18:18:43 +0200 Subject: [PATCH 34/36] Polish Blog feed default XSL/CSS --- .../assets/atom.css | 69 +++++++++---------- .../assets/atom.xsl | 64 +++++++++-------- .../assets/rss.css | 65 ++++++++--------- .../assets/rss.xsl | 62 ++++++++--------- website/docusaurus.config.ts | 2 + 5 files changed, 129 insertions(+), 133 deletions(-) diff --git a/packages/docusaurus-plugin-content-blog/assets/atom.css b/packages/docusaurus-plugin-content-blog/assets/atom.css index 2d5975b1b3f8..d2fc20b27416 100644 --- a/packages/docusaurus-plugin-content-blog/assets/atom.css +++ b/packages/docusaurus-plugin-content-blog/assets/atom.css @@ -5,15 +5,10 @@ * LICENSE file in the root directory of this source tree. */ -* { - color: #0d1137; -} - main { flex: 1 0 auto; width: 100%; - margin: 4rem auto; - padding: 1.5 rem; + margin: 2rem auto; max-width: 800px; /* stylelint-disable-next-line font-family-name-quotes */ font-family: system-ui, -apple-system, Segoe UI, Roboto, Ubuntu, Cantarell; @@ -21,32 +16,14 @@ main { .info { display: block; - margin: 3rem 0; - padding: 2rem 3rem; + margin: 2rem 0; + padding: 1.6rem 2.4rem; border: 1px solid dodgerblue; border-left-width: 0.5rem; border-radius: 0.4rem; background-color: #edf5ff; } -.rss-icon { - height: 3.8rem; - width: 3.8rem; - margin-right: 1rem; -} - -.flex { - display: flex; -} - -.items-start { - align-items: flex-start; -} - -.pb-7 { - padding-bottom: 3rem; -} - a { color: #005aff; text-decoration: none; @@ -54,23 +31,45 @@ a { h1 { text-wrap: balance; - font-size: 3.8rem; - line-height: 1; + font-size: 3.4rem; font-weight: 800; - margin-bottom: 4rem; + margin-bottom: 2rem; + display: flex; + align-items: center; +} + +h1 .rss-icon { + height: 3.2rem; + width: 3.2rem; + margin-right: 1rem; } h2 { - font-size: 3rem; - line-height: 1.2; + font-size: 2.2rem; font-weight: 700; - margin-bottom: 3rem; + margin-bottom: 0.2rem; } -h2:not(:first-child) { - margin-top: 5.8rem; +h3 { + font-size: 1.8rem; + font-weight: 700; + margin-bottom: 0.1rem; +} + +.blog-description { + font-size: 1.4rem; + margin-bottom: 0.6rem; } -.italic { +.blog-post-date { + font-size: 1rem; + line-height: 1.4rem; font-style: italic; + color: #797b7e; +} + +.blog-post-description { + font-size: 1rem; + line-height: 1.4rem; + color: #434349; } diff --git a/packages/docusaurus-plugin-content-blog/assets/atom.xsl b/packages/docusaurus-plugin-content-blog/assets/atom.xsl index 2bd08fbd8de6..271895cf7775 100644 --- a/packages/docusaurus-plugin-content-blog/assets/atom.xsl +++ b/packages/docusaurus-plugin-content-blog/assets/atom.xsl @@ -3,7 +3,6 @@ version="3.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:atom="http://www.w3.org/2005/Atom"> - @@ -18,11 +17,12 @@
      - This is an Atom feed. Subscribe by copying the URL from the address - bar into your newsreader. Visit About Feeds to - learn more and get started. It’s free.
      -

      + This is an Atom feed. Subscribe by copying the URL + from the address bar into your newsreader. Visit + About Feeds to learn more + and get started. It’s free. +

      +

      - - + - - + - - - - + +
      - Atom Feed Preview

      -

      -

      -

      Description:

      + +

      + +

      Recent Posts

      -
      +
      -
      - - - -
      Published on +

      + -
      +
      @@ -90,5 +89,4 @@ - diff --git a/packages/docusaurus-plugin-content-blog/assets/rss.css b/packages/docusaurus-plugin-content-blog/assets/rss.css index 17d483670f0d..d2fc20b27416 100644 --- a/packages/docusaurus-plugin-content-blog/assets/rss.css +++ b/packages/docusaurus-plugin-content-blog/assets/rss.css @@ -8,8 +8,7 @@ main { flex: 1 0 auto; width: 100%; - margin: 4rem auto; - padding: 1.5 rem; + margin: 2rem auto; max-width: 800px; /* stylelint-disable-next-line font-family-name-quotes */ font-family: system-ui, -apple-system, Segoe UI, Roboto, Ubuntu, Cantarell; @@ -17,32 +16,14 @@ main { .info { display: block; - margin: 3rem 0; - padding: 2rem 3rem; + margin: 2rem 0; + padding: 1.6rem 2.4rem; border: 1px solid dodgerblue; border-left-width: 0.5rem; border-radius: 0.4rem; background-color: #edf5ff; } -.rss-icon { - height: 3.8rem; - width: 3.8rem; - margin-right: 1rem; -} - -.flex { - display: flex; -} - -.items-start { - align-items: flex-start; -} - -.pb-7 { - padding-bottom: 3rem; -} - a { color: #005aff; text-decoration: none; @@ -50,23 +31,45 @@ a { h1 { text-wrap: balance; - font-size: 3.8rem; - line-height: 1; + font-size: 3.4rem; font-weight: 800; - margin-bottom: 4rem; + margin-bottom: 2rem; + display: flex; + align-items: center; +} + +h1 .rss-icon { + height: 3.2rem; + width: 3.2rem; + margin-right: 1rem; } h2 { - font-size: 3rem; - line-height: 1.2; + font-size: 2.2rem; font-weight: 700; - margin-bottom: 3rem; + margin-bottom: 0.2rem; } -h2:not(:first-child) { - margin-top: 5.8rem; +h3 { + font-size: 1.8rem; + font-weight: 700; + margin-bottom: 0.1rem; } -.italic { +.blog-description { + font-size: 1.4rem; + margin-bottom: 0.6rem; +} + +.blog-post-date { + font-size: 1rem; + line-height: 1.4rem; font-style: italic; + color: #797b7e; +} + +.blog-post-description { + font-size: 1rem; + line-height: 1.4rem; + color: #434349; } diff --git a/packages/docusaurus-plugin-content-blog/assets/rss.xsl b/packages/docusaurus-plugin-content-blog/assets/rss.xsl index e060e1519d3f..e9695b298468 100644 --- a/packages/docusaurus-plugin-content-blog/assets/rss.xsl +++ b/packages/docusaurus-plugin-content-blog/assets/rss.xsl @@ -3,7 +3,6 @@ version="3.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:atom="http://www.w3.org/2005/Atom"> - @@ -16,11 +15,12 @@
      - This is an RSS feed. Subscribe by copying the URL from the address - bar into your newsreader. Visit About Feeds to - learn more and get started. It’s free.
      -

      + This is an RSS feed. Subscribe by copying the URL + from the address bar into your newsreader. Visit + About Feeds to learn more + and get started. It’s free. +

      +

      - - + - - + - - - - + +
      - RSS Feed Preview

      -

      -

      -

      Description:

      + +

      + +

      Recent Posts

      -
      +
      -
      - - - -
      Published on +
      +

      + -
      +
      @@ -88,5 +83,4 @@ - diff --git a/website/docusaurus.config.ts b/website/docusaurus.config.ts index 56d24ea441c7..26a3e265f0af 100644 --- a/website/docusaurus.config.ts +++ b/website/docusaurus.config.ts @@ -487,6 +487,8 @@ export default async function createConfigAsync() { postsPerPage: 5, feedOptions: { type: 'all', + description: + 'Keep up to date with upcoming Docusaurus releases and articles by following our feed!', copyright: `Copyright © ${new Date().getFullYear()} Facebook, Inc.`, xslt: true, }, From 221e695125543d6d692b3b9376c6e0a3e1737902 Mon Sep 17 00:00:00 2001 From: sebastien Date: Fri, 2 Aug 2024 18:41:37 +0200 Subject: [PATCH 35/36] add docs for FeedXSLTOptions --- .../src/plugin-content-blog.d.ts | 16 ++++++++------- .../docs/api/plugins/plugin-content-blog.mdx | 20 +++++++++++++++++++ website/docs/blog.mdx | 11 +++++++++- 3 files changed, 39 insertions(+), 8 deletions(-) diff --git a/packages/docusaurus-plugin-content-blog/src/plugin-content-blog.d.ts b/packages/docusaurus-plugin-content-blog/src/plugin-content-blog.d.ts index 1bf1c12687b1..02e98f0b1e3b 100644 --- a/packages/docusaurus-plugin-content-blog/src/plugin-content-blog.d.ts +++ b/packages/docusaurus-plugin-content-blog/src/plugin-content-blog.d.ts @@ -523,6 +523,14 @@ declare module '@docusaurus/plugin-content-blog' { onInlineAuthors: 'ignore' | 'log' | 'warn' | 'throw'; }; + export type UserFeedXSLTOptions = + | boolean + | null + | { + rss?: string | boolean | null; + atom?: string | boolean | null; + }; + /** * Feed options, as provided by user config. `type` accepts `all` as shortcut */ @@ -532,13 +540,7 @@ declare module '@docusaurus/plugin-content-blog' { /** Type of feed to be generated. Use `null` to disable generation. */ type?: FeedOptions['type'] | 'all' | FeedType; /** User-provided XSLT config for feeds, un-normalized */ - xslt?: - | boolean - | null - | { - rss?: string | boolean | null; - atom?: string | boolean | null; - }; + xslt?: UserFeedXSLTOptions; } >; /** diff --git a/website/docs/api/plugins/plugin-content-blog.mdx b/website/docs/api/plugins/plugin-content-blog.mdx index 3ad31c590296..9b2d50d96d2e 100644 --- a/website/docs/api/plugins/plugin-content-blog.mdx +++ b/website/docs/api/plugins/plugin-content-blog.mdx @@ -77,6 +77,7 @@ Accepted fields: | `feedOptions.title` | `string` | `siteConfig.title` | Title of the feed. | | `feedOptions.description` | `string` | \`$\{siteConfig.title} Blog\` | Description of the feed. | | `feedOptions.copyright` | `string` | `undefined` | Copyright message. | +| `feedOptions.xslt` | boolean \| [FeedXSLTOptions](#FeedXSLTOptions) | `undefined` | Copyright message. | | `feedOptions.language` | `string` (See [documentation](http://www.w3.org/TR/REC-html40/struct/dirlang.html#langcodes) for possible values) | `undefined` | Language metadata of the feed. | | `sortPosts` | 'descending' \| 'ascending' | `'descending'` | Governs the direction of blog post sorting. | | `processBlogPosts` | [ProcessBlogPostsFn](#ProcessBlogPostsFn) | `undefined` | An optional function which can be used to transform blog posts (filter, modify, delete, etc...). | @@ -129,6 +130,25 @@ type ReadingTimeFn = (params: { type FeedType = 'rss' | 'atom' | 'json'; ``` +#### `FeedXSLTOptions` {#FeedXSLTOptions} + +Permits to style the blog XML feeds so that browsers render them nicely with [XSLT](https://developer.mozilla.org/en-US/docs/Web/XSLT). + +- Use `true` to let the blog use its built-in `.xsl` and `.css` files to style the blog feed +- Use a falsy value (`undefined | null | false`) to disable the feature +- Use a `string` to provide a file path to a custom `.xsl` file relative to the blog content folder. By convention, you must provide a `.css` file with the exact same name. + +```ts +type FeedXSLTOptions = + | boolean + | undefined + | null + | { + rss?: string | boolean | null | undefined; + atom?: string | boolean | null | undefined; + }; +``` + #### `CreateFeedItemsFn` {#CreateFeedItemsFn} ```ts diff --git a/website/docs/blog.mdx b/website/docs/blog.mdx index e6cf18644e98..468e42f3b929 100644 --- a/website/docs/blog.mdx +++ b/website/docs/blog.mdx @@ -602,9 +602,18 @@ type BlogOptions = { title?: string; description?: string; copyright: string; + language?: string; // possible values: http://www.w3.org/TR/REC-html40/struct/dirlang.html#langcodes limit?: number | false | null; // defaults to 20 - /** Allow control over the construction of BlogFeedItems */ + // XSLT permits browsers to style and render nicely the feed XML files + xslt?: + | boolean + | { + // + rss?: string | boolean; + atom?: string | boolean; + }; + // Allow control over the construction of BlogFeedItems createFeedItems?: (params: { blogPosts: BlogPost[]; siteConfig: DocusaurusConfig; From 3e5531440a5a0e21dd2adb6659f79b39b2347105 Mon Sep 17 00:00:00 2001 From: sebastien Date: Fri, 2 Aug 2024 18:42:11 +0200 Subject: [PATCH 36/36] update test snapshots --- .../website/build-snap/blog/atom.css | 69 +++++++++---------- .../website/build-snap/blog/atom.xsl | 64 +++++++++-------- .../website/build-snap/blog/rss.css | 65 ++++++++--------- .../website/build-snap/blog/rss.xsl | 62 ++++++++--------- 4 files changed, 127 insertions(+), 133 deletions(-) diff --git a/packages/docusaurus-plugin-content-blog/src/__tests__/__fixtures__/website/build-snap/blog/atom.css b/packages/docusaurus-plugin-content-blog/src/__tests__/__fixtures__/website/build-snap/blog/atom.css index 2d5975b1b3f8..d2fc20b27416 100644 --- a/packages/docusaurus-plugin-content-blog/src/__tests__/__fixtures__/website/build-snap/blog/atom.css +++ b/packages/docusaurus-plugin-content-blog/src/__tests__/__fixtures__/website/build-snap/blog/atom.css @@ -5,15 +5,10 @@ * LICENSE file in the root directory of this source tree. */ -* { - color: #0d1137; -} - main { flex: 1 0 auto; width: 100%; - margin: 4rem auto; - padding: 1.5 rem; + margin: 2rem auto; max-width: 800px; /* stylelint-disable-next-line font-family-name-quotes */ font-family: system-ui, -apple-system, Segoe UI, Roboto, Ubuntu, Cantarell; @@ -21,32 +16,14 @@ main { .info { display: block; - margin: 3rem 0; - padding: 2rem 3rem; + margin: 2rem 0; + padding: 1.6rem 2.4rem; border: 1px solid dodgerblue; border-left-width: 0.5rem; border-radius: 0.4rem; background-color: #edf5ff; } -.rss-icon { - height: 3.8rem; - width: 3.8rem; - margin-right: 1rem; -} - -.flex { - display: flex; -} - -.items-start { - align-items: flex-start; -} - -.pb-7 { - padding-bottom: 3rem; -} - a { color: #005aff; text-decoration: none; @@ -54,23 +31,45 @@ a { h1 { text-wrap: balance; - font-size: 3.8rem; - line-height: 1; + font-size: 3.4rem; font-weight: 800; - margin-bottom: 4rem; + margin-bottom: 2rem; + display: flex; + align-items: center; +} + +h1 .rss-icon { + height: 3.2rem; + width: 3.2rem; + margin-right: 1rem; } h2 { - font-size: 3rem; - line-height: 1.2; + font-size: 2.2rem; font-weight: 700; - margin-bottom: 3rem; + margin-bottom: 0.2rem; } -h2:not(:first-child) { - margin-top: 5.8rem; +h3 { + font-size: 1.8rem; + font-weight: 700; + margin-bottom: 0.1rem; +} + +.blog-description { + font-size: 1.4rem; + margin-bottom: 0.6rem; } -.italic { +.blog-post-date { + font-size: 1rem; + line-height: 1.4rem; font-style: italic; + color: #797b7e; +} + +.blog-post-description { + font-size: 1rem; + line-height: 1.4rem; + color: #434349; } diff --git a/packages/docusaurus-plugin-content-blog/src/__tests__/__fixtures__/website/build-snap/blog/atom.xsl b/packages/docusaurus-plugin-content-blog/src/__tests__/__fixtures__/website/build-snap/blog/atom.xsl index 2bd08fbd8de6..271895cf7775 100644 --- a/packages/docusaurus-plugin-content-blog/src/__tests__/__fixtures__/website/build-snap/blog/atom.xsl +++ b/packages/docusaurus-plugin-content-blog/src/__tests__/__fixtures__/website/build-snap/blog/atom.xsl @@ -3,7 +3,6 @@ version="3.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:atom="http://www.w3.org/2005/Atom"> - @@ -18,11 +17,12 @@
      - This is an Atom feed. Subscribe by copying the URL from the address - bar into your newsreader. Visit About Feeds to - learn more and get started. It’s free.
      -

      + This is an Atom feed. Subscribe by copying the URL + from the address bar into your newsreader. Visit + About Feeds to learn more + and get started. It’s free. +

      +

      - - + - - + - - - - + +
      - Atom Feed Preview

      -

      -

      -

      Description:

      + +

      + +

      Recent Posts

      -
      +
      -
      - - - -
      Published on +

      + -
      +
      @@ -90,5 +89,4 @@ - diff --git a/packages/docusaurus-plugin-content-blog/src/__tests__/__fixtures__/website/build-snap/blog/rss.css b/packages/docusaurus-plugin-content-blog/src/__tests__/__fixtures__/website/build-snap/blog/rss.css index 17d483670f0d..d2fc20b27416 100644 --- a/packages/docusaurus-plugin-content-blog/src/__tests__/__fixtures__/website/build-snap/blog/rss.css +++ b/packages/docusaurus-plugin-content-blog/src/__tests__/__fixtures__/website/build-snap/blog/rss.css @@ -8,8 +8,7 @@ main { flex: 1 0 auto; width: 100%; - margin: 4rem auto; - padding: 1.5 rem; + margin: 2rem auto; max-width: 800px; /* stylelint-disable-next-line font-family-name-quotes */ font-family: system-ui, -apple-system, Segoe UI, Roboto, Ubuntu, Cantarell; @@ -17,32 +16,14 @@ main { .info { display: block; - margin: 3rem 0; - padding: 2rem 3rem; + margin: 2rem 0; + padding: 1.6rem 2.4rem; border: 1px solid dodgerblue; border-left-width: 0.5rem; border-radius: 0.4rem; background-color: #edf5ff; } -.rss-icon { - height: 3.8rem; - width: 3.8rem; - margin-right: 1rem; -} - -.flex { - display: flex; -} - -.items-start { - align-items: flex-start; -} - -.pb-7 { - padding-bottom: 3rem; -} - a { color: #005aff; text-decoration: none; @@ -50,23 +31,45 @@ a { h1 { text-wrap: balance; - font-size: 3.8rem; - line-height: 1; + font-size: 3.4rem; font-weight: 800; - margin-bottom: 4rem; + margin-bottom: 2rem; + display: flex; + align-items: center; +} + +h1 .rss-icon { + height: 3.2rem; + width: 3.2rem; + margin-right: 1rem; } h2 { - font-size: 3rem; - line-height: 1.2; + font-size: 2.2rem; font-weight: 700; - margin-bottom: 3rem; + margin-bottom: 0.2rem; } -h2:not(:first-child) { - margin-top: 5.8rem; +h3 { + font-size: 1.8rem; + font-weight: 700; + margin-bottom: 0.1rem; } -.italic { +.blog-description { + font-size: 1.4rem; + margin-bottom: 0.6rem; +} + +.blog-post-date { + font-size: 1rem; + line-height: 1.4rem; font-style: italic; + color: #797b7e; +} + +.blog-post-description { + font-size: 1rem; + line-height: 1.4rem; + color: #434349; } diff --git a/packages/docusaurus-plugin-content-blog/src/__tests__/__fixtures__/website/build-snap/blog/rss.xsl b/packages/docusaurus-plugin-content-blog/src/__tests__/__fixtures__/website/build-snap/blog/rss.xsl index e060e1519d3f..e9695b298468 100644 --- a/packages/docusaurus-plugin-content-blog/src/__tests__/__fixtures__/website/build-snap/blog/rss.xsl +++ b/packages/docusaurus-plugin-content-blog/src/__tests__/__fixtures__/website/build-snap/blog/rss.xsl @@ -3,7 +3,6 @@ version="3.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:atom="http://www.w3.org/2005/Atom"> - @@ -16,11 +15,12 @@
      - This is an RSS feed. Subscribe by copying the URL from the address - bar into your newsreader. Visit About Feeds to - learn more and get started. It’s free.
      -

      + This is an RSS feed. Subscribe by copying the URL + from the address bar into your newsreader. Visit + About Feeds to learn more + and get started. It’s free. +

      +

      - - + - - + - - - - + +
      - RSS Feed Preview

      -

      -

      -

      Description:

      + +

      + +

      Recent Posts

      -
      +
      -
      - - - -
      Published on +
      +

      + -
      +
      @@ -88,5 +83,4 @@ -