Skip to content

Commit cb8718a

Browse files
feat: adds blog archive route (facebook#5428)
* [feature] adds blog archive route * Update plugin-content-blog.md * fix TS issues + minor refactors * remove useless css * add translation apis * add missing translations Co-authored-by: slorber <lorber.sebastien@gmail.com>
1 parent e5d9ff1 commit cb8718a

File tree

28 files changed

+177
-4
lines changed

28 files changed

+177
-4
lines changed

packages/docusaurus-plugin-content-blog/src/index.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,8 @@ export default function pluginContentBlog(
225225
blogPostComponent,
226226
blogTagsListComponent,
227227
blogTagsPostsComponent,
228+
routeBasePath,
229+
archiveBasePath,
228230
} = options;
229231

230232
const {addRoute, createData} = actions;
@@ -243,6 +245,26 @@ export default function pluginContentBlog(
243245
? blogPosts
244246
: take(blogPosts, options.blogSidebarCount);
245247

248+
const archiveUrl = normalizeUrl([
249+
baseUrl,
250+
routeBasePath,
251+
archiveBasePath,
252+
]);
253+
254+
// creates a blog archive route
255+
const archiveProp = await createData(
256+
`${docuHash(archiveUrl)}.json`,
257+
JSON.stringify({blogPosts}, null, 2),
258+
);
259+
addRoute({
260+
path: archiveUrl,
261+
component: '@theme/BlogArchivePage',
262+
exact: true,
263+
modules: {
264+
archive: aliasedSource(archiveProp),
265+
},
266+
});
267+
246268
// This prop is useful to provide the blog list sidebar
247269
const sidebarProp = await createData(
248270
// Note that this created data path must be in sync with

packages/docusaurus-plugin-content-blog/src/plugin-content-blog.d.ts

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -70,10 +70,6 @@ declare module '@theme/BlogListPage' {
7070
import type {Content} from '@theme/BlogPostPage';
7171
import type {BlogSidebar} from '@theme/BlogSidebar';
7272

73-
export type Item = {
74-
readonly content: () => JSX.Element;
75-
};
76-
7773
export type Metadata = {
7874
readonly blogTitle: string;
7975
readonly blogDescription: string;
@@ -130,3 +126,17 @@ declare module '@theme/BlogTagsPostsPage' {
130126
const BlogTagsPostsPage: (props: Props) => JSX.Element;
131127
export default BlogTagsPostsPage;
132128
}
129+
130+
declare module '@theme/BlogArchivePage' {
131+
import type {Content} from '@theme/BlogPostPage';
132+
133+
export type ArchiveBlogPost = Content;
134+
135+
export type Props = {
136+
readonly archive: {
137+
blogPosts: readonly ArchiveBlogPost[];
138+
};
139+
};
140+
141+
export default function BlogArchivePage(props: Props): JSX.Element;
142+
}

packages/docusaurus-plugin-content-blog/src/pluginOptionSchema.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,15 @@ export const DEFAULT_OPTIONS: PluginOptions = {
3636
include: ['**/*.{md,mdx}'],
3737
exclude: GlobExcludeDefault,
3838
routeBasePath: 'blog',
39+
archiveBasePath: 'archive',
3940
path: 'blog',
4041
editLocalizedFiles: false,
4142
authorsMapPath: 'authors.yml',
4243
};
4344

4445
export const PluginOptionSchema = Joi.object<PluginOptions>({
4546
path: Joi.string().default(DEFAULT_OPTIONS.path),
47+
archiveBasePath: Joi.string().default(DEFAULT_OPTIONS.archiveBasePath),
4648
routeBasePath: Joi.string()
4749
// '' not allowed, see https://github.com/facebook/docusaurus/issues/3374
4850
// .allow('')

packages/docusaurus-plugin-content-blog/src/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ export interface PluginOptions extends RemarkAndRehypePluginOptions {
3535
id?: string;
3636
path: string;
3737
routeBasePath: string;
38+
archiveBasePath: string;
3839
include: string[];
3940
exclude: string[];
4041
postsPerPage: number | 'ALL';

packages/docusaurus-theme-classic/codeTranslations/ar.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121
"theme.SearchPage.inputPlaceholder": "اكتب ما تبحث عنه هنا",
2222
"theme.SearchPage.noResultsText": "لم يتم العثور على نتائج",
2323
"theme.TOCCollapsible.toggleButtonLabel": "محتويات هذه الصفحة",
24+
"theme.blog.archive.description": "Archive",
25+
"theme.blog.archive.title": "Archive",
2426
"theme.blog.paginator.navAriaLabel": "التنقل في صفحة قائمة المدونة",
2527
"theme.blog.paginator.newerEntries": "إدخالات أحدث",
2628
"theme.blog.paginator.olderEntries": "إدخالات أقدم",

packages/docusaurus-theme-classic/codeTranslations/base.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,10 @@
4343
"theme.SearchPage.noResultsText___DESCRIPTION": "The paragraph for empty search result",
4444
"theme.TOCCollapsible.toggleButtonLabel": "On this page",
4545
"theme.TOCCollapsible.toggleButtonLabel___DESCRIPTION": "The label used by the button on the collapsible TOC component",
46+
"theme.blog.archive.description": "Archive",
47+
"theme.blog.archive.description___DESCRIPTION": "The page & hero description of the blog archive page",
48+
"theme.blog.archive.title": "Archive",
49+
"theme.blog.archive.title___DESCRIPTION": "The page & hero title of the blog archive page",
4650
"theme.blog.paginator.navAriaLabel": "Blog list page navigation",
4751
"theme.blog.paginator.navAriaLabel___DESCRIPTION": "The ARIA label for the blog pagination",
4852
"theme.blog.paginator.newerEntries": "Newer Entries",

packages/docusaurus-theme-classic/codeTranslations/bn.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121
"theme.SearchPage.inputPlaceholder": "আপনার অনুসন্ধান এখানে টাইপ করুন",
2222
"theme.SearchPage.noResultsText": "কোন ফলাফল পাওয়া যায়নি",
2323
"theme.TOCCollapsible.toggleButtonLabel": "এই পেজ এ রয়েছে",
24+
"theme.blog.archive.description": "Archive",
25+
"theme.blog.archive.title": "Archive",
2426
"theme.blog.paginator.navAriaLabel": "ব্লগ তালিকা পেজ নেভিগেশন",
2527
"theme.blog.paginator.newerEntries": "নতুন এন্ট্রি",
2628
"theme.blog.paginator.olderEntries": "পুরানো এন্ট্রি",

packages/docusaurus-theme-classic/codeTranslations/cs.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121
"theme.SearchPage.inputPlaceholder": "Zde napište hledaný text",
2222
"theme.SearchPage.noResultsText": "Nic nebylo nalezeno",
2323
"theme.TOCCollapsible.toggleButtonLabel": "Na této stránce",
24+
"theme.blog.archive.description": "Archive",
25+
"theme.blog.archive.title": "Archive",
2426
"theme.blog.paginator.navAriaLabel": "Stránkování článků na blogu",
2527
"theme.blog.paginator.newerEntries": "Novější záznamy",
2628
"theme.blog.paginator.olderEntries": "Starší záznamy",

packages/docusaurus-theme-classic/codeTranslations/da.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121
"theme.SearchPage.inputPlaceholder": "Indtast din søgning her",
2222
"theme.SearchPage.noResultsText": "Ingen resultater fundet",
2323
"theme.TOCCollapsible.toggleButtonLabel": "On this page",
24+
"theme.blog.archive.description": "Archive",
25+
"theme.blog.archive.title": "Archive",
2426
"theme.blog.paginator.navAriaLabel": "Blogoversigt navigation",
2527
"theme.blog.paginator.newerEntries": "Nyere indslag",
2628
"theme.blog.paginator.olderEntries": "Tidligere indslag",

packages/docusaurus-theme-classic/codeTranslations/de.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121
"theme.SearchPage.inputPlaceholder": "Geben Sie hier Ihre Suche ein",
2222
"theme.SearchPage.noResultsText": "Es wurden keine Ergebnisse gefunden",
2323
"theme.TOCCollapsible.toggleButtonLabel": "On this page",
24+
"theme.blog.archive.description": "Archive",
25+
"theme.blog.archive.title": "Archive",
2426
"theme.blog.paginator.navAriaLabel": "Navigation der Blog-Listenseite",
2527
"theme.blog.paginator.newerEntries": "Neuere Einträge",
2628
"theme.blog.paginator.olderEntries": "Ältere Einträge",

0 commit comments

Comments
 (0)