From b6079568c85401b9dc3dede6c980d6ef67882647 Mon Sep 17 00:00:00 2001 From: VinceCYLiao Date: Wed, 19 Jul 2023 00:26:31 +0800 Subject: [PATCH 01/19] fix: #9136:fix(content-blog): links in feed should be absolute --- packages/docusaurus-plugin-content-blog/src/feed.ts | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/packages/docusaurus-plugin-content-blog/src/feed.ts b/packages/docusaurus-plugin-content-blog/src/feed.ts index dc9a7b85f84c..9efc84e16ccf 100644 --- a/packages/docusaurus-plugin-content-blog/src/feed.ts +++ b/packages/docusaurus-plugin-content-blog/src/feed.ts @@ -106,6 +106,14 @@ async function defaultCreateFeedItems({ const $ = cheerioLoad(content); const link = normalizeUrl([siteUrl, permalink]); + + $(`div#${blogPostContainerID} a`).each((_, elm) => { + const {href} = elm.attribs; + if (href) { + elm.attribs.href = String(new URL(href, link)); + } + }); + const feedItem: BlogFeedItem = { title: metadataTitle, id: link, From a339fc9f8142e9595eeeefd69f8f95798081dd22 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=94=BF=E5=AE=87=20=E5=BB=96?= Date: Wed, 19 Jul 2023 16:15:33 +0800 Subject: [PATCH 02/19] feat: add test to check if links in feed are resolved correctly (+2 squashed commits) Squashed commits: [2db488373] chore: add a new file to test href resolving [6c18ceaa4] docs: added to test if href resolved correctly in feed --- .../website/blog/blog-with-links.md | 11 + .../blog/blog-with-links/index.html | 21 ++ .../__tests__/__snapshots__/feed.test.ts.snap | 357 ++++++++++++++++-- .../src/__tests__/feed.test.ts | 130 ++++++- .../src/feed.ts | 2 +- .../_dogfooding/_blog tests/2023-07-19-a.mdx | 9 + .../_dogfooding/_blog tests/2023-07-19-b.mdx | 1 + 7 files changed, 501 insertions(+), 30 deletions(-) create mode 100644 packages/docusaurus-plugin-content-blog/src/__tests__/__fixtures__/website/blog/blog-with-links.md create mode 100644 packages/docusaurus-plugin-content-blog/src/__tests__/__fixtures__/website/build-snap/blog/blog-with-links/index.html create mode 100644 website/_dogfooding/_blog tests/2023-07-19-a.mdx create mode 100644 website/_dogfooding/_blog tests/2023-07-19-b.mdx diff --git a/packages/docusaurus-plugin-content-blog/src/__tests__/__fixtures__/website/blog/blog-with-links.md b/packages/docusaurus-plugin-content-blog/src/__tests__/__fixtures__/website/blog/blog-with-links.md new file mode 100644 index 000000000000..651c4cbe5525 --- /dev/null +++ b/packages/docusaurus-plugin-content-blog/src/__tests__/__fixtures__/website/blog/blog-with-links.md @@ -0,0 +1,11 @@ +--- +title: 'Test if href in feed resolved correctly' +--- + +[absolute full url](https://github.com/facebook/docusaurus) + +[absolute url with implicit domain name](/tests/blog/2023/07/19/b) + +[relative url](2023-07-19-b.mdx) + +[anchor](#title) diff --git a/packages/docusaurus-plugin-content-blog/src/__tests__/__fixtures__/website/build-snap/blog/blog-with-links/index.html b/packages/docusaurus-plugin-content-blog/src/__tests__/__fixtures__/website/build-snap/blog/blog-with-links/index.html new file mode 100644 index 000000000000..3ba7d0584081 --- /dev/null +++ b/packages/docusaurus-plugin-content-blog/src/__tests__/__fixtures__/website/build-snap/blog/blog-with-links/index.html @@ -0,0 +1,21 @@ + + + + + +Test if href in feed resolved correctly | Docusaurus blog only! + + + + + + + + + + + + \ No newline at end of file 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 ae568922d131..1033b98702b6 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 @@ -1,17 +1,28 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP -exports[`atom filters to the first two entries 1`] = ` +exports[`Test defaultCreateFeedItems links in feeds are resolved correctly 1`] = ` [ " https://docusaurus.io/myBaseUrl/blog Hello Blog - 2021-03-06T00:00:00.000Z + 2023-07-19T08:15:33.000Z https://github.com/jpmonette/feed Hello Blog https://docusaurus.io/myBaseUrl/image/favicon.ico Copyright + + <![CDATA[Test if href in feed resolved correctly]]> + https://docusaurus.io/myBaseUrl/blog/blog-with-links + + 2023-07-19T08:15:33.000Z + + absolute full url

+

absolute url with implicit domain name

+

relative url

+

anchor

]]>
+
<![CDATA[MDX Blog Sample with require calls]]> https://docusaurus.io/myBaseUrl/blog/mdx-require-blog-post @@ -26,7 +37,267 @@ exports[`atom filters to the first two entries 1`] = ` 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

linkimage

]]>
+ 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

linkimage

]]>
+
+ + <![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!

]]>
+ + Yangshun Tay (translated) + + + Sébastien Lorber (translated) + lorber.sebastien@gmail.com + +
+
", + " + + + Hello Blog + https://docusaurus.io/myBaseUrl/blog + Hello Blog + Wed, 19 Jul 2023 08:15:33 GMT + https://validator.w3.org/feed/docs/rss2.html + https://github.com/jpmonette/feed + en + Copyright + + <![CDATA[Test if href in feed resolved correctly]]> + https://docusaurus.io/myBaseUrl/blog/blog-with-links + https://docusaurus.io/myBaseUrl/blog/blog-with-links + Wed, 19 Jul 2023 08:15:33 GMT + + absolute full url

+

absolute url with implicit domain name

+

relative url

+

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

linkimage

]]>
+
+ + <![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!

]]>
+ lorber.sebastien@gmail.com (Sébastien Lorber (translated)) +
+
+
", + "{ + "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 url with implicit domain name

/n

relative url

/n

anchor

", + "url": "https://docusaurus.io/myBaseUrl/blog/blog-with-links", + "title": "Test if href in feed resolved correctly", + "summary": "absolute full url", + "date_modified": "2023-07-19T08:15:33.000Z", + "tags": [] + }, + { + "id": "https://docusaurus.io/myBaseUrl/blog/mdx-require-blog-post", + "content_html": "

Test MDX with require calls

", + "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

HTML Heading 2

HTML Paragraph

Import DOM

Heading 1

Heading 2

Heading 3

Heading 4

Heading 5

Normal Text Italics Text Bold Text

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!

", + "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[`atom filters to the first two entries 1`] = ` +[ + " + + https://docusaurus.io/myBaseUrl/blog + Hello Blog + 2023-07-19T08:15:33.000Z + https://github.com/jpmonette/feed + + Hello Blog + https://docusaurus.io/myBaseUrl/image/favicon.ico + Copyright + + <![CDATA[Test if href in feed resolved correctly]]> + https://docusaurus.io/myBaseUrl/blog/blog-with-links + + 2023-07-19T08:15:33.000Z + + absolute full url

+

absolute url with implicit domain name

+

relative url

+

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

]]>
", ] @@ -38,12 +309,23 @@ exports[`atom has feed item for each post 1`] = ` https://docusaurus.io/myBaseUrl/blog Hello Blog - 2021-03-06T00:00:00.000Z + 2023-07-19T08:15:33.000Z https://github.com/jpmonette/feed Hello Blog https://docusaurus.io/myBaseUrl/image/favicon.ico Copyright + + <![CDATA[Test if href in feed resolved correctly]]> + https://docusaurus.io/myBaseUrl/blog/blog-with-links + + 2023-07-19T08:15:33.000Z + + absolute full url

+

absolute url with implicit domain name

+

relative url

+

anchor

]]>
+
<![CDATA[MDX Blog Sample with require calls]]> https://docusaurus.io/myBaseUrl/blog/mdx-require-blog-post @@ -58,7 +340,7 @@ exports[`atom has feed item for each post 1`] = ` 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

linkimage

]]>
+ 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

linkimage

]]>
<![CDATA[Complex Slug]]> @@ -124,6 +406,15 @@ exports[`json filters to the first two entries 1`] = ` "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 url with implicit domain name

/n

relative url

/n

anchor

", + "url": "https://docusaurus.io/myBaseUrl/blog/blog-with-links", + "title": "Test if href in feed resolved correctly", + "summary": "absolute full url", + "date_modified": "2023-07-19T08:15:33.000Z", + "tags": [] + }, { "id": "https://docusaurus.io/myBaseUrl/blog/mdx-require-blog-post", "content_html": "

Test MDX with require calls

", @@ -132,15 +423,6 @@ exports[`json filters to the first two entries 1`] = ` "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

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\\"

", - "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": [] } ] }", @@ -155,6 +437,15 @@ exports[`json has feed item for each post 1`] = ` "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 url with implicit domain name

/n

relative url

/n

anchor

", + "url": "https://docusaurus.io/myBaseUrl/blog/blog-with-links", + "title": "Test if href in feed resolved correctly", + "summary": "absolute full url", + "date_modified": "2023-07-19T08:15:33.000Z", + "tags": [] + }, { "id": "https://docusaurus.io/myBaseUrl/blog/mdx-require-blog-post", "content_html": "

Test MDX with require calls

", @@ -166,7 +457,7 @@ exports[`json has feed item for each post 1`] = ` }, { "id": "https://docusaurus.io/myBaseUrl/blog/mdx-blog-post", - "content_html": "

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\\"

", + "content_html": "

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\\"

", "url": "https://docusaurus.io/myBaseUrl/blog/mdx-blog-post", "title": "Full Blog Sample", "summary": "HTML Heading 1", @@ -242,11 +533,22 @@ exports[`rss filters to the first two entries 1`] = ` Hello Blog https://docusaurus.io/myBaseUrl/blog Hello Blog - Sat, 06 Mar 2021 00:00:00 GMT + Wed, 19 Jul 2023 08:15:33 GMT https://validator.w3.org/feed/docs/rss2.html https://github.com/jpmonette/feed en Copyright + + <![CDATA[Test if href in feed resolved correctly]]> + https://docusaurus.io/myBaseUrl/blog/blog-with-links + https://docusaurus.io/myBaseUrl/blog/blog-with-links + Wed, 19 Jul 2023 08:15:33 GMT + + absolute full url

+

absolute url with implicit domain name

+

relative url

+

anchor

]]>
+
<![CDATA[MDX Blog Sample with require calls]]> https://docusaurus.io/myBaseUrl/blog/mdx-require-blog-post @@ -255,14 +557,6 @@ exports[`rss filters to the first two entries 1`] = ` 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

linkimage

]]>
-
", ] @@ -276,11 +570,22 @@ exports[`rss has feed item for each post 1`] = ` Hello Blog https://docusaurus.io/myBaseUrl/blog Hello Blog - Sat, 06 Mar 2021 00:00:00 GMT + Wed, 19 Jul 2023 08:15:33 GMT https://validator.w3.org/feed/docs/rss2.html https://github.com/jpmonette/feed en Copyright + + <![CDATA[Test if href in feed resolved correctly]]> + https://docusaurus.io/myBaseUrl/blog/blog-with-links + https://docusaurus.io/myBaseUrl/blog/blog-with-links + Wed, 19 Jul 2023 08:15:33 GMT + + absolute full url

+

absolute url with implicit domain name

+

relative url

+

anchor

]]>
+
<![CDATA[MDX Blog Sample with require calls]]> https://docusaurus.io/myBaseUrl/blog/mdx-require-blog-post @@ -295,7 +600,7 @@ exports[`rss has feed item for each post 1`] = ` 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

linkimage

]]>
+ 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

