Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

feat(core): hash router option - browse site offline (experimental) #9859

Merged
merged 53 commits into from
May 19, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
53 commits
Select commit Hold shift + click to select a range
27b1acf
attempt to use hash-based history and make it work offline
slorber Feb 16, 2024
da45fff
Merge branch 'main' into slorber/offline-mode-poc-2
slorber Feb 22, 2024
de0df2d
Add router type to config file
slorber Feb 22, 2024
0c5034b
fix tests
slorber Feb 22, 2024
45c1c9d
add link hack
slorber Feb 22, 2024
25a9004
disable redirect plugin with the hash router?
slorber Feb 22, 2024
904f730
add siteConfig DOCUSAURUS_ROUTER env variable
slorber Feb 22, 2024
a1b9ba6
logging message
slorber Feb 22, 2024
547d8ab
sitemap should support hash router?
slorber Feb 22, 2024
4c5a9de
Disable PWA/client-redirects plugins in Hash Router mode
slorber Feb 22, 2024
c22da5a
Fix heading/TOC/anchor links with hash router
slorber Feb 22, 2024
4a22ebb
urlUtils normalizeUrl should support hash router
slorber Feb 23, 2024
5a5d2f3
simplify feeds unit tests
slorber Feb 23, 2024
81dbd82
blog feed support for Hash Router
slorber Feb 23, 2024
6c072c3
remove comment
slorber Feb 23, 2024
bffb2f0
add unit test for sitemap with hash router
slorber Feb 23, 2024
030688a
Add router config type doc
slorber Feb 23, 2024
62aa2cb
Make it possible to switch router dynamically
slorber Feb 23, 2024
6582ea7
Rework full build workflow for hash router support
slorber Feb 23, 2024
2f33aad
refactor: apply lint autofix
slorber Feb 23, 2024
e902401
Merge branch 'main' into slorber/offline-mode-poc-2
slorber May 17, 2024
b82e8a5
add missing route codegen after merge
slorber May 17, 2024
abc3a31
Encapsulate router impl switch in docusaurus core to avoid pnpm / yar…
slorber May 17, 2024
62fc20e
rename siteConfig import
slorber May 17, 2024
b80d22c
disable sitemap plugin with hash router
slorber May 17, 2024
e8ef286
disable blog feeds for hash router
slorber May 17, 2024
6282cca
improve disabled plugin warning
slorber May 17, 2024
b7d2884
Fix router type
slorber May 17, 2024
2c323f1
Move router config to siteConfig.future.experimental_router + add con…
slorber May 17, 2024
520bc92
fix webpack client config
slorber May 17, 2024
61f453e
fix unit tests breaking due to missing siteConfig.future
slorber May 17, 2024
62a25c5
Fix Docusaurus website config
slorber May 17, 2024
0a24bb7
simpler router switch
slorber May 17, 2024
9bbb135
simpler router switch
slorber May 17, 2024
15cc555
fix dev server with hash router + baseUrl
slorber May 17, 2024
f12aeee
fix hash router build
slorber May 17, 2024
bbc94c7
do not emit Algolia opensearch file with hash router
slorber May 17, 2024
533e307
Extract StaticDirectoriesCopyPlugin + move it to the client webpack c…
slorber May 17, 2024
1dad032
Add some tests for useBaseUrl with hash router
slorber May 17, 2024
f8edab1
basic router type docs
slorber May 17, 2024
b1f2c8d
revert useless serverEntry hack
slorber May 17, 2024
0465e7e
simplify ssg params
slorber May 17, 2024
a36ab2e
Add CI workflow for build with hash router
slorber May 17, 2024
905e681
fix CI workflow?
slorber May 17, 2024
4b7a8c2
only apply hash router logic when the hash router is enabled for html…
slorber May 17, 2024
db860a8
Add hack comment
slorber May 17, 2024
d877806
deploy hash router to github pages
slorber May 19, 2024
2b5e458
deploy hash router to github pages
slorber May 19, 2024
19745dc
deploy hash router to github pages
slorber May 19, 2024
a732f95
deploy hash router to github pages
slorber May 19, 2024
3610306
deploy hash router to github pages
slorber May 19, 2024
2de9c18
deploy hash router to github pages
slorber May 19, 2024
7cf6500
deploy hash router to github pages
slorber May 19, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
blog feed support for Hash Router
  • Loading branch information
slorber committed Feb 23, 2024
commit 81dbd820911c5d2782f37214f9dc15549e8dbb0e
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,91 @@ exports[`atom has feed item for each post 1`] = `
]
`;

exports[`atom has feed item for each post using hash router 1`] = `
[
"<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
<id>https://docusaurus.io/myBaseUrl/blog</id>
<title>Hello Blog</title>
<updated>2023-07-23T00:00:00.000Z</updated>
<generator>https://github.com/jpmonette/feed</generator>
<link rel="alternate" href="https://docusaurus.io/myBaseUrl/blog"/>
<subtitle>Hello Blog</subtitle>
<icon>https://docusaurus.io/myBaseUrl/image/favicon.ico</icon>
<rights>Copyright</rights>
<entry>
<title type="html"><![CDATA[test links]]></title>
<id>https://docusaurus.io/#/myBaseUrl/blog/blog-with-links</id>
<link href="https://docusaurus.io/#/myBaseUrl/blog/blog-with-links"/>
<updated>2023-07-23T00:00:00.000Z</updated>
<summary type="html"><![CDATA[absolute full url]]></summary>
</entry>
<entry>
<title type="html"><![CDATA[MDX Blog Sample with require calls]]></title>
<id>https://docusaurus.io/#/myBaseUrl/blog/mdx-require-blog-post</id>
<link href="https://docusaurus.io/#/myBaseUrl/blog/mdx-require-blog-post"/>
<updated>2021-03-06T00:00:00.000Z</updated>
<summary type="html"><![CDATA[Test MDX with require calls]]></summary>
</entry>
<entry>
<title type="html"><![CDATA[Full Blog Sample]]></title>
<id>https://docusaurus.io/#/myBaseUrl/blog/mdx-blog-post</id>
<link href="https://docusaurus.io/#/myBaseUrl/blog/mdx-blog-post"/>
<updated>2021-03-05T00:00:00.000Z</updated>
<summary type="html"><![CDATA[HTML Heading 1]]></summary>
</entry>
<entry>
<title type="html"><![CDATA[Complex Slug]]></title>
<id>https://docusaurus.io/#/myBaseUrl/blog/hey/my super path/héllô</id>
<link href="https://docusaurus.io/#/myBaseUrl/blog/hey/my super path/héllô"/>
<updated>2020-08-16T00:00:00.000Z</updated>
<summary type="html"><![CDATA[complex url slug]]></summary>
<category label="date" term="date"/>
<category label="complex" term="complex"/>
</entry>
<entry>
<title type="html"><![CDATA[Simple Slug]]></title>
<id>https://docusaurus.io/#/myBaseUrl/blog/simple/slug</id>
<link href="https://docusaurus.io/#/myBaseUrl/blog/simple/slug"/>
<updated>2020-08-15T00:00:00.000Z</updated>
<summary type="html"><![CDATA[simple url slug]]></summary>
<author>
<name>Sébastien Lorber</name>
<uri>https://sebastienlorber.com</uri>
</author>
</entry>
<entry>
<title type="html"><![CDATA[some heading]]></title>
<id>https://docusaurus.io/#/myBaseUrl/blog/heading-as-title</id>
<link href="https://docusaurus.io/#/myBaseUrl/blog/heading-as-title"/>
<updated>2019-01-02T00:00:00.000Z</updated>
</entry>
<entry>
<title type="html"><![CDATA[date-matter]]></title>
<id>https://docusaurus.io/#/myBaseUrl/blog/date-matter</id>
<link href="https://docusaurus.io/#/myBaseUrl/blog/date-matter"/>
<updated>2019-01-01T00:00:00.000Z</updated>
<summary type="html"><![CDATA[date inside front matter]]></summary>
<category label="date" term="date"/>
</entry>
<entry>
<title type="html"><![CDATA[Happy 1st Birthday Slash! (translated)]]></title>
<id>https://docusaurus.io/#/myBaseUrl/blog/2018/12/14/Happy-First-Birthday-Slash</id>
<link href="https://docusaurus.io/#/myBaseUrl/blog/2018/12/14/Happy-First-Birthday-Slash"/>
<updated>2018-12-14T00:00:00.000Z</updated>
<summary type="html"><![CDATA[Happy birthday! (translated)]]></summary>
<author>
<name>Yangshun Tay (translated)</name>
</author>
<author>
<name>Sébastien Lorber (translated)</name>
<email>lorber.sebastien@gmail.com</email>
</author>
</entry>
</feed>",
]
`;

exports[`json filters to the first two entries 1`] = `
[
"{
Expand Down Expand Up @@ -378,6 +463,94 @@ exports[`json has feed item for each post 1`] = `
]
`;

exports[`json has feed item for each post using hash router 1`] = `
[
"{
"version": "https://jsonfeed.org/version/1",
"title": "Hello Blog",
"home_page_url": "https://docusaurus.io/myBaseUrl/blog",
"description": "Hello Blog",
"items": [
{
"id": "https://docusaurus.io/#/myBaseUrl/blog/blog-with-links",
"url": "https://docusaurus.io/#/myBaseUrl/blog/blog-with-links",
"title": "test links",
"summary": "absolute full url",
"date_modified": "2023-07-23T00:00:00.000Z",
"tags": []
},
{
"id": "https://docusaurus.io/#/myBaseUrl/blog/mdx-require-blog-post",
"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",
"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ô",
"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",
"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",
"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",
"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",
"url": "https://docusaurus.io/#/myBaseUrl/blog/2018/12/14/Happy-First-Birthday-Slash",
"title": "Happy 1st Birthday Slash! (translated)",
"summary": "Happy birthday! (translated)",
"date_modified": "2018-12-14T00:00:00.000Z",
"author": {
"name": "Yangshun Tay (translated)"
},
"tags": []
}
]
}",
]
`;

exports[`rss filters to the first two entries 1`] = `
[
"<?xml version="1.0" encoding="utf-8"?>
Expand Down Expand Up @@ -593,3 +766,80 @@ exports[`rss has feed item for each post 1`] = `
</rss>",
]
`;

exports[`rss has feed item for each post using hash router 1`] = `
[
"<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0">
<channel>
<title>Hello Blog</title>
<link>https://docusaurus.io/myBaseUrl/blog</link>
<description>Hello Blog</description>
<lastBuildDate>Sun, 23 Jul 2023 00:00:00 GMT</lastBuildDate>
<docs>https://validator.w3.org/feed/docs/rss2.html</docs>
<generator>https://github.com/jpmonette/feed</generator>
<language>en</language>
<copyright>Copyright</copyright>
<item>
<title><![CDATA[test links]]></title>
<link>https://docusaurus.io/#/myBaseUrl/blog/blog-with-links</link>
<guid>https://docusaurus.io/#/myBaseUrl/blog/blog-with-links</guid>
<pubDate>Sun, 23 Jul 2023 00:00:00 GMT</pubDate>
<description><![CDATA[absolute full url]]></description>
</item>
<item>
<title><![CDATA[MDX Blog Sample with require calls]]></title>
<link>https://docusaurus.io/#/myBaseUrl/blog/mdx-require-blog-post</link>
<guid>https://docusaurus.io/#/myBaseUrl/blog/mdx-require-blog-post</guid>
<pubDate>Sat, 06 Mar 2021 00:00:00 GMT</pubDate>
<description><![CDATA[Test MDX with require calls]]></description>
</item>
<item>
<title><![CDATA[Full Blog Sample]]></title>
<link>https://docusaurus.io/#/myBaseUrl/blog/mdx-blog-post</link>
<guid>https://docusaurus.io/#/myBaseUrl/blog/mdx-blog-post</guid>
<pubDate>Fri, 05 Mar 2021 00:00:00 GMT</pubDate>
<description><![CDATA[HTML Heading 1]]></description>
</item>
<item>
<title><![CDATA[Complex Slug]]></title>
<link>https://docusaurus.io/#/myBaseUrl/blog/hey/my super path/héllô</link>
<guid>https://docusaurus.io/#/myBaseUrl/blog/hey/my super path/héllô</guid>
<pubDate>Sun, 16 Aug 2020 00:00:00 GMT</pubDate>
<description><![CDATA[complex url slug]]></description>
<category>date</category>
<category>complex</category>
</item>
<item>
<title><![CDATA[Simple Slug]]></title>
<link>https://docusaurus.io/#/myBaseUrl/blog/simple/slug</link>
<guid>https://docusaurus.io/#/myBaseUrl/blog/simple/slug</guid>
<pubDate>Sat, 15 Aug 2020 00:00:00 GMT</pubDate>
<description><![CDATA[simple url slug]]></description>
</item>
<item>
<title><![CDATA[some heading]]></title>
<link>https://docusaurus.io/#/myBaseUrl/blog/heading-as-title</link>
<guid>https://docusaurus.io/#/myBaseUrl/blog/heading-as-title</guid>
<pubDate>Wed, 02 Jan 2019 00:00:00 GMT</pubDate>
</item>
<item>
<title><![CDATA[date-matter]]></title>
<link>https://docusaurus.io/#/myBaseUrl/blog/date-matter</link>
<guid>https://docusaurus.io/#/myBaseUrl/blog/date-matter</guid>
<pubDate>Tue, 01 Jan 2019 00:00:00 GMT</pubDate>
<description><![CDATA[date inside front matter]]></description>
<category>date</category>
</item>
<item>
<title><![CDATA[Happy 1st Birthday Slash! (translated)]]></title>
<link>https://docusaurus.io/#/myBaseUrl/blog/2018/12/14/Happy-First-Birthday-Slash</link>
<guid>https://docusaurus.io/#/myBaseUrl/blog/2018/12/14/Happy-First-Birthday-Slash</guid>
<pubDate>Fri, 14 Dec 2018 00:00:00 GMT</pubDate>
<description><![CDATA[Happy birthday! (translated)]]></description>
<author>lorber.sebastien@gmail.com (Sébastien Lorber (translated))</author>
</item>
</channel>
</rss>",
]
`;
26 changes: 24 additions & 2 deletions packages/docusaurus-plugin-content-blog/src/__tests__/feed.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import type {
I18n,
DocusaurusConfig,
MarkdownConfig,
RouterType,
} from '@docusaurus/types';
import type {BlogContentPaths} from '../types';
import type {FeedType, PluginOptions} from '@docusaurus/plugin-content-blog';
Expand Down Expand Up @@ -100,10 +101,14 @@ function pluginOptions(
});
}

function siteFor(siteDir: string, siteOptions?: {baseUrl?: string}) {
function siteFor(
siteDir: string,
siteOptions?: {baseUrl?: string; router?: RouterType},
) {
const siteConfig = partial<DocusaurusConfig>({
title: 'Hello',
baseUrl: siteOptions?.baseUrl ?? '/',
router: siteOptions?.router,
baseUrl: siteOptions?.baseUrl,
url: 'https://docusaurus.io',
favicon: 'image/favicon.ico',
markdown,
Expand Down Expand Up @@ -149,6 +154,23 @@ describe.each(['atom', 'rss', 'json'] as FeedType[])('%s', (feedType) => {
fsMock.mockClear();
});

it('has feed item for each post using hash router', async () => {
const siteDir = path.join(__dirname, '__fixtures__', 'website');
const {loadContext} = siteFor(siteDir, {
baseUrl: '/myBaseUrl/',
router: 'hash',
});

// Build is quite difficult to mock, so we built the blog beforehand and
// copied the output to the fixture...
await testGenerateFeeds(loadContext, pluginOptions(feedType));

expect(
fsMock.mock.calls.map((call) => call[1] as string),
).toMatchSnapshot();
fsMock.mockClear();
});

it('filters to the first two entries', async () => {
const siteDir = path.join(__dirname, '__fixtures__', 'website');
const {loadContext} = siteFor(siteDir, {
Expand Down
Loading
Loading