MCPcopy
hub / github.com/facebook/docusaurus / generateBlogFeed

Function generateBlogFeed

packages/docusaurus-plugin-content-blog/src/feed.ts:35–93  ·  view source on GitHub ↗
({
  blogPosts,
  options,
  siteConfig,
  outDir,
  locale,
}: {
  blogPosts: BlogPost[];
  options: PluginOptions;
  siteConfig: DocusaurusConfig;
  outDir: string;
  locale: string;
})

Source from the content-addressed store, hash-verified

33} from '@docusaurus/plugin-content-blog';
34
35async function generateBlogFeed({
36 blogPosts,
37 options,
38 siteConfig,
39 outDir,
40 locale,
41}: {
42 blogPosts: BlogPost[];
43 options: PluginOptions;
44 siteConfig: DocusaurusConfig;
45 outDir: string;
46 locale: string;
47}): Promise<Feed | null> {
48 if (!blogPosts.length) {
49 return null;
50 }
51
52 const {feedOptions, routeBasePath} = options;
53 const {url: siteUrl, baseUrl, title, favicon, trailingSlash} = siteConfig;
54 const blogBaseUrl = applyTrailingSlash(
55 normalizeUrl([siteUrl, baseUrl, routeBasePath]),
56 {
57 trailingSlash,
58 baseUrl,
59 },
60 );
61
62 const blogPostsForFeed =
63 feedOptions.limit === false || feedOptions.limit === null
64 ? blogPosts
65 : blogPosts.slice(0, feedOptions.limit);
66
67 const updated = blogPostsForFeed[0]?.metadata.date;
68
69 const feed = new Feed({
70 id: blogBaseUrl,
71 title: feedOptions.title ?? `${title} Blog`,
72 updated,
73 language: feedOptions.language ?? locale,
74 link: blogBaseUrl,
75 description: feedOptions.description ?? `${siteConfig.title} Blog`,
76 favicon: favicon ? normalizeUrl([siteUrl, baseUrl, favicon]) : undefined,
77 copyright: feedOptions.copyright,
78 });
79
80 const createFeedItems =
81 options.feedOptions.createFeedItems ?? defaultCreateFeedItems;
82
83 const feedItems = await createFeedItems({
84 blogPosts: blogPostsForFeed,
85 siteConfig,
86 outDir,
87 defaultCreateFeedItems,
88 });
89
90 feedItems.forEach(feed.addItem);
91
92 return feed;

Callers 1

createBlogFeedFilesFunction · 0.85

Calls 2

applyTrailingSlashFunction · 0.90
normalizeUrlFunction · 0.90

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…