linkimage

]]>
<![CDATA[Complex Slug]]> 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 6592c09d7aa5..d98961e3868e 100644 --- a/packages/docusaurus-plugin-content-blog/src/__tests__/feed.test.ts +++ b/packages/docusaurus-plugin-content-blog/src/__tests__/feed.test.ts @@ -8,12 +8,18 @@ import {jest} from '@jest/globals'; import path from 'path'; import fs from 'fs-extra'; +import {load as cheerioLoad} from 'cheerio'; +import {readOutputHTMLFile} from '@docusaurus/utils'; +import {blogPostContainerID} from '@docusaurus/utils-common'; import {DEFAULT_OPTIONS} from '../options'; import {generateBlogPosts} from '../blogUtils'; -import {createBlogFeedFiles} from '../feed'; -import type {LoadContext, I18n} from '@docusaurus/types'; +import { + createBlogFeedFiles, + defaultCreateFeedItems as feedDefaultCreateFeedItems, +} from '../feed'; +import type {LoadContext, I18n, DocusaurusConfig} from '@docusaurus/types'; import type {BlogContentPaths} from '../types'; -import type {PluginOptions} from '@docusaurus/plugin-content-blog'; +import type {BlogPost, PluginOptions} from '@docusaurus/plugin-content-blog'; const DefaultI18N: I18n = { currentLocale: 'en', @@ -62,6 +68,32 @@ async function testGenerateFeeds( }); } +function isFullAbsolutePath(str: string) { + const domain = 'https://domain.com'; + const {origin} = new URL(str, domain); + return origin !== domain; +} + +async function generateLinksOfBlogPosts(outDir: string, blogPosts: BlogPost[]) { + const linksOfBlogPosts: {[postId: string]: string[]} = {}; + const pathOfFile = path.join(outDir, 'blog'); + const promises = blogPosts.map(async (post) => { + try { + const content = await readOutputHTMLFile(post.id, pathOfFile, true); + const $ = cheerioLoad(content); + const anchorElements = $(`div#${blogPostContainerID} a`); + if (anchorElements.length > 0) { + const href = anchorElements.map((_, elm) => elm.attribs.href).toArray(); + linksOfBlogPosts[post.id] = href; + } + } catch { + // post is a draft + } + }); + await Promise.all(promises); + return linksOfBlogPosts; +} + describe.each(['atom', 'rss', 'json'])('%s', (feedType) => { const fsMock = jest.spyOn(fs, 'outputFile').mockImplementation(() => {}); @@ -196,3 +228,95 @@ describe.each(['atom', 'rss', 'json'])('%s', (feedType) => { fsMock.mockClear(); }); }); + +describe('Test defaultCreateFeedItems', () => { + const fsMock = jest.spyOn(fs, 'outputFile').mockImplementation(() => {}); + it('links in feeds are resolved correctly', 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', + } as DocusaurusConfig; + + const context = { + siteDir, + siteConfig, + i18n: DefaultI18N, + outDir, + } as LoadContext; + + const options = { + path: 'blog', + routeBasePath: 'blog', + tagsBasePath: 'tags', + authorsMapPath: 'authors.yml', + include: DEFAULT_OPTIONS.include, + exclude: DEFAULT_OPTIONS.exclude, + feedOptions: { + type: ['atom', 'rss', 'json'], + copyright: 'Copyright', + }, + readingTime: ({content, defaultReadingTime}) => + defaultReadingTime({content}), + truncateMarker: //, + } as PluginOptions; + + const blogPosts = await generateBlogPosts( + getBlogContentPaths(siteDir), + context, + options, + ); + + await createBlogFeedFiles({ + blogPosts, + options, + siteConfig: context.siteConfig, + outDir: context.outDir, + locale: 'en', + }); + + const originalLinksInBlogs: {[id: string]: Array} = + await generateLinksOfBlogPosts(outDir, blogPosts); + + const blogPostsWithLinks = blogPosts.filter( + (post) => originalLinksInBlogs[post.id], + ); + + const feedsWithLinks = await feedDefaultCreateFeedItems({ + blogPosts: blogPostsWithLinks, + siteConfig, + outDir, + }); + + feedsWithLinks.forEach((feed) => { + const $ = cheerioLoad(feed.content ?? ''); + const linksInFeed = $('a') + .map((_, elm) => elm.attribs.href) + .toArray(); + const idOfBlogPost = feed.id!.replace( + new URL(`${siteConfig.baseUrl}blog`, siteConfig.url).href, + '', + ); + const originalLinksInBlog = originalLinksInBlogs[idOfBlogPost]; + const {permalink = ''} = + blogPostsWithLinks.find((post) => post.id === idOfBlogPost)?.metadata || + {}; + + originalLinksInBlog!.forEach((originalLinkInBlog, idx) => { + const linkToTest = isFullAbsolutePath(originalLinkInBlog) + ? originalLinkInBlog + : new URL(originalLinkInBlog, new URL(permalink, siteConfig.url)) + .href; + + expect(linkToTest).toEqual(linksInFeed[idx]); + }); + }); + 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 9efc84e16ccf..df0da93f5ce5 100644 --- a/packages/docusaurus-plugin-content-blog/src/feed.ts +++ b/packages/docusaurus-plugin-content-blog/src/feed.ts @@ -70,7 +70,7 @@ async function generateBlogFeed({ return feed; } -async function defaultCreateFeedItems({ +export async function defaultCreateFeedItems({ blogPosts, siteConfig, outDir, diff --git a/website/_dogfooding/_blog tests/2023-07-19-a.mdx b/website/_dogfooding/_blog tests/2023-07-19-a.mdx new file mode 100644 index 000000000000..16cdfd88d675 --- /dev/null +++ b/website/_dogfooding/_blog tests/2023-07-19-a.mdx @@ -0,0 +1,9 @@ +--- +title: 'Test if href in feed resolved correctly' +--- + +[absolute full url](https://github.com/facebook/docusaurus) + +[absolute url with implicit domain name](/tests/blog/2023/07/19/b) + +[relative url](2023-07-19-b.mdx) diff --git a/website/_dogfooding/_blog tests/2023-07-19-b.mdx b/website/_dogfooding/_blog tests/2023-07-19-b.mdx new file mode 100644 index 000000000000..d6a54897045a --- /dev/null +++ b/website/_dogfooding/_blog tests/2023-07-19-b.mdx @@ -0,0 +1 @@ +# Test Relative Path From e65995e2f4c63782300df50dae32516ddb9e5de1 Mon Sep 17 00:00:00 2001 From: VinceCYLiao Date: Sun, 23 Jul 2023 15:47:07 +0800 Subject: [PATCH 03/19] feat: absolutize img URLs --- .../src/feed.ts | 31 +++++++++++++++---- 1 file changed, 25 insertions(+), 6 deletions(-) diff --git a/packages/docusaurus-plugin-content-blog/src/feed.ts b/packages/docusaurus-plugin-content-blog/src/feed.ts index df0da93f5ce5..06ef67cb3b04 100644 --- a/packages/docusaurus-plugin-content-blog/src/feed.ts +++ b/packages/docusaurus-plugin-content-blog/src/feed.ts @@ -107,12 +107,31 @@ export async function defaultCreateFeedItems({ const link = normalizeUrl([siteUrl, permalink]); - $(`div#${blogPostContainerID} a`).each((_, elm) => { - const {href} = elm.attribs; - if (href) { - elm.attribs.href = String(new URL(href, link)); - } - }); + $(`div#${blogPostContainerID} a, div#${blogPostContainerID} img`).each( + (_, elm) => { + if (elm.tagName === 'a') { + const {href} = elm.attribs; + if (href) { + elm.attribs.href = String(new URL(href, link)); + } + } else if (elm.tagName === 'img') { + const {src, srcset} = elm.attribs; + if (src) { + elm.attribs.src = String(new URL(src, link)); + } + if (srcset) { + elm.attribs.srcset = srcset + .split(',') + .map((s) => { + const [imageURL, ...descriptors] = s.trim().split(/\s+/); + const newImageURL = new URL(imageURL ?? '', link).href; + return [newImageURL, ...descriptors].join(' '); + }) + .join(', '); + } + } + }, + ); const feedItem: BlogFeedItem = { title: metadataTitle, From aaa869a514f1a30ae398c04b2ed86b9f226f8285 Mon Sep 17 00:00:00 2001 From: VinceCYLiao Date: Sun, 23 Jul 2023 15:48:30 +0800 Subject: [PATCH 04/19] chore: remove test case added in previous commit --- .../src/__tests__/feed.test.ts | 130 +----------------- 1 file changed, 3 insertions(+), 127 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 d98961e3868e..6592c09d7aa5 100644 --- a/packages/docusaurus-plugin-content-blog/src/__tests__/feed.test.ts +++ b/packages/docusaurus-plugin-content-blog/src/__tests__/feed.test.ts @@ -8,18 +8,12 @@ import {jest} from '@jest/globals'; import path from 'path'; import fs from 'fs-extra'; -import {load as cheerioLoad} from 'cheerio'; -import {readOutputHTMLFile} from '@docusaurus/utils'; -import {blogPostContainerID} from '@docusaurus/utils-common'; import {DEFAULT_OPTIONS} from '../options'; import {generateBlogPosts} from '../blogUtils'; -import { - createBlogFeedFiles, - defaultCreateFeedItems as feedDefaultCreateFeedItems, -} from '../feed'; -import type {LoadContext, I18n, DocusaurusConfig} from '@docusaurus/types'; +import {createBlogFeedFiles} from '../feed'; +import type {LoadContext, I18n} from '@docusaurus/types'; import type {BlogContentPaths} from '../types'; -import type {BlogPost, PluginOptions} from '@docusaurus/plugin-content-blog'; +import type {PluginOptions} from '@docusaurus/plugin-content-blog'; const DefaultI18N: I18n = { currentLocale: 'en', @@ -68,32 +62,6 @@ async function testGenerateFeeds( }); } -function isFullAbsolutePath(str: string) { - const domain = 'https://domain.com'; - const {origin} = new URL(str, domain); - return origin !== domain; -} - -async function generateLinksOfBlogPosts(outDir: string, blogPosts: BlogPost[]) { - const linksOfBlogPosts: {[postId: string]: string[]} = {}; - const pathOfFile = path.join(outDir, 'blog'); - const promises = blogPosts.map(async (post) => { - try { - const content = await readOutputHTMLFile(post.id, pathOfFile, true); - const $ = cheerioLoad(content); - const anchorElements = $(`div#${blogPostContainerID} a`); - if (anchorElements.length > 0) { - const href = anchorElements.map((_, elm) => elm.attribs.href).toArray(); - linksOfBlogPosts[post.id] = href; - } - } catch { - // post is a draft - } - }); - await Promise.all(promises); - return linksOfBlogPosts; -} - describe.each(['atom', 'rss', 'json'])('%s', (feedType) => { const fsMock = jest.spyOn(fs, 'outputFile').mockImplementation(() => {}); @@ -228,95 +196,3 @@ describe.each(['atom', 'rss', 'json'])('%s', (feedType) => { fsMock.mockClear(); }); }); - -describe('Test defaultCreateFeedItems', () => { - const fsMock = jest.spyOn(fs, 'outputFile').mockImplementation(() => {}); - it('links in feeds are resolved correctly', 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', - } as DocusaurusConfig; - - const context = { - siteDir, - siteConfig, - i18n: DefaultI18N, - outDir, - } as LoadContext; - - const options = { - path: 'blog', - routeBasePath: 'blog', - tagsBasePath: 'tags', - authorsMapPath: 'authors.yml', - include: DEFAULT_OPTIONS.include, - exclude: DEFAULT_OPTIONS.exclude, - feedOptions: { - type: ['atom', 'rss', 'json'], - copyright: 'Copyright', - }, - readingTime: ({content, defaultReadingTime}) => - defaultReadingTime({content}), - truncateMarker: //, - } as PluginOptions; - - const blogPosts = await generateBlogPosts( - getBlogContentPaths(siteDir), - context, - options, - ); - - await createBlogFeedFiles({ - blogPosts, - options, - siteConfig: context.siteConfig, - outDir: context.outDir, - locale: 'en', - }); - - const originalLinksInBlogs: {[id: string]: Array} = - await generateLinksOfBlogPosts(outDir, blogPosts); - - const blogPostsWithLinks = blogPosts.filter( - (post) => originalLinksInBlogs[post.id], - ); - - const feedsWithLinks = await feedDefaultCreateFeedItems({ - blogPosts: blogPostsWithLinks, - siteConfig, - outDir, - }); - - feedsWithLinks.forEach((feed) => { - const $ = cheerioLoad(feed.content ?? ''); - const linksInFeed = $('a') - .map((_, elm) => elm.attribs.href) - .toArray(); - const idOfBlogPost = feed.id!.replace( - new URL(`${siteConfig.baseUrl}blog`, siteConfig.url).href, - '', - ); - const originalLinksInBlog = originalLinksInBlogs[idOfBlogPost]; - const {permalink = ''} = - blogPostsWithLinks.find((post) => post.id === idOfBlogPost)?.metadata || - {}; - - originalLinksInBlog!.forEach((originalLinkInBlog, idx) => { - const linkToTest = isFullAbsolutePath(originalLinkInBlog) - ? originalLinkInBlog - : new URL(originalLinkInBlog, new URL(permalink, siteConfig.url)) - .href; - - expect(linkToTest).toEqual(linksInFeed[idx]); - }); - }); - expect( - fsMock.mock.calls.map((call) => call[1] as string), - ).toMatchSnapshot(); - fsMock.mockClear(); - }); -}); From af9cbe28b8193e53e7c61410f40fc50921e23526 Mon Sep 17 00:00:00 2001 From: VinceCYLiao Date: Sun, 23 Jul 2023 16:27:25 +0800 Subject: [PATCH 05/19] chore: update fixture --- .../website/blog/blog-with-links.md | 11 --------- .../website/blog/blog-with-links.mdx | 22 +++++++++++++++++ .../blog/blog-with-links/index.html | 24 +++++++++++++------ 3 files changed, 39 insertions(+), 18 deletions(-) delete mode 100644 packages/docusaurus-plugin-content-blog/src/__tests__/__fixtures__/website/blog/blog-with-links.md create mode 100644 packages/docusaurus-plugin-content-blog/src/__tests__/__fixtures__/website/blog/blog-with-links.mdx diff --git a/packages/docusaurus-plugin-content-blog/src/__tests__/__fixtures__/website/blog/blog-with-links.md b/packages/docusaurus-plugin-content-blog/src/__tests__/__fixtures__/website/blog/blog-with-links.md deleted file mode 100644 index 651c4cbe5525..000000000000 --- a/packages/docusaurus-plugin-content-blog/src/__tests__/__fixtures__/website/blog/blog-with-links.md +++ /dev/null @@ -1,11 +0,0 @@ ---- -title: 'Test if href in feed resolved correctly' ---- - -[absolute full url](https://github.com/facebook/docusaurus) - -[absolute url with implicit domain name](/tests/blog/2023/07/19/b) - -[relative url](2023-07-19-b.mdx) - -[anchor](#title) diff --git a/packages/docusaurus-plugin-content-blog/src/__tests__/__fixtures__/website/blog/blog-with-links.mdx b/packages/docusaurus-plugin-content-blog/src/__tests__/__fixtures__/website/blog/blog-with-links.mdx new file mode 100644 index 000000000000..5292e8b59a2d --- /dev/null +++ b/packages/docusaurus-plugin-content-blog/src/__tests__/__fixtures__/website/blog/blog-with-links.mdx @@ -0,0 +1,22 @@ +import dino from "../static/img/docusaurus.png"; +import useBaseUrl from '@docusaurus/useBaseUrl'; + +--- +title: test links +date: 2023-07-23 +--- +[absolute full url](https://github.com/facebook/docusaurus) + +[absolute url with implicit domain name](/blog/2017/12/14/introducing-docusaurus) + +[relative url](2017-12-14-introducing-docusaurus.mdx) + +[anchor](#title) + +![](/img/docusaurus.png) + +![](https://docusaurus.io/assets/images/slash-introducing-411a16dd05086935b8e9ddae38ae9b45.svg) + + + + diff --git a/packages/docusaurus-plugin-content-blog/src/__tests__/__fixtures__/website/build-snap/blog/blog-with-links/index.html b/packages/docusaurus-plugin-content-blog/src/__tests__/__fixtures__/website/build-snap/blog/blog-with-links/index.html index 3ba7d0584081..9d37b3731fd4 100644 --- a/packages/docusaurus-plugin-content-blog/src/__tests__/__fixtures__/website/build-snap/blog/blog-with-links/index.html +++ b/packages/docusaurus-plugin-content-blog/src/__tests__/__fixtures__/website/build-snap/blog/blog-with-links/index.html @@ -3,19 +3,29 @@ -Test if href in feed resolved correctly | Docusaurus blog only! +blog-with-links | Docusaurus blog only! - - + + - + \ No newline at end of file From 10ba5cbbc119b405fa84eb9eca7dfe43b32b4234 Mon Sep 17 00:00:00 2001 From: VinceCYLiao Date: Sun, 23 Jul 2023 16:27:44 +0800 Subject: [PATCH 06/19] chore: add for cSpell --- project-words.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/project-words.txt b/project-words.txt index 96342b59cbac..c18baaf60529 100644 --- a/project-words.txt +++ b/project-words.txt @@ -152,6 +152,7 @@ jodyheavener joshcena jscodeshift jssdk +juillet kaszubowski katex kato From 6a8345d43adabe4f3288bb877f53d81b202fe419 Mon Sep 17 00:00:00 2001 From: VinceCYLiao Date: Sun, 23 Jul 2023 16:32:09 +0800 Subject: [PATCH 07/19] feat: update test cases as added on new fixture file and update snapshot --- .../__tests__/__snapshots__/feed.test.ts.snap | 396 ++++-------------- .../src/__tests__/index.test.ts | 19 +- 2 files changed, 93 insertions(+), 322 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 1033b98702b6..234f8ce0b281 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 @@ -1,295 +1,36 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP -exports[`Test defaultCreateFeedItems links in feeds are resolved correctly 1`] = ` -[ - " - - https://docusaurus.io/myBaseUrl/blog - Hello Blog - 2023-07-19T08:15:33.000Z - https://github.com/jpmonette/feed - - Hello Blog - https://docusaurus.io/myBaseUrl/image/favicon.ico - Copyright - - <![CDATA[Test if href in feed resolved correctly]]> - https://docusaurus.io/myBaseUrl/blog/blog-with-links - - 2023-07-19T08:15:33.000Z - - absolute full url

-

absolute url with implicit domain name

-

relative url

-

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

linkimage

]]>
-
- - <![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!

]]>
- - Yangshun Tay (translated) - - - Sébastien Lorber (translated) - lorber.sebastien@gmail.com - -
-
", - " - - - Hello Blog - https://docusaurus.io/myBaseUrl/blog - Hello Blog - Wed, 19 Jul 2023 08:15:33 GMT - https://validator.w3.org/feed/docs/rss2.html - https://github.com/jpmonette/feed - en - Copyright - - <![CDATA[Test if href in feed resolved correctly]]> - https://docusaurus.io/myBaseUrl/blog/blog-with-links - https://docusaurus.io/myBaseUrl/blog/blog-with-links - Wed, 19 Jul 2023 08:15:33 GMT - - absolute full url

-

absolute url with implicit domain name

-

relative url

-

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

linkimage

]]>
-
- - <![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!

]]>
- lorber.sebastien@gmail.com (Sébastien Lorber (translated)) -
-
-
", - "{ - "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 url with implicit domain name

/n

relative url

/n

anchor

", - "url": "https://docusaurus.io/myBaseUrl/blog/blog-with-links", - "title": "Test if href in feed resolved correctly", - "summary": "absolute full url", - "date_modified": "2023-07-19T08:15:33.000Z", - "tags": [] - }, - { - "id": "https://docusaurus.io/myBaseUrl/blog/mdx-require-blog-post", - "content_html": "

Test MDX with require calls

", - "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

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\\"

", - "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!

", - "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[`atom filters to the first two entries 1`] = ` [ " https://docusaurus.io/myBaseUrl/blog Hello Blog - 2023-07-19T08:15:33.000Z + 2023-07-23T08:27:25.000Z https://github.com/jpmonette/feed Hello Blog https://docusaurus.io/myBaseUrl/image/favicon.ico Copyright - <![CDATA[Test if href in feed resolved correctly]]> + <![CDATA[blog-with-links]]> https://docusaurus.io/myBaseUrl/blog/blog-with-links - 2023-07-19T08:15:33.000Z - - absolute full url

-

absolute url with implicit domain name

-

relative url

-

anchor

]]>
+ 2023-07-23T08:27:25.000Z + + +

title: test links +date: 2023-07-23

+

absolute full url

+

absolute url with implicit domain name

+

relative url

+

anchor

+

+

+ +]]>
<![CDATA[MDX Blog Sample with require calls]]> @@ -297,7 +38,7 @@ exports[`atom filters to the first two entries 1`] = ` 2021-03-06T00:00:00.000Z - Test MDX with require calls

]]>
+ Test MDX with require calls

]]>
", ] @@ -309,22 +50,31 @@ exports[`atom has feed item for each post 1`] = ` https://docusaurus.io/myBaseUrl/blog Hello Blog - 2023-07-19T08:15:33.000Z + 2023-07-23T08:27:25.000Z https://github.com/jpmonette/feed Hello Blog https://docusaurus.io/myBaseUrl/image/favicon.ico Copyright - <![CDATA[Test if href in feed resolved correctly]]> + <![CDATA[blog-with-links]]> https://docusaurus.io/myBaseUrl/blog/blog-with-links - 2023-07-19T08:15:33.000Z - - absolute full url

-

absolute url with implicit domain name

-

relative url

-

anchor

]]>
+ 2023-07-23T08:27:25.000Z + + +

title: test links +date: 2023-07-23

+

absolute full url

+

absolute url with implicit domain name

+

relative url

+

anchor

+

+

+ +]]>
<![CDATA[MDX Blog Sample with require calls]]> @@ -332,7 +82,7 @@ exports[`atom has feed item for each post 1`] = ` 2021-03-06T00:00:00.000Z - Test MDX with require calls

]]>
+ Test MDX with require calls

]]>
<![CDATA[Full Blog Sample]]> @@ -408,16 +158,16 @@ exports[`json filters to the first two entries 1`] = ` "items": [ { "id": "https://docusaurus.io/myBaseUrl/blog/blog-with-links", - "content_html": "

absolute full url

/n

absolute url with implicit domain name

/n

relative url

/n

anchor

", + "content_html": "
/n

title: test links/ndate: 2023-07-23

/n

absolute full url

/n

absolute url with implicit domain name

/n

relative url

/n

anchor

/n

/n

\\"\\"

/n/n", "url": "https://docusaurus.io/myBaseUrl/blog/blog-with-links", - "title": "Test if href in feed resolved correctly", - "summary": "absolute full url", - "date_modified": "2023-07-19T08:15:33.000Z", + "title": "blog-with-links", + "summary": "---", + "date_modified": "2023-07-23T08:27:25.000Z", "tags": [] }, { "id": "https://docusaurus.io/myBaseUrl/blog/mdx-require-blog-post", - "content_html": "

Test MDX with require calls

", + "content_html": "

Test MDX with require calls

", "url": "https://docusaurus.io/myBaseUrl/blog/mdx-require-blog-post", "title": "MDX Blog Sample with require calls", "summary": "Test MDX with require calls", @@ -439,16 +189,16 @@ exports[`json has feed item for each post 1`] = ` "items": [ { "id": "https://docusaurus.io/myBaseUrl/blog/blog-with-links", - "content_html": "

absolute full url

/n

absolute url with implicit domain name

/n

relative url

/n

anchor

", + "content_html": "
/n

title: test links/ndate: 2023-07-23

/n

absolute full url

/n

absolute url with implicit domain name

/n

relative url

/n

anchor

/n

/n

\\"\\"

/n/n", "url": "https://docusaurus.io/myBaseUrl/blog/blog-with-links", - "title": "Test if href in feed resolved correctly", - "summary": "absolute full url", - "date_modified": "2023-07-19T08:15:33.000Z", + "title": "blog-with-links", + "summary": "---", + "date_modified": "2023-07-23T08:27:25.000Z", "tags": [] }, { "id": "https://docusaurus.io/myBaseUrl/blog/mdx-require-blog-post", - "content_html": "

Test MDX with require calls

", + "content_html": "

Test MDX with require calls

", "url": "https://docusaurus.io/myBaseUrl/blog/mdx-require-blog-post", "title": "MDX Blog Sample with require calls", "summary": "Test MDX with require calls", @@ -533,21 +283,30 @@ exports[`rss filters to the first two entries 1`] = ` Hello Blog https://docusaurus.io/myBaseUrl/blog Hello Blog - Wed, 19 Jul 2023 08:15:33 GMT + Sun, 23 Jul 2023 08:27:25 GMT https://validator.w3.org/feed/docs/rss2.html https://github.com/jpmonette/feed en Copyright - <![CDATA[Test if href in feed resolved correctly]]> + <![CDATA[blog-with-links]]> https://docusaurus.io/myBaseUrl/blog/blog-with-links https://docusaurus.io/myBaseUrl/blog/blog-with-links - Wed, 19 Jul 2023 08:15:33 GMT - - absolute full url

-

absolute url with implicit domain name

-

relative url

-

anchor

]]>
+ Sun, 23 Jul 2023 08:27:25 GMT + + +

title: test links +date: 2023-07-23

+

absolute full url

+

absolute url with implicit domain name

+

relative url

+

anchor

+

+

+ +]]>
<![CDATA[MDX Blog Sample with require calls]]> @@ -555,7 +314,7 @@ 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

]]>
+ Test MDX with require calls

]]>
", @@ -570,21 +329,30 @@ exports[`rss has feed item for each post 1`] = ` Hello Blog https://docusaurus.io/myBaseUrl/blog Hello Blog - Wed, 19 Jul 2023 08:15:33 GMT + Sun, 23 Jul 2023 08:27:25 GMT https://validator.w3.org/feed/docs/rss2.html https://github.com/jpmonette/feed en Copyright - <![CDATA[Test if href in feed resolved correctly]]> + <![CDATA[blog-with-links]]> https://docusaurus.io/myBaseUrl/blog/blog-with-links https://docusaurus.io/myBaseUrl/blog/blog-with-links - Wed, 19 Jul 2023 08:15:33 GMT - - absolute full url

-

absolute url with implicit domain name

-

relative url

-

anchor

]]>
+ Sun, 23 Jul 2023 08:27:25 GMT + + +

title: test links +date: 2023-07-23

+

absolute full url

+

absolute url with implicit domain name

+

relative url

+

anchor

+

+

+ +]]>
<![CDATA[MDX Blog Sample with require calls]]> @@ -592,7 +360,7 @@ exports[`rss has feed item for each post 1`] = ` https://docusaurus.io/myBaseUrl/blog/mdx-require-blog-post Sat, 06 Mar 2021 00:00:00 GMT - Test MDX with require calls

]]>
+ Test MDX with require calls

]]>
<![CDATA[Full Blog Sample]]> diff --git a/packages/docusaurus-plugin-content-blog/src/__tests__/index.test.ts b/packages/docusaurus-plugin-content-blog/src/__tests__/index.test.ts index ee7c68680cb5..8b392611e741 100644 --- a/packages/docusaurus-plugin-content-blog/src/__tests__/index.test.ts +++ b/packages/docusaurus-plugin-content-blog/src/__tests__/index.test.ts @@ -325,29 +325,32 @@ describe('blog plugin', () => { it('builds simple website blog with localized dates', async () => { const siteDir = path.join(__dirname, '__fixtures__', 'website'); const blogPostsFrench = await getBlogPosts(siteDir, {}, getI18n('fr')); - expect(blogPostsFrench).toHaveLength(9); + expect(blogPostsFrench).toHaveLength(10); expect(blogPostsFrench[0]!.metadata.formattedDate).toMatchInlineSnapshot( - `"6 mars 2021"`, + `"23 juillet 2023"`, ); expect(blogPostsFrench[1]!.metadata.formattedDate).toMatchInlineSnapshot( - `"5 mars 2021"`, + `"6 mars 2021"`, ); expect(blogPostsFrench[2]!.metadata.formattedDate).toMatchInlineSnapshot( - `"16 août 2020"`, + `"5 mars 2021"`, ); expect(blogPostsFrench[3]!.metadata.formattedDate).toMatchInlineSnapshot( - `"15 août 2020"`, + `"16 août 2020"`, ); expect(blogPostsFrench[4]!.metadata.formattedDate).toMatchInlineSnapshot( - `"27 février 2020"`, + `"15 août 2020"`, ); expect(blogPostsFrench[5]!.metadata.formattedDate).toMatchInlineSnapshot( `"27 février 2020"`, ); expect(blogPostsFrench[6]!.metadata.formattedDate).toMatchInlineSnapshot( - `"2 janvier 2019"`, + `"27 février 2020"`, ); expect(blogPostsFrench[7]!.metadata.formattedDate).toMatchInlineSnapshot( + `"2 janvier 2019"`, + ); + expect(blogPostsFrench[8]!.metadata.formattedDate).toMatchInlineSnapshot( `"1 janvier 2019"`, ); }); @@ -377,7 +380,7 @@ describe('blog plugin', () => { expect(blogPost.metadata.editUrl).toEqual(hardcodedEditUrl); }); - expect(editUrlFunction).toHaveBeenCalledTimes(9); + expect(editUrlFunction).toHaveBeenCalledTimes(10); expect(editUrlFunction).toHaveBeenCalledWith({ blogDirPath: 'blog', From 84493db860635b15aafb441d768fd36ffc3ef75c Mon Sep 17 00:00:00 2001 From: VinceCYLiao Date: Thu, 3 Aug 2023 13:24:33 +0800 Subject: [PATCH 08/19] chore: correct order of front matter and imports --- .../website/blog/blog-with-links.mdx | 7 ++++--- .../build-snap/blog/blog-with-links/index.html | 16 +++++----------- 2 files changed, 9 insertions(+), 14 deletions(-) diff --git a/packages/docusaurus-plugin-content-blog/src/__tests__/__fixtures__/website/blog/blog-with-links.mdx b/packages/docusaurus-plugin-content-blog/src/__tests__/__fixtures__/website/blog/blog-with-links.mdx index 5292e8b59a2d..d0d5cd77fe80 100644 --- a/packages/docusaurus-plugin-content-blog/src/__tests__/__fixtures__/website/blog/blog-with-links.mdx +++ b/packages/docusaurus-plugin-content-blog/src/__tests__/__fixtures__/website/blog/blog-with-links.mdx @@ -1,10 +1,11 @@ -import dino from "../static/img/docusaurus.png"; -import useBaseUrl from '@docusaurus/useBaseUrl'; - --- title: test links date: 2023-07-23 --- + +import useBaseUrl from '@docusaurus/useBaseUrl'; +import dino from "../static/img/docusaurus.png"; + [absolute full url](https://github.com/facebook/docusaurus) [absolute url with implicit domain name](/blog/2017/12/14/introducing-docusaurus) diff --git a/packages/docusaurus-plugin-content-blog/src/__tests__/__fixtures__/website/build-snap/blog/blog-with-links/index.html b/packages/docusaurus-plugin-content-blog/src/__tests__/__fixtures__/website/build-snap/blog/blog-with-links/index.html index 9d37b3731fd4..02e2d33d8f1d 100644 --- a/packages/docusaurus-plugin-content-blog/src/__tests__/__fixtures__/website/build-snap/blog/blog-with-links/index.html +++ b/packages/docusaurus-plugin-content-blog/src/__tests__/__fixtures__/website/build-snap/blog/blog-with-links/index.html @@ -3,29 +3,23 @@ -blog-with-links | Docusaurus blog only! +test links | Docusaurus blog only! - - + + -

blog-with-links

· One min read

-

title: test links -date: 2023-07-23

-

absolute full url

+ +
\ No newline at end of file From f382af64d49a5c14ad295618de001cb903f9e0de Mon Sep 17 00:00:00 2001 From: VinceCYLiao Date: Thu, 3 Aug 2023 13:26:37 +0800 Subject: [PATCH 09/19] feat: use srcset lib to parse urls in img's srcset and make them absolute --- .../docusaurus-plugin-content-blog/package.json | 1 + .../docusaurus-plugin-content-blog/src/feed.ts | 17 ++++++++--------- yarn.lock | 5 +++++ 3 files changed, 14 insertions(+), 9 deletions(-) diff --git a/packages/docusaurus-plugin-content-blog/package.json b/packages/docusaurus-plugin-content-blog/package.json index 1003f7cb5c80..3480242cc90f 100644 --- a/packages/docusaurus-plugin-content-blog/package.json +++ b/packages/docusaurus-plugin-content-blog/package.json @@ -30,6 +30,7 @@ "fs-extra": "^11.1.1", "lodash": "^4.17.21", "reading-time": "^1.5.0", + "srcset": "^4.0.0", "tslib": "^2.6.0", "unist-util-visit": "^2.0.3", "utility-types": "^3.10.0", diff --git a/packages/docusaurus-plugin-content-blog/src/feed.ts b/packages/docusaurus-plugin-content-blog/src/feed.ts index 06ef67cb3b04..39deb604f3c6 100644 --- a/packages/docusaurus-plugin-content-blog/src/feed.ts +++ b/packages/docusaurus-plugin-content-blog/src/feed.ts @@ -9,6 +9,7 @@ import path from 'path'; import fs from 'fs-extra'; import logger from '@docusaurus/logger'; import {Feed, type Author as FeedAuthor} from 'feed'; +import {parse, stringify} from 'srcset'; import {normalizeUrl, readOutputHTMLFile} from '@docusaurus/utils'; import {blogPostContainerID} from '@docusaurus/utils-common'; import {load as cheerioLoad} from 'cheerio'; @@ -43,7 +44,7 @@ async function generateBlogFeed({ const blogBaseUrl = normalizeUrl([siteUrl, baseUrl, routeBasePath]); const updated = blogPosts[0]?.metadata.date; - + console.log('==updated', updated); const feed = new Feed({ id: blogBaseUrl, title: feedOptions.title ?? `${title} Blog`, @@ -120,14 +121,12 @@ export async function defaultCreateFeedItems({ elm.attribs.src = String(new URL(src, link)); } if (srcset) { - elm.attribs.srcset = srcset - .split(',') - .map((s) => { - const [imageURL, ...descriptors] = s.trim().split(/\s+/); - const newImageURL = new URL(imageURL ?? '', link).href; - return [newImageURL, ...descriptors].join(' '); - }) - .join(', '); + elm.attribs.srcset = stringify( + parse(srcset).map((props) => ({ + ...props, + url: String(new URL(props.url, link)), + })), + ); } } }, diff --git a/yarn.lock b/yarn.lock index 7d071f4393f5..12c0f4ccb8c3 100644 --- a/yarn.lock +++ b/yarn.lock @@ -15367,6 +15367,11 @@ sprintf-js@~1.0.2: resolved "https://registry.yarnpkg.com/sprintf-js/-/sprintf-js-1.0.3.tgz#04e6926f662895354f3dd015203633b857297e2c" integrity sha512-D9cPgkvLlV3t3IzL0D0YLvGA9Ahk4PcvVwUbN0dSGr1aP0Nrt4AEnTUbuGvquEC0mA64Gqt1fzirlRs5ibXx8g== +srcset@^4.0.0: + version "4.0.0" + resolved "https://registry.yarnpkg.com/srcset/-/srcset-4.0.0.tgz#336816b665b14cd013ba545b6fe62357f86e65f4" + integrity sha512-wvLeHgcVHKO8Sc/H/5lkGreJQVeYMm9rlmt8PuR1xE31rIuXhuzznUUqAt8MqLhB3MqJdFzlNAfpcWnxiFUcPw== + ssri@9.0.1, ssri@^9.0.0: version "9.0.1" resolved "https://registry.yarnpkg.com/ssri/-/ssri-9.0.1.tgz#544d4c357a8d7b71a19700074b6883fcb4eae057" From 08e17dbcfbd7a5b06755730d2df41966fa6c4822 Mon Sep 17 00:00:00 2001 From: VinceCYLiao Date: Thu, 3 Aug 2023 13:28:43 +0800 Subject: [PATCH 10/19] chore: update snapshot --- .../__tests__/__snapshots__/feed.test.ts.snap | 76 +++++++------------ 1 file changed, 28 insertions(+), 48 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 234f8ce0b281..b763dd42c3d8 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 @@ -6,24 +6,19 @@ exports[`atom filters to the first two entries 1`] = ` https://docusaurus.io/myBaseUrl/blog Hello Blog - 2023-07-23T08:27:25.000Z + 2023-07-23T00:00:00.000Z https://github.com/jpmonette/feed Hello Blog https://docusaurus.io/myBaseUrl/image/favicon.ico Copyright - <![CDATA[blog-with-links]]> + <![CDATA[test links]]> https://docusaurus.io/myBaseUrl/blog/blog-with-links - 2023-07-23T08:27:25.000Z - - -

