mirror of
https://github.com/facebook/docusaurus.git
synced 2025-08-02 00:09:48 +02:00
feat(blog): add options.createFeedItems to filter/limit/transform feed items (#8378)
Co-authored-by: sebastienlorber <lorber.sebastien@gmail.com>
This commit is contained in:
parent
0985fa0af3
commit
022e00554e
7 changed files with 249 additions and 8 deletions
|
@ -511,6 +511,17 @@ type BlogOptions = {
|
|||
description?: string;
|
||||
copyright: string;
|
||||
language?: string; // possible values: http://www.w3.org/TR/REC-html40/struct/dirlang.html#langcodes
|
||||
/** Allow control over the construction of BlogFeedItems */
|
||||
createFeedItems?: (params: {
|
||||
blogPosts: BlogPost[];
|
||||
siteConfig: DocusaurusConfig;
|
||||
outDir: string;
|
||||
defaultCreateFeedItems: (params: {
|
||||
blogPosts: BlogPost[];
|
||||
siteConfig: DocusaurusConfig;
|
||||
outDir: string;
|
||||
}) => Promise<BlogFeedItem[]>;
|
||||
}) => Promise<BlogFeedItem[]>;
|
||||
};
|
||||
};
|
||||
```
|
||||
|
@ -529,6 +540,14 @@ module.exports = {
|
|||
feedOptions: {
|
||||
type: 'all',
|
||||
copyright: `Copyright © ${new Date().getFullYear()} Facebook, Inc.`,
|
||||
createFeedItems: async (params) => {
|
||||
const {blogPosts, defaultCreateFeedItems, ...rest} = params;
|
||||
return defaultCreateFeedItems({
|
||||
// keep only the 10 most recent blog posts in the feed
|
||||
blogPosts: blogPosts.filter((item, index) => index < 10),
|
||||
...rest,
|
||||
});
|
||||
},
|
||||
},
|
||||
// highlight-end
|
||||
},
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue