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
+
+
+ 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
]]>
+
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 1HTML Heading 2 HTML Paragraph
Import DOM
Heading 1 Heading 2 Heading 3 Heading 4 Heading 5 Normal Text Italics Text Bold Text
link
]]>
+ HTML Heading 1HTML Heading 2 HTML Paragraph
Import DOM
Heading 1 Heading 2 Heading 3 Heading 4 Heading 5 Normal Text Italics Text Bold Text
link
]]>
+
+
+
+ https://docusaurus.io/myBaseUrl/blog/hey/my super path/héllô
+
+ 2020-08-16T00:00:00.000Z
+
+ complex url slug]]>
+
+
+
+
+
+ https://docusaurus.io/myBaseUrl/blog/simple/slug
+
+ 2020-08-15T00:00:00.000Z
+
+ simple url slug]]>
+
+ Sébastien Lorber
+ https://sebastienlorber.com
+
+
+
+
+ https://docusaurus.io/myBaseUrl/blog/heading-as-title
+
+ 2019-01-02T00:00:00.000Z
+
+
+
+ https://docusaurus.io/myBaseUrl/blog/date-matter
+
+ 2019-01-01T00:00:00.000Z
+
+ date inside front matter]]>
+
+
+
+
+ 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
+ -
+
+ 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
]]>
+
+ -
+
+ 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 ]]>
+
+ -
+
+ 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 1HTML Heading 2 HTML Paragraph
Import DOM
Heading 1 Heading 2 Heading 3 Heading 4 Heading 5 Normal Text Italics Text Bold Text
link
]]>
+
+ -
+
+ 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
+
+ -
+
+ 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]]>
+
+ -
+
+ https://docusaurus.io/myBaseUrl/blog/heading-as-title
+ https://docusaurus.io/myBaseUrl/blog/heading-as-title
+ Wed, 02 Jan 2019 00:00:00 GMT
+
+ -
+
+ 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
+
+ -
+
+ 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
/nabsolute url with implicit domain name
/nrelative url
/nanchor
",
+ "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
",
+ "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
+
+
+ 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
]]>
+
+
+
+ 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
+
+
+ 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
]]>
+
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 1HTML Heading 2 HTML Paragraph
Import DOM
Heading 1 Heading 2 Heading 3 Heading 4 Heading 5 Normal Text Italics Text Bold Text
link
]]>
+ HTML Heading 1HTML Heading 2 HTML Paragraph
Import DOM
Heading 1 Heading 2 Heading 3 Heading 4 Heading 5 Normal Text Italics Text Bold Text
link
]]>
@@ -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
/nabsolute url with implicit domain name
/nrelative url
/nanchor
",
+ "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 Normal Text Italics Text Bold Text
link
",
- "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
/nabsolute url with implicit domain name
/nrelative url
/nanchor
",
+ "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 Normal Text Italics Text Bold Text
link
",
+ "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
",
"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
+ -
+
+ 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
]]>
+
-
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 ]]>
- -
-
- 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 1HTML Heading 2 HTML Paragraph
Import DOM
Heading 1 Heading 2 Heading 3 Heading 4 Heading 5 Normal Text Italics Text Bold Text
link
]]>
-
",
]
@@ -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
+ -
+
+ 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
]]>
+
-
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 1HTML Heading 2 HTML Paragraph
Import DOM
Heading 1 Heading 2 Heading 3 Heading 4 Heading 5 Normal Text Italics Text Bold Text
link
]]>
+ HTML Heading 1HTML Heading 2 HTML Paragraph
Import DOM
Heading 1 Heading 2 Heading 3 Heading 4 Heading 5 Normal Text Italics Text Bold Text
link
]]>
-
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