@@ -29,11 +29,11 @@ import {
29
29
} from './blogUtils' ;
30
30
import footnoteIDFixer from './remark/footnoteIDFixer' ;
31
31
import { translateContent , getTranslationFiles } from './translations' ;
32
- import { createBlogFeedFiles } from './feed' ;
32
+ import { createBlogFeedFiles , createFeedHtmlHeadTags } from './feed' ;
33
33
34
34
import { createAllRoutes } from './routes' ;
35
35
import type { BlogContentPaths , BlogMarkdownLoaderOptions } from './types' ;
36
- import type { LoadContext , Plugin , HtmlTags } from '@docusaurus/types' ;
36
+ import type { LoadContext , Plugin } from '@docusaurus/types' ;
37
37
import type {
38
38
PluginOptions ,
39
39
BlogPostFrontMatter ,
@@ -44,6 +44,8 @@ import type {
44
44
BlogPaginated ,
45
45
} from '@docusaurus/plugin-content-blog' ;
46
46
47
+ const PluginName = 'docusaurus-plugin-content-blog' ;
48
+
47
49
export default async function pluginContentBlog (
48
50
context : LoadContext ,
49
51
options : PluginOptions ,
@@ -55,22 +57,29 @@ export default async function pluginContentBlog(
55
57
localizationDir,
56
58
i18n : { currentLocale} ,
57
59
} = context ;
60
+
61
+ const router = siteConfig . future . experimental_router ;
62
+ const isBlogFeedDisabledBecauseOfHashRouter =
63
+ router === 'hash' && ! ! options . feedOptions . type ;
64
+ if ( isBlogFeedDisabledBecauseOfHashRouter ) {
65
+ logger . warn (
66
+ `${ PluginName } feed feature does not support the Hash Router. Feeds won't be generated.` ,
67
+ ) ;
68
+ }
69
+
58
70
const { onBrokenMarkdownLinks, baseUrl} = siteConfig ;
59
71
60
72
const contentPaths : BlogContentPaths = {
61
73
contentPath : path . resolve ( siteDir , options . path ) ,
62
74
contentPathLocalized : getPluginI18nPath ( {
63
75
localizationDir,
64
- pluginName : 'docusaurus-plugin-content-blog' ,
76
+ pluginName : PluginName ,
65
77
pluginId : options . id ,
66
78
} ) ,
67
79
} ;
68
80
const pluginId = options . id ?? DEFAULT_PLUGIN_ID ;
69
81
70
- const pluginDataDirRoot = path . join (
71
- generatedFilesDir ,
72
- 'docusaurus-plugin-content-blog' ,
73
- ) ;
82
+ const pluginDataDirRoot = path . join ( generatedFilesDir , PluginName ) ;
74
83
const dataDir = path . join ( pluginDataDirRoot , pluginId ) ;
75
84
// TODO Docusaurus v4 breaking change
76
85
// module aliasing should be automatic
@@ -84,7 +93,7 @@ export default async function pluginContentBlog(
84
93
} ) ;
85
94
86
95
return {
87
- name : 'docusaurus-plugin-content-blog' ,
96
+ name : PluginName ,
88
97
89
98
getPathsToWatch ( ) {
90
99
const { include} = options ;
@@ -295,15 +304,16 @@ export default async function pluginContentBlog(
295
304
} ,
296
305
297
306
async postBuild ( { outDir, content} ) {
298
- if ( ! options . feedOptions . type ) {
299
- return ;
300
- }
301
- const { blogPosts } = content ;
302
- if ( ! blogPosts . length ) {
307
+ if (
308
+ ! content . blogPosts . length ||
309
+ ! options . feedOptions . type ||
310
+ isBlogFeedDisabledBecauseOfHashRouter
311
+ ) {
303
312
return ;
304
313
}
314
+
305
315
await createBlogFeedFiles ( {
306
- blogPosts,
316
+ blogPosts : content . blogPosts ,
307
317
options,
308
318
outDir,
309
319
siteConfig,
@@ -312,56 +322,15 @@ export default async function pluginContentBlog(
312
322
} ,
313
323
314
324
injectHtmlTags ( { content} ) {
315
- if ( ! content . blogPosts . length || ! options . feedOptions . type ) {
325
+ if (
326
+ ! content . blogPosts . length ||
327
+ ! options . feedOptions . type ||
328
+ isBlogFeedDisabledBecauseOfHashRouter
329
+ ) {
316
330
return { } ;
317
331
}
318
332
319
- const feedTypes = options . feedOptions . type ;
320
- const feedTitle = options . feedOptions . title ?? context . siteConfig . title ;
321
- const feedsConfig = {
322
- rss : {
323
- type : 'application/rss+xml' ,
324
- path : 'rss.xml' ,
325
- title : `${ feedTitle } RSS Feed` ,
326
- } ,
327
- atom : {
328
- type : 'application/atom+xml' ,
329
- path : 'atom.xml' ,
330
- title : `${ feedTitle } Atom Feed` ,
331
- } ,
332
- json : {
333
- type : 'application/json' ,
334
- path : 'feed.json' ,
335
- title : `${ feedTitle } JSON Feed` ,
336
- } ,
337
- } ;
338
- const headTags : HtmlTags = [ ] ;
339
-
340
- feedTypes . forEach ( ( feedType ) => {
341
- const {
342
- type,
343
- path : feedConfigPath ,
344
- title : feedConfigTitle ,
345
- } = feedsConfig [ feedType ] ;
346
-
347
- headTags . push ( {
348
- tagName : 'link' ,
349
- attributes : {
350
- rel : 'alternate' ,
351
- type,
352
- href : normalizeUrl ( [
353
- baseUrl ,
354
- options . routeBasePath ,
355
- feedConfigPath ,
356
- ] ) ,
357
- title : feedConfigTitle ,
358
- } ,
359
- } ) ;
360
- } ) ;
361
-
362
- return {
363
- headTags,
364
- } ;
333
+ return { headTags : createFeedHtmlHeadTags ( { context, options} ) } ;
365
334
} ,
366
335
} ;
367
336
}
0 commit comments