title: test links -date: 2023-07-23

-

absolute full url

+ 2023-07-23T00:00:00.000Z + + absolute full url

absolute url with implicit domain name

relative url

anchor

@@ -50,24 +45,19 @@ exports[`atom has feed item for each post 1`] = ` https://docusaurus.io/myBaseUrl/blog Hello Blog - 2023-07-23T08:27:25.000Z + 2023-07-23T00:00:00.000Z https://github.com/jpmonette/feed Hello Blog https://docusaurus.io/myBaseUrl/image/favicon.ico Copyright - <![CDATA[blog-with-links]]> + <![CDATA[test links]]> https://docusaurus.io/myBaseUrl/blog/blog-with-links - 2023-07-23T08:27:25.000Z - - -

title: test links -date: 2023-07-23

-

absolute full url

+ 2023-07-23T00:00:00.000Z + + absolute full url

absolute url with implicit domain name

relative url

anchor

@@ -158,11 +148,11 @@ exports[`json filters to the first two entries 1`] = ` "items": [ { "id": "https://docusaurus.io/myBaseUrl/blog/blog-with-links", - "content_html": "
/n

title: test links/ndate: 2023-07-23

/n

absolute full url

/n

absolute url with implicit domain name

/n

relative url

/n

anchor

/n

/n

\\"\\"

/n/n", + "content_html": "

absolute full url

/n

absolute url with implicit domain name

/n

relative url

/n

anchor

/n

/n

\\"\\"

/n/n", "url": "https://docusaurus.io/myBaseUrl/blog/blog-with-links", - "title": "blog-with-links", - "summary": "---", - "date_modified": "2023-07-23T08:27:25.000Z", + "title": "test links", + "summary": "absolute full url", + "date_modified": "2023-07-23T00:00:00.000Z", "tags": [] }, { @@ -189,11 +179,11 @@ exports[`json has feed item for each post 1`] = ` "items": [ { "id": "https://docusaurus.io/myBaseUrl/blog/blog-with-links", - "content_html": "
/n

title: test links/ndate: 2023-07-23

/n

absolute full url

/n

absolute url with implicit domain name

/n

relative url

/n

anchor

/n

/n

\\"\\"

/n/n", + "content_html": "

absolute full url

/n

absolute url with implicit domain name

/n

relative url

/n

anchor

/n

/n

\\"\\"

/n/n", "url": "https://docusaurus.io/myBaseUrl/blog/blog-with-links", - "title": "blog-with-links", - "summary": "---", - "date_modified": "2023-07-23T08:27:25.000Z", + "title": "test links", + "summary": "absolute full url", + "date_modified": "2023-07-23T00:00:00.000Z", "tags": [] }, { @@ -283,23 +273,18 @@ exports[`rss filters to the first two entries 1`] = ` Hello Blog https://docusaurus.io/myBaseUrl/blog Hello Blog - Sun, 23 Jul 2023 08:27:25 GMT + Sun, 23 Jul 2023 00:00:00 GMT https://validator.w3.org/feed/docs/rss2.html https://github.com/jpmonette/feed en Copyright - <![CDATA[blog-with-links]]> + <![CDATA[test links]]> https://docusaurus.io/myBaseUrl/blog/blog-with-links https://docusaurus.io/myBaseUrl/blog/blog-with-links - Sun, 23 Jul 2023 08:27:25 GMT - - -

title: test links -date: 2023-07-23

-

absolute full url

+ Sun, 23 Jul 2023 00:00:00 GMT + + absolute full url

absolute url with implicit domain name

relative url

anchor

@@ -329,23 +314,18 @@ exports[`rss has feed item for each post 1`] = ` Hello Blog https://docusaurus.io/myBaseUrl/blog Hello Blog - Sun, 23 Jul 2023 08:27:25 GMT + Sun, 23 Jul 2023 00:00:00 GMT https://validator.w3.org/feed/docs/rss2.html https://github.com/jpmonette/feed en Copyright - <![CDATA[blog-with-links]]> + <![CDATA[test links]]> https://docusaurus.io/myBaseUrl/blog/blog-with-links https://docusaurus.io/myBaseUrl/blog/blog-with-links - Sun, 23 Jul 2023 08:27:25 GMT - - -

title: test links -date: 2023-07-23

-

absolute full url

+ Sun, 23 Jul 2023 00:00:00 GMT + + absolute full url

absolute url with implicit domain name

relative url

anchor

From df689054b63e68e159c0b14ebe9e395466f640f9 Mon Sep 17 00:00:00 2001 From: VinceCYLiao Date: Thu, 3 Aug 2023 13:34:11 +0800 Subject: [PATCH 11/19] chore: remove console.log --- packages/docusaurus-plugin-content-blog/src/feed.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/packages/docusaurus-plugin-content-blog/src/feed.ts b/packages/docusaurus-plugin-content-blog/src/feed.ts index 39deb604f3c6..b9384d9ab16a 100644 --- a/packages/docusaurus-plugin-content-blog/src/feed.ts +++ b/packages/docusaurus-plugin-content-blog/src/feed.ts @@ -44,7 +44,6 @@ async function generateBlogFeed({ const blogBaseUrl = normalizeUrl([siteUrl, baseUrl, routeBasePath]); const updated = blogPosts[0]?.metadata.date; - console.log('==updated', updated); const feed = new Feed({ id: blogBaseUrl, title: feedOptions.title ?? `${title} Blog`, From 646d22a027058016d4611c8dc58a4f759308b51a Mon Sep 17 00:00:00 2001 From: VinceCYLiao Date: Thu, 3 Aug 2023 13:41:09 +0800 Subject: [PATCH 12/19] chore: remove unneeded export declaration --- packages/docusaurus-plugin-content-blog/src/feed.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/packages/docusaurus-plugin-content-blog/src/feed.ts b/packages/docusaurus-plugin-content-blog/src/feed.ts index b9384d9ab16a..116a52acff7c 100644 --- a/packages/docusaurus-plugin-content-blog/src/feed.ts +++ b/packages/docusaurus-plugin-content-blog/src/feed.ts @@ -44,6 +44,7 @@ async function generateBlogFeed({ const blogBaseUrl = normalizeUrl([siteUrl, baseUrl, routeBasePath]); const updated = blogPosts[0]?.metadata.date; + const feed = new Feed({ id: blogBaseUrl, title: feedOptions.title ?? `${title} Blog`, @@ -70,7 +71,7 @@ async function generateBlogFeed({ return feed; } -export async function defaultCreateFeedItems({ +async function defaultCreateFeedItems({ blogPosts, siteConfig, outDir, From d34fda6f2d4fadf738e739ac0e993bfb27e77914 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Lorber?= Date: Thu, 3 Aug 2023 16:12:33 +0200 Subject: [PATCH 13/19] Update packages/docusaurus-plugin-content-blog/src/feed.ts Co-authored-by: Joshua Chen --- packages/docusaurus-plugin-content-blog/src/feed.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/docusaurus-plugin-content-blog/src/feed.ts b/packages/docusaurus-plugin-content-blog/src/feed.ts index 116a52acff7c..5030e9592fa3 100644 --- a/packages/docusaurus-plugin-content-blog/src/feed.ts +++ b/packages/docusaurus-plugin-content-blog/src/feed.ts @@ -9,7 +9,7 @@ import path from 'path'; import fs from 'fs-extra'; import logger from '@docusaurus/logger'; import {Feed, type Author as FeedAuthor} from 'feed'; -import {parse, stringify} from 'srcset'; +import * as srcset from 'srcset'; import {normalizeUrl, readOutputHTMLFile} from '@docusaurus/utils'; import {blogPostContainerID} from '@docusaurus/utils-common'; import {load as cheerioLoad} from 'cheerio'; From 0016a18d6e1e9835ce8cc8dca53cb8f676a4ee0c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Lorber?= Date: Thu, 3 Aug 2023 16:12:40 +0200 Subject: [PATCH 14/19] Update packages/docusaurus-plugin-content-blog/src/feed.ts Co-authored-by: Joshua Chen --- packages/docusaurus-plugin-content-blog/src/feed.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/docusaurus-plugin-content-blog/src/feed.ts b/packages/docusaurus-plugin-content-blog/src/feed.ts index 5030e9592fa3..04904e4dc860 100644 --- a/packages/docusaurus-plugin-content-blog/src/feed.ts +++ b/packages/docusaurus-plugin-content-blog/src/feed.ts @@ -116,13 +116,13 @@ async function defaultCreateFeedItems({ elm.attribs.href = String(new URL(href, link)); } } else if (elm.tagName === 'img') { - const {src, srcset} = elm.attribs; + const {src, srcset: srcsetAttr} = elm.attribs; if (src) { elm.attribs.src = String(new URL(src, link)); } - if (srcset) { - elm.attribs.srcset = stringify( - parse(srcset).map((props) => ({ + if (srcsetAttr) { + elm.attribs.srcset = srcset.stringify( + srcset.parse(srcsetAttr).map((props) => ({ ...props, url: String(new URL(props.url, link)), })), From 2158d7c8742fad2cc9a471d52df5718bdfb8411e Mon Sep 17 00:00:00 2001 From: sebastienlorber Date: Thu, 3 Aug 2023 16:18:43 +0200 Subject: [PATCH 15/19] simplify impl --- .../docusaurus-plugin-content-blog/src/feed.ts | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/packages/docusaurus-plugin-content-blog/src/feed.ts b/packages/docusaurus-plugin-content-blog/src/feed.ts index 04904e4dc860..4dd82117e362 100644 --- a/packages/docusaurus-plugin-content-blog/src/feed.ts +++ b/packages/docusaurus-plugin-content-blog/src/feed.ts @@ -106,25 +106,30 @@ async function defaultCreateFeedItems({ ); const $ = cheerioLoad(content); - const link = normalizeUrl([siteUrl, permalink]); + const blogPostAbsoluteUrl = normalizeUrl([siteUrl, permalink]); + const toAbsoluteUrl = (src: string) => + String(new URL(src, blogPostAbsoluteUrl)); + + // Make links and image urls absolute + // See https://github.com/facebook/docusaurus/issues/9136 $(`div#${blogPostContainerID} a, div#${blogPostContainerID} img`).each( (_, elm) => { if (elm.tagName === 'a') { const {href} = elm.attribs; if (href) { - elm.attribs.href = String(new URL(href, link)); + elm.attribs.href = toAbsoluteUrl(href); } } else if (elm.tagName === 'img') { const {src, srcset: srcsetAttr} = elm.attribs; if (src) { - elm.attribs.src = String(new URL(src, link)); + elm.attribs.src = toAbsoluteUrl(src); } if (srcsetAttr) { elm.attribs.srcset = srcset.stringify( srcset.parse(srcsetAttr).map((props) => ({ ...props, - url: String(new URL(props.url, link)), + url: toAbsoluteUrl(props.url), })), ); } @@ -134,8 +139,8 @@ async function defaultCreateFeedItems({ const feedItem: BlogFeedItem = { title: metadataTitle, - id: link, - link, + id: blogPostAbsoluteUrl, + link: blogPostAbsoluteUrl, date, description, // Atom feed demands the "term", while other feeds use "name" From c04e223d00ae78a8ffca26473dd5c9434a1ce5ba Mon Sep 17 00:00:00 2001 From: sebastienlorber Date: Thu, 3 Aug 2023 18:07:19 +0200 Subject: [PATCH 16/19] replace docusaurus.png --- .../website/blog/blog-with-links.mdx | 12 +++++--- .../blog/blog-with-links/index.html | 6 ++-- .../__tests__/__snapshots__/feed.test.ts.snap | 30 +++++++++---------- 3 files changed, 26 insertions(+), 22 deletions(-) diff --git a/packages/docusaurus-plugin-content-blog/src/__tests__/__fixtures__/website/blog/blog-with-links.mdx b/packages/docusaurus-plugin-content-blog/src/__tests__/__fixtures__/website/blog/blog-with-links.mdx index d0d5cd77fe80..3589b9712feb 100644 --- a/packages/docusaurus-plugin-content-blog/src/__tests__/__fixtures__/website/blog/blog-with-links.mdx +++ b/packages/docusaurus-plugin-content-blog/src/__tests__/__fixtures__/website/blog/blog-with-links.mdx @@ -4,7 +4,7 @@ date: 2023-07-23 --- import useBaseUrl from '@docusaurus/useBaseUrl'; -import dino from "../static/img/docusaurus.png"; +import dino from '../static/img/test-image.png'; [absolute full url](https://github.com/facebook/docusaurus) @@ -14,10 +14,14 @@ import dino from "../static/img/docusaurus.png"; [anchor](#title) -![](/img/docusaurus.png) +![](/img/test-image.png) ![](https://docusaurus.io/assets/images/slash-introducing-411a16dd05086935b8e9ddae38ae9b45.svg) - + - + diff --git a/packages/docusaurus-plugin-content-blog/src/__tests__/__fixtures__/website/build-snap/blog/blog-with-links/index.html b/packages/docusaurus-plugin-content-blog/src/__tests__/__fixtures__/website/build-snap/blog/blog-with-links/index.html index 02e2d33d8f1d..3d97c9bd64e8 100644 --- a/packages/docusaurus-plugin-content-blog/src/__tests__/__fixtures__/website/build-snap/blog/blog-with-links/index.html +++ b/packages/docusaurus-plugin-content-blog/src/__tests__/__fixtures__/website/build-snap/blog/blog-with-links/index.html @@ -19,7 +19,7 @@

anchor

- - + + - \ No newline at end of file + 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 155c6af759ce..9296d8d91e4f 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 @@ -24,8 +24,8 @@ exports[`atom filters to the first two entries 1`] = `

anchor

- -]]>
+ +]]>
<![CDATA[MDX Blog Sample with require calls]]> @@ -68,8 +68,8 @@ exports[`atom filters to the first two entries using limit 1`] = `

anchor

- -]]>
+ +]]>
<![CDATA[MDX Blog Sample with require calls]]> @@ -112,8 +112,8 @@ exports[`atom has feed item for each post 1`] = `

anchor

- -]]> + +]]>
<![CDATA[MDX Blog Sample with require calls]]> @@ -224,7 +224,7 @@ exports[`json filters to the first two entries 1`] = ` "items": [ { "id": "https://docusaurus.io/myBaseUrl/blog/blog-with-links", - "content_html": "

absolute full url

/n

absolute url with implicit domain name

/n

relative url

/n

anchor

/n

/n

\\"\\"

/n/n", + "content_html": "

absolute full url

/n

absolute url with implicit domain name

/n

relative url

/n

anchor

/n

/n

\\"\\"

/n/n", "url": "https://docusaurus.io/myBaseUrl/blog/blog-with-links", "title": "test links", "summary": "absolute full url", @@ -255,7 +255,7 @@ exports[`json filters to the first two entries using limit 1`] = ` "items": [ { "id": "https://docusaurus.io/myBaseUrl/blog/blog-with-links", - "content_html": "

absolute full url

/n

absolute url with implicit domain name

/n

relative url

/n

anchor

/n

/n

\\"\\"

/n/n", + "content_html": "

absolute full url

/n

absolute url with implicit domain name

/n

relative url

/n

anchor

/n

/n

\\"\\"

/n/n", "url": "https://docusaurus.io/myBaseUrl/blog/blog-with-links", "title": "test links", "summary": "absolute full url", @@ -286,7 +286,7 @@ exports[`json has feed item for each post 1`] = ` "items": [ { "id": "https://docusaurus.io/myBaseUrl/blog/blog-with-links", - "content_html": "

absolute full url

/n

absolute url with implicit domain name

/n

relative url

/n

anchor

/n

/n

\\"\\"

/n/n", + "content_html": "

absolute full url

/n

absolute url with implicit domain name

/n

relative url

/n

anchor

/n

/n

\\"\\"

/n/n", "url": "https://docusaurus.io/myBaseUrl/blog/blog-with-links", "title": "test links", "summary": "absolute full url", @@ -397,8 +397,8 @@ exports[`rss filters to the first two entries 1`] = `

anchor

- -]]> + +]]>
<![CDATA[MDX Blog Sample with require calls]]> @@ -443,8 +443,8 @@ exports[`rss filters to the first two entries using limit 1`] = `

anchor

- -]]> + +]]>
<![CDATA[MDX Blog Sample with require calls]]> @@ -489,8 +489,8 @@ exports[`rss has feed item for each post 1`] = `

anchor

- -]]> + +]]>
<![CDATA[MDX Blog Sample with require calls]]> From 0afae8b64fbc4d3ac933752a95836be6a52445d4 Mon Sep 17 00:00:00 2001 From: sebastienlorber Date: Thu, 3 Aug 2023 18:12:48 +0200 Subject: [PATCH 17/19] improve blog-with-links.mdx file links --- .../__fixtures__/website/blog/blog-with-links.mdx | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/packages/docusaurus-plugin-content-blog/src/__tests__/__fixtures__/website/blog/blog-with-links.mdx b/packages/docusaurus-plugin-content-blog/src/__tests__/__fixtures__/website/blog/blog-with-links.mdx index 3589b9712feb..3a7b6ddf192a 100644 --- a/packages/docusaurus-plugin-content-blog/src/__tests__/__fixtures__/website/blog/blog-with-links.mdx +++ b/packages/docusaurus-plugin-content-blog/src/__tests__/__fixtures__/website/blog/blog-with-links.mdx @@ -8,12 +8,16 @@ import dino from '../static/img/test-image.png'; [absolute full url](https://github.com/facebook/docusaurus) -[absolute url with implicit domain name](/blog/2017/12/14/introducing-docusaurus) +[absolute pathname](/blog/heading-as-title) -[relative url](2017-12-14-introducing-docusaurus.mdx) +[relative pathname](heading-as-title) + +[md link](heading-as-title.md) [anchor](#title) +[relative pathname + anchor](heading-as-title#title) + ![](/img/test-image.png) ![](https://docusaurus.io/assets/images/slash-introducing-411a16dd05086935b8e9ddae38ae9b45.svg) From 1f8dfadd52150f2cab8efec13cff48ee2955e3f0 Mon Sep 17 00:00:00 2001 From: sebastienlorber Date: Thu, 3 Aug 2023 18:12:58 +0200 Subject: [PATCH 18/19] regenerate build-snap --- .../__fixtures__/website/build-snap/404.html | 6 ++-- .../14/Happy-First-Birthday-Slash/index.html | 8 ++--- .../build-snap/blog/archive/index.html | 8 ++--- .../website/build-snap/blog/atom.xml | 19 +++++++++++- .../blog/blog-with-links/index.html | 31 ++++++++++--------- .../build-snap/blog/date-matter/index.html | 8 ++--- .../website/build-snap/blog/feed.json | 9 ++++++ .../blog/heading-as-title/index.html | 8 ++--- .../h\303\251ll\303\264/index.html" | 8 ++--- .../website/build-snap/blog/index.html | 21 +++++++++---- .../build-snap/blog/mdx-blog-post/index.html | 8 ++--- .../blog/mdx-require-blog-post/index.html | 10 +++--- .../website/build-snap/blog/page/2/index.html | 8 ++--- .../website/build-snap/blog/page/3/index.html | 8 ++--- .../website/build-snap/blog/rss.xml | 19 +++++++++++- .../build-snap/blog/simple/slug/index.html | 8 ++--- .../build-snap/blog/tags/complex/index.html | 8 ++--- .../build-snap/blog/tags/date/index.html | 8 ++--- .../website/build-snap/blog/tags/index.html | 8 ++--- .../build-snap/blog/unlisted/index.html | 8 ++--- .../website/build-snap/index.html | 6 ++-- .../website/build-snap/search/index.html | 6 ++-- .../website/build-snap/sitemap.xml | 2 +- 23 files changed, 144 insertions(+), 89 deletions(-) diff --git a/packages/docusaurus-plugin-content-blog/src/__tests__/__fixtures__/website/build-snap/404.html b/packages/docusaurus-plugin-content-blog/src/__tests__/__fixtures__/website/build-snap/404.html index dcf1291ed021..944eb5f6bb98 100644 --- a/packages/docusaurus-plugin-content-blog/src/__tests__/__fixtures__/website/build-snap/404.html +++ b/packages/docusaurus-plugin-content-blog/src/__tests__/__fixtures__/website/build-snap/404.html @@ -3,15 +3,15 @@ -Page Not Found | Docusaurus blog website fixture +Page Not Found | Docusaurus blog website fixture - - + +

Page Not Found

We could not find what you were looking for.

Please contact the owner of the site that linked you to the original URL and let them know their link is broken.

diff --git a/packages/docusaurus-plugin-content-blog/src/__tests__/__fixtures__/website/build-snap/blog/2018/12/14/Happy-First-Birthday-Slash/index.html b/packages/docusaurus-plugin-content-blog/src/__tests__/__fixtures__/website/build-snap/blog/2018/12/14/Happy-First-Birthday-Slash/index.html index 0d9c913bf406..3cf7c4156a96 100644 --- a/packages/docusaurus-plugin-content-blog/src/__tests__/__fixtures__/website/build-snap/blog/2018/12/14/Happy-First-Birthday-Slash/index.html +++ b/packages/docusaurus-plugin-content-blog/src/__tests__/__fixtures__/website/build-snap/blog/2018/12/14/Happy-First-Birthday-Slash/index.html @@ -3,17 +3,17 @@ -Happy 1st Birthday Slash! (translated) | Docusaurus blog website fixture +Happy 1st Birthday Slash! (translated) | Docusaurus blog website fixture - - + + -
+
\ No newline at end of file diff --git a/packages/docusaurus-plugin-content-blog/src/__tests__/__fixtures__/website/build-snap/blog/archive/index.html b/packages/docusaurus-plugin-content-blog/src/__tests__/__fixtures__/website/build-snap/blog/archive/index.html index 468c1d26823d..7faf4fe57430 100644 --- a/packages/docusaurus-plugin-content-blog/src/__tests__/__fixtures__/website/build-snap/blog/archive/index.html +++ b/packages/docusaurus-plugin-content-blog/src/__tests__/__fixtures__/website/build-snap/blog/archive/index.html @@ -3,17 +3,17 @@ -Archive | Docusaurus blog website fixture +Archive | Docusaurus blog website fixture - - + + - + \ No newline at end of file diff --git a/packages/docusaurus-plugin-content-blog/src/__tests__/__fixtures__/website/build-snap/blog/atom.xml b/packages/docusaurus-plugin-content-blog/src/__tests__/__fixtures__/website/build-snap/blog/atom.xml index 93f32cd2c032..88f35a40be6e 100644 --- a/packages/docusaurus-plugin-content-blog/src/__tests__/__fixtures__/website/build-snap/blog/atom.xml +++ b/packages/docusaurus-plugin-content-blog/src/__tests__/__fixtures__/website/build-snap/blog/atom.xml @@ -2,12 +2,29 @@ https://docusaurus.io/blog/ Docusaurus blog website fixture Blog - 2021-03-06T00:00:00.000Z + 2023-07-23T00:00:00.000Z https://github.com/jpmonette/feed Docusaurus blog website fixture Blog https://docusaurus.io/img/docusaurus.ico Copyright + + <![CDATA[test links]]> + https://docusaurus.io/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/blog/mdx-require-blog-post diff --git a/packages/docusaurus-plugin-content-blog/src/__tests__/__fixtures__/website/build-snap/blog/blog-with-links/index.html b/packages/docusaurus-plugin-content-blog/src/__tests__/__fixtures__/website/build-snap/blog/blog-with-links/index.html index 3d97c9bd64e8..c31f3d249be9 100644 --- a/packages/docusaurus-plugin-content-blog/src/__tests__/__fixtures__/website/build-snap/blog/blog-with-links/index.html +++ b/packages/docusaurus-plugin-content-blog/src/__tests__/__fixtures__/website/build-snap/blog/blog-with-links/index.html @@ -3,23 +3,26 @@ -test links | Docusaurus blog only! - - +test links | Docusaurus blog website fixture + + - - - + + + + -

test links

· One min read

absolute full url

-

absolute url with implicit domain name

-

relative url

+ +

relative pathname + anchor

+

+

+ +
- + \ No newline at end of file diff --git a/packages/docusaurus-plugin-content-blog/src/__tests__/__fixtures__/website/build-snap/blog/date-matter/index.html b/packages/docusaurus-plugin-content-blog/src/__tests__/__fixtures__/website/build-snap/blog/date-matter/index.html index 09bdd8971f1f..8d0fad961801 100644 --- a/packages/docusaurus-plugin-content-blog/src/__tests__/__fixtures__/website/build-snap/blog/date-matter/index.html +++ b/packages/docusaurus-plugin-content-blog/src/__tests__/__fixtures__/website/build-snap/blog/date-matter/index.html @@ -3,17 +3,17 @@ -date-matter | Docusaurus blog website fixture +date-matter | Docusaurus blog website fixture - - + + - + \ No newline at end of file diff --git a/packages/docusaurus-plugin-content-blog/src/__tests__/__fixtures__/website/build-snap/blog/feed.json b/packages/docusaurus-plugin-content-blog/src/__tests__/__fixtures__/website/build-snap/blog/feed.json index d2fa55d912c0..d5377e75c5c4 100644 --- a/packages/docusaurus-plugin-content-blog/src/__tests__/__fixtures__/website/build-snap/blog/feed.json +++ b/packages/docusaurus-plugin-content-blog/src/__tests__/__fixtures__/website/build-snap/blog/feed.json @@ -4,6 +4,15 @@ "home_page_url": "https://docusaurus.io/blog/", "description": "Docusaurus blog website fixture Blog", "items": [ + { + "id": "https://docusaurus.io/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/blog/blog-with-links", + "title": "test links", + "summary": "absolute full url", + "date_modified": "2023-07-23T00:00:00.000Z", + "tags": [] + }, { "id": "https://docusaurus.io/blog/mdx-require-blog-post", "content_html": "

Test MDX with require calls

\n\n\n\n\n", diff --git a/packages/docusaurus-plugin-content-blog/src/__tests__/__fixtures__/website/build-snap/blog/heading-as-title/index.html b/packages/docusaurus-plugin-content-blog/src/__tests__/__fixtures__/website/build-snap/blog/heading-as-title/index.html index 89462fa86a5c..4b3e39eb132a 100644 --- a/packages/docusaurus-plugin-content-blog/src/__tests__/__fixtures__/website/build-snap/blog/heading-as-title/index.html +++ b/packages/docusaurus-plugin-content-blog/src/__tests__/__fixtures__/website/build-snap/blog/heading-as-title/index.html @@ -3,17 +3,17 @@ -some heading | Docusaurus blog website fixture +some heading | Docusaurus blog website fixture - - + + - + \ No newline at end of file diff --git "a/packages/docusaurus-plugin-content-blog/src/__tests__/__fixtures__/website/build-snap/blog/hey/my super path/h\303\251ll\303\264/index.html" "b/packages/docusaurus-plugin-content-blog/src/__tests__/__fixtures__/website/build-snap/blog/hey/my super path/h\303\251ll\303\264/index.html" index 89a12664ca8d..ee0856269f00 100644 --- "a/packages/docusaurus-plugin-content-blog/src/__tests__/__fixtures__/website/build-snap/blog/hey/my super path/h\303\251ll\303\264/index.html" +++ "b/packages/docusaurus-plugin-content-blog/src/__tests__/__fixtures__/website/build-snap/blog/hey/my super path/h\303\251ll\303\264/index.html" @@ -3,17 +3,17 @@ -Complex Slug | Docusaurus blog website fixture +Complex Slug | Docusaurus blog website fixture - - + + - + \ No newline at end of file diff --git a/packages/docusaurus-plugin-content-blog/src/__tests__/__fixtures__/website/build-snap/blog/index.html b/packages/docusaurus-plugin-content-blog/src/__tests__/__fixtures__/website/build-snap/blog/index.html index c27d9d218179..0f32d3f19cc7 100644 --- a/packages/docusaurus-plugin-content-blog/src/__tests__/__fixtures__/website/build-snap/blog/index.html +++ b/packages/docusaurus-plugin-content-blog/src/__tests__/__fixtures__/website/build-snap/blog/index.html @@ -3,23 +3,32 @@ -Blog | Docusaurus blog website fixture +Blog | Docusaurus blog website fixture - - + + -

· One min read

Test MDX with require calls

+
+

link image

\ No newline at end of file diff --git a/packages/docusaurus-plugin-content-blog/src/__tests__/__fixtures__/website/build-snap/blog/mdx-blog-post/index.html b/packages/docusaurus-plugin-content-blog/src/__tests__/__fixtures__/website/build-snap/blog/mdx-blog-post/index.html index 920c7c06d0ea..5768f9d0e188 100644 --- a/packages/docusaurus-plugin-content-blog/src/__tests__/__fixtures__/website/build-snap/blog/mdx-blog-post/index.html +++ b/packages/docusaurus-plugin-content-blog/src/__tests__/__fixtures__/website/build-snap/blog/mdx-blog-post/index.html @@ -3,18 +3,18 @@ -Full Blog Sample | Docusaurus blog website fixture +Full Blog Sample | Docusaurus blog website fixture - - + + -

Full Blog Sample

· One min read

HTML Heading 1

+

Full Blog Sample

· One min read

HTML Heading 1

HTML Heading 2

HTML Paragraph

diff --git a/packages/docusaurus-plugin-content-blog/src/__tests__/__fixtures__/website/build-snap/blog/mdx-require-blog-post/index.html b/packages/docusaurus-plugin-content-blog/src/__tests__/__fixtures__/website/build-snap/blog/mdx-require-blog-post/index.html index a0f23c4ef6da..c8c7a170c0d1 100644 --- a/packages/docusaurus-plugin-content-blog/src/__tests__/__fixtures__/website/build-snap/blog/mdx-require-blog-post/index.html +++ b/packages/docusaurus-plugin-content-blog/src/__tests__/__fixtures__/website/build-snap/blog/mdx-require-blog-post/index.html @@ -3,22 +3,22 @@ -MDX Blog Sample with require calls | Docusaurus blog website fixture +MDX Blog Sample with require calls | Docusaurus blog website fixture - - + + -

MDX Blog Sample with require calls

· One min read

Test MDX with require calls

+

MDX Blog Sample with require calls

· One min read

Test MDX with require calls

-
+
\ No newline at end of file diff --git a/packages/docusaurus-plugin-content-blog/src/__tests__/__fixtures__/website/build-snap/blog/page/2/index.html b/packages/docusaurus-plugin-content-blog/src/__tests__/__fixtures__/website/build-snap/blog/page/2/index.html index 8b0b50a48bda..b38f219c042d 100644 --- a/packages/docusaurus-plugin-content-blog/src/__tests__/__fixtures__/website/build-snap/blog/page/2/index.html +++ b/packages/docusaurus-plugin-content-blog/src/__tests__/__fixtures__/website/build-snap/blog/page/2/index.html @@ -3,17 +3,17 @@ -Blog | Docusaurus blog website fixture +Blog | Docusaurus blog website fixture - - + + -

· One min read

date inside front matter

+
\ No newline at end of file diff --git a/packages/docusaurus-plugin-content-blog/src/__tests__/__fixtures__/website/build-snap/blog/page/3/index.html b/packages/docusaurus-plugin-content-blog/src/__tests__/__fixtures__/website/build-snap/blog/page/3/index.html index 326ccbc61ffa..3210fd3fb973 100644 --- a/packages/docusaurus-plugin-content-blog/src/__tests__/__fixtures__/website/build-snap/blog/page/3/index.html +++ b/packages/docusaurus-plugin-content-blog/src/__tests__/__fixtures__/website/build-snap/blog/page/3/index.html @@ -3,17 +3,17 @@ -Blog | Docusaurus blog website fixture +Blog | Docusaurus blog website fixture - - + + -
+

· One min read

date inside front matter

\ No newline at end of file diff --git a/packages/docusaurus-plugin-content-blog/src/__tests__/__fixtures__/website/build-snap/blog/rss.xml b/packages/docusaurus-plugin-content-blog/src/__tests__/__fixtures__/website/build-snap/blog/rss.xml index 6eb89081aaa1..bc749a48f342 100644 --- a/packages/docusaurus-plugin-content-blog/src/__tests__/__fixtures__/website/build-snap/blog/rss.xml +++ b/packages/docusaurus-plugin-content-blog/src/__tests__/__fixtures__/website/build-snap/blog/rss.xml @@ -4,11 +4,28 @@ Docusaurus blog website fixture Blog https://docusaurus.io/blog/ Docusaurus blog website fixture Blog - Sat, 06 Mar 2021 00:00:00 GMT + 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/blog/blog-with-links + https://docusaurus.io/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/blog/mdx-require-blog-post diff --git a/packages/docusaurus-plugin-content-blog/src/__tests__/__fixtures__/website/build-snap/blog/simple/slug/index.html b/packages/docusaurus-plugin-content-blog/src/__tests__/__fixtures__/website/build-snap/blog/simple/slug/index.html index 57781f0c98e5..7f60ef680b19 100644 --- a/packages/docusaurus-plugin-content-blog/src/__tests__/__fixtures__/website/build-snap/blog/simple/slug/index.html +++ b/packages/docusaurus-plugin-content-blog/src/__tests__/__fixtures__/website/build-snap/blog/simple/slug/index.html @@ -3,17 +3,17 @@ -Simple Slug | Docusaurus blog website fixture +Simple Slug | Docusaurus blog website fixture - - + + - + \ No newline at end of file diff --git a/packages/docusaurus-plugin-content-blog/src/__tests__/__fixtures__/website/build-snap/blog/tags/complex/index.html b/packages/docusaurus-plugin-content-blog/src/__tests__/__fixtures__/website/build-snap/blog/tags/complex/index.html index 17f15a052dbc..e8ceaf557408 100644 --- a/packages/docusaurus-plugin-content-blog/src/__tests__/__fixtures__/website/build-snap/blog/tags/complex/index.html +++ b/packages/docusaurus-plugin-content-blog/src/__tests__/__fixtures__/website/build-snap/blog/tags/complex/index.html @@ -3,17 +3,17 @@ -One post tagged with "complex" | Docusaurus blog website fixture +One post tagged with "complex" | Docusaurus blog website fixture - - + + -

One post tagged with "complex"

View All Tags
+

One post tagged with "complex"

View All Tags
\ No newline at end of file diff --git a/packages/docusaurus-plugin-content-blog/src/__tests__/__fixtures__/website/build-snap/blog/tags/date/index.html b/packages/docusaurus-plugin-content-blog/src/__tests__/__fixtures__/website/build-snap/blog/tags/date/index.html index 714f7832a7d0..fa8c63e91db6 100644 --- a/packages/docusaurus-plugin-content-blog/src/__tests__/__fixtures__/website/build-snap/blog/tags/date/index.html +++ b/packages/docusaurus-plugin-content-blog/src/__tests__/__fixtures__/website/build-snap/blog/tags/date/index.html @@ -3,17 +3,17 @@ -2 posts tagged with "date" | Docusaurus blog website fixture +2 posts tagged with "date" | Docusaurus blog website fixture - - + + -

2 posts tagged with "date"

View All Tags

· One min read

date inside front matter

+

2 posts tagged with "date"

View All Tags

· One min read

date inside front matter

\ No newline at end of file diff --git a/packages/docusaurus-plugin-content-blog/src/__tests__/__fixtures__/website/build-snap/blog/tags/index.html b/packages/docusaurus-plugin-content-blog/src/__tests__/__fixtures__/website/build-snap/blog/tags/index.html index 67951eb3f371..a19fde15671d 100644 --- a/packages/docusaurus-plugin-content-blog/src/__tests__/__fixtures__/website/build-snap/blog/tags/index.html +++ b/packages/docusaurus-plugin-content-blog/src/__tests__/__fixtures__/website/build-snap/blog/tags/index.html @@ -3,17 +3,17 @@ -Tags | Docusaurus blog website fixture +Tags | Docusaurus blog website fixture - - + + - + \ No newline at end of file diff --git a/packages/docusaurus-plugin-content-blog/src/__tests__/__fixtures__/website/build-snap/blog/unlisted/index.html b/packages/docusaurus-plugin-content-blog/src/__tests__/__fixtures__/website/build-snap/blog/unlisted/index.html index 20a148326ac2..b036938a8469 100644 --- a/packages/docusaurus-plugin-content-blog/src/__tests__/__fixtures__/website/build-snap/blog/unlisted/index.html +++ b/packages/docusaurus-plugin-content-blog/src/__tests__/__fixtures__/website/build-snap/blog/unlisted/index.html @@ -3,17 +3,17 @@ -unlisted | Docusaurus blog website fixture +unlisted | Docusaurus blog website fixture - - + + -
Unlisted page
This page is unlisted. Search engines will not index it, and only users having a direct link can access it.

unlisted

· One min read

this post is unlisted

+
Unlisted page
This page is unlisted. Search engines will not index it, and only users having a direct link can access it.

unlisted

· One min read

this post is unlisted

\ No newline at end of file diff --git a/packages/docusaurus-plugin-content-blog/src/__tests__/__fixtures__/website/build-snap/index.html b/packages/docusaurus-plugin-content-blog/src/__tests__/__fixtures__/website/build-snap/index.html index cb26a9a1f218..bd5ce2908562 100644 --- a/packages/docusaurus-plugin-content-blog/src/__tests__/__fixtures__/website/build-snap/index.html +++ b/packages/docusaurus-plugin-content-blog/src/__tests__/__fixtures__/website/build-snap/index.html @@ -3,15 +3,15 @@ -Home | Docusaurus blog website fixture +Home | Docusaurus blog website fixture - - + + diff --git a/packages/docusaurus-plugin-content-blog/src/__tests__/__fixtures__/website/build-snap/search/index.html b/packages/docusaurus-plugin-content-blog/src/__tests__/__fixtures__/website/build-snap/search/index.html index 1063bf3c8804..60c3c5439119 100644 --- a/packages/docusaurus-plugin-content-blog/src/__tests__/__fixtures__/website/build-snap/search/index.html +++ b/packages/docusaurus-plugin-content-blog/src/__tests__/__fixtures__/website/build-snap/search/index.html @@ -3,15 +3,15 @@ -Search the documentation | Docusaurus blog website fixture +Search the documentation | Docusaurus blog website fixture - - + +

Search the documentation

diff --git a/packages/docusaurus-plugin-content-blog/src/__tests__/__fixtures__/website/build-snap/sitemap.xml b/packages/docusaurus-plugin-content-blog/src/__tests__/__fixtures__/website/build-snap/sitemap.xml index f131680d500e..77b35be7b438 100644 --- a/packages/docusaurus-plugin-content-blog/src/__tests__/__fixtures__/website/build-snap/sitemap.xml +++ b/packages/docusaurus-plugin-content-blog/src/__tests__/__fixtures__/website/build-snap/sitemap.xml @@ -1 +1 @@ -https://docusaurus.io/blog/weekly0.5https://docusaurus.io/blog/2018/12/14/Happy-First-Birthday-Slashweekly0.5https://docusaurus.io/blog/archiveweekly0.5https://docusaurus.io/blog/date-matterweekly0.5https://docusaurus.io/blog/heading-as-titleweekly0.5https://docusaurus.io/blog/hey/my%20super%20path/h%C3%A9ll%C3%B4weekly0.5https://docusaurus.io/blog/mdx-blog-postweekly0.5https://docusaurus.io/blog/mdx-require-blog-postweekly0.5https://docusaurus.io/blog/page/2weekly0.5https://docusaurus.io/blog/page/3weekly0.5https://docusaurus.io/blog/simple/slugweekly0.5https://docusaurus.io/blog/tagsweekly0.5https://docusaurus.io/blog/tags/complexweekly0.5https://docusaurus.io/blog/tags/dateweekly0.5https://docusaurus.io/searchweekly0.5https://docusaurus.io/weekly0.5 \ No newline at end of file +https://docusaurus.io/blog/weekly0.5https://docusaurus.io/blog/2018/12/14/Happy-First-Birthday-Slashweekly0.5https://docusaurus.io/blog/archiveweekly0.5https://docusaurus.io/blog/blog-with-linksweekly0.5https://docusaurus.io/blog/date-matterweekly0.5https://docusaurus.io/blog/heading-as-titleweekly0.5https://docusaurus.io/blog/hey/my%20super%20path/h%C3%A9ll%C3%B4weekly0.5https://docusaurus.io/blog/mdx-blog-postweekly0.5https://docusaurus.io/blog/mdx-require-blog-postweekly0.5https://docusaurus.io/blog/page/2weekly0.5https://docusaurus.io/blog/page/3weekly0.5https://docusaurus.io/blog/simple/slugweekly0.5https://docusaurus.io/blog/tagsweekly0.5https://docusaurus.io/blog/tags/complexweekly0.5https://docusaurus.io/blog/tags/dateweekly0.5https://docusaurus.io/searchweekly0.5https://docusaurus.io/weekly0.5 \ No newline at end of file From da0fb441319071dd649a91a577950f75e2fcb78b Mon Sep 17 00:00:00 2001 From: sebastienlorber Date: Thu, 3 Aug 2023 18:13:23 +0200 Subject: [PATCH 19/19] Update feed snapshots --- .../__tests__/__snapshots__/feed.test.ts.snap | 90 +++++++++++-------- 1 file changed, 51 insertions(+), 39 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 9296d8d91e4f..8af04cf9ae22 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 @@ -19,13 +19,15 @@ exports[`atom filters to the first two entries 1`] = ` 2023-07-23T00:00:00.000Z absolute full url

-

absolute url with implicit domain name

-

relative url

+

absolute pathname

+

relative pathname

+

md link

anchor

-

-

- -]]>
+

relative pathname + anchor

+

+

+ +]]> <![CDATA[MDX Blog Sample with require calls]]> @@ -63,13 +65,15 @@ exports[`atom filters to the first two entries using limit 1`] = ` 2023-07-23T00:00:00.000Z absolute full url

-

absolute url with implicit domain name

-

relative url

+

absolute pathname

+

relative pathname

+

md link

anchor

-

-

- -]]>
+

relative pathname + anchor

+

+

+ +]]>
<![CDATA[MDX Blog Sample with require calls]]> @@ -107,13 +111,15 @@ exports[`atom has feed item for each post 1`] = ` 2023-07-23T00:00:00.000Z absolute full url

-

absolute url with implicit domain name

-

relative url

+

absolute pathname

+

relative pathname

+

md link

anchor

-

-

- -]]>
+

relative pathname + anchor

+

+

+ +]]>
<![CDATA[MDX Blog Sample with require calls]]> @@ -224,7 +230,7 @@ exports[`json filters to the first two entries 1`] = ` "items": [ { "id": "https://docusaurus.io/myBaseUrl/blog/blog-with-links", - "content_html": "

absolute full url

/n

absolute url with implicit domain name

/n

relative url

/n

anchor

/n

/n

\\"\\"

/n/n", + "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", @@ -255,7 +261,7 @@ exports[`json filters to the first two entries using limit 1`] = ` "items": [ { "id": "https://docusaurus.io/myBaseUrl/blog/blog-with-links", - "content_html": "

absolute full url

/n

absolute url with implicit domain name

/n

relative url

/n

anchor

/n

/n

\\"\\"

/n/n", + "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", @@ -286,7 +292,7 @@ exports[`json has feed item for each post 1`] = ` "items": [ { "id": "https://docusaurus.io/myBaseUrl/blog/blog-with-links", - "content_html": "

absolute full url

/n

absolute url with implicit domain name

/n

relative url

/n

anchor

/n

/n

\\"\\"

/n/n", + "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", @@ -392,13 +398,15 @@ exports[`rss filters to the first two entries 1`] = ` Sun, 23 Jul 2023 00:00:00 GMT absolute full url

-

absolute url with implicit domain name

-

relative url

+

absolute pathname

+

relative pathname

+

md link

anchor

-

-

- -]]>
+

relative pathname + anchor

+

+

+ +]]>
<![CDATA[MDX Blog Sample with require calls]]> @@ -438,13 +446,15 @@ exports[`rss filters to the first two entries using limit 1`] = ` Sun, 23 Jul 2023 00:00:00 GMT absolute full url

-

absolute url with implicit domain name

-

relative url

+

absolute pathname

+

relative pathname

+

md link

anchor

-

-

- -]]>
+

relative pathname + anchor

+

+

+ +]]>
<![CDATA[MDX Blog Sample with require calls]]> @@ -484,13 +494,15 @@ exports[`rss has feed item for each post 1`] = ` Sun, 23 Jul 2023 00:00:00 GMT absolute full url

-

absolute url with implicit domain name

-

relative url

+

absolute pathname

+

relative pathname

+

md link

anchor

-

-

- -]]>
+

relative pathname + anchor

+

+

+ +]]>
<![CDATA[MDX Blog Sample with require calls]]>