@docusaurus/plugin-content-blog 0.0.0-5943 → 0.0.0-5946

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/feed.d.ts CHANGED
@@ -5,7 +5,7 @@
5
5
  * LICENSE file in the root directory of this source tree.
6
6
  */
7
7
  /// <reference path="../src/plugin-content-blog.d.ts" />
8
- import type { DocusaurusConfig } from '@docusaurus/types';
8
+ import type { DocusaurusConfig, HtmlTags, LoadContext } from '@docusaurus/types';
9
9
  import type { PluginOptions, BlogPost } from '@docusaurus/plugin-content-blog';
10
10
  export declare function createBlogFeedFiles({ blogPosts: allBlogPosts, options, siteConfig, outDir, locale, }: {
11
11
  blogPosts: BlogPost[];
@@ -14,3 +14,7 @@ export declare function createBlogFeedFiles({ blogPosts: allBlogPosts, options,
14
14
  outDir: string;
15
15
  locale: string;
16
16
  }): Promise<void>;
17
+ export declare function createFeedHtmlHeadTags({ context, options, }: {
18
+ context: LoadContext;
19
+ options: PluginOptions;
20
+ }): HtmlTags;
package/lib/feed.js CHANGED
@@ -6,7 +6,7 @@
6
6
  * LICENSE file in the root directory of this source tree.
7
7
  */
8
8
  Object.defineProperty(exports, "__esModule", { value: true });
9
- exports.createBlogFeedFiles = void 0;
9
+ exports.createFeedHtmlHeadTags = exports.createBlogFeedFiles = void 0;
10
10
  const tslib_1 = require("tslib");
11
11
  const path_1 = tslib_1.__importDefault(require("path"));
12
12
  const fs_extra_1 = tslib_1.__importDefault(require("fs-extra"));
@@ -151,3 +151,46 @@ async function createBlogFeedFiles({ blogPosts: allBlogPosts, options, siteConfi
151
151
  })));
152
152
  }
153
153
  exports.createBlogFeedFiles = createBlogFeedFiles;
154
+ function createFeedHtmlHeadTags({ context, options, }) {
155
+ const feedTypes = options.feedOptions.type;
156
+ if (!feedTypes) {
157
+ return [];
158
+ }
159
+ const feedTitle = options.feedOptions.title ?? context.siteConfig.title;
160
+ const feedsConfig = {
161
+ rss: {
162
+ type: 'application/rss+xml',
163
+ path: 'rss.xml',
164
+ title: `${feedTitle} RSS Feed`,
165
+ },
166
+ atom: {
167
+ type: 'application/atom+xml',
168
+ path: 'atom.xml',
169
+ title: `${feedTitle} Atom Feed`,
170
+ },
171
+ json: {
172
+ type: 'application/json',
173
+ path: 'feed.json',
174
+ title: `${feedTitle} JSON Feed`,
175
+ },
176
+ };
177
+ const headTags = [];
178
+ feedTypes.forEach((feedType) => {
179
+ const { type, path: feedConfigPath, title: feedConfigTitle, } = feedsConfig[feedType];
180
+ headTags.push({
181
+ tagName: 'link',
182
+ attributes: {
183
+ rel: 'alternate',
184
+ type,
185
+ href: (0, utils_1.normalizeUrl)([
186
+ context.siteConfig.baseUrl,
187
+ options.routeBasePath,
188
+ feedConfigPath,
189
+ ]),
190
+ title: feedConfigTitle,
191
+ },
192
+ });
193
+ });
194
+ return headTags;
195
+ }
196
+ exports.createFeedHtmlHeadTags = createFeedHtmlHeadTags;
package/lib/index.js CHANGED
@@ -16,19 +16,25 @@ const footnoteIDFixer_1 = tslib_1.__importDefault(require("./remark/footnoteIDFi
16
16
  const translations_1 = require("./translations");
17
17
  const feed_1 = require("./feed");
18
18
  const routes_1 = require("./routes");
19
+ const PluginName = 'docusaurus-plugin-content-blog';
19
20
  async function pluginContentBlog(context, options) {
20
21
  const { siteDir, siteConfig, generatedFilesDir, localizationDir, i18n: { currentLocale }, } = context;
22
+ const router = siteConfig.future.experimental_router;
23
+ const isBlogFeedDisabledBecauseOfHashRouter = router === 'hash' && !!options.feedOptions.type;
24
+ if (isBlogFeedDisabledBecauseOfHashRouter) {
25
+ logger_1.default.warn(`${PluginName} feed feature does not support the Hash Router. Feeds won't be generated.`);
26
+ }
21
27
  const { onBrokenMarkdownLinks, baseUrl } = siteConfig;
22
28
  const contentPaths = {
23
29
  contentPath: path_1.default.resolve(siteDir, options.path),
24
30
  contentPathLocalized: (0, utils_1.getPluginI18nPath)({
25
31
  localizationDir,
26
- pluginName: 'docusaurus-plugin-content-blog',
32
+ pluginName: PluginName,
27
33
  pluginId: options.id,
28
34
  }),
29
35
  };
30
36
  const pluginId = options.id ?? utils_1.DEFAULT_PLUGIN_ID;
31
- const pluginDataDirRoot = path_1.default.join(generatedFilesDir, 'docusaurus-plugin-content-blog');
37
+ const pluginDataDirRoot = path_1.default.join(generatedFilesDir, PluginName);
32
38
  const dataDir = path_1.default.join(pluginDataDirRoot, pluginId);
33
39
  // TODO Docusaurus v4 breaking change
34
40
  // module aliasing should be automatic
@@ -39,7 +45,7 @@ async function pluginContentBlog(context, options) {
39
45
  contentPaths,
40
46
  });
41
47
  return {
42
- name: 'docusaurus-plugin-content-blog',
48
+ name: PluginName,
43
49
  getPathsToWatch() {
44
50
  const { include } = options;
45
51
  const contentMarkdownGlobs = (0, utils_1.getContentPathList)(contentPaths).flatMap((contentPath) => include.map((pattern) => `${contentPath}/${pattern}`));
@@ -194,15 +200,13 @@ async function pluginContentBlog(context, options) {
194
200
  };
195
201
  },
196
202
  async postBuild({ outDir, content }) {
197
- if (!options.feedOptions.type) {
198
- return;
199
- }
200
- const { blogPosts } = content;
201
- if (!blogPosts.length) {
203
+ if (!content.blogPosts.length ||
204
+ !options.feedOptions.type ||
205
+ isBlogFeedDisabledBecauseOfHashRouter) {
202
206
  return;
203
207
  }
204
208
  await (0, feed_1.createBlogFeedFiles)({
205
- blogPosts,
209
+ blogPosts: content.blogPosts,
206
210
  options,
207
211
  outDir,
208
212
  siteConfig,
@@ -210,48 +214,12 @@ async function pluginContentBlog(context, options) {
210
214
  });
211
215
  },
212
216
  injectHtmlTags({ content }) {
213
- if (!content.blogPosts.length || !options.feedOptions.type) {
217
+ if (!content.blogPosts.length ||
218
+ !options.feedOptions.type ||
219
+ isBlogFeedDisabledBecauseOfHashRouter) {
214
220
  return {};
215
221
  }
216
- const feedTypes = options.feedOptions.type;
217
- const feedTitle = options.feedOptions.title ?? context.siteConfig.title;
218
- const feedsConfig = {
219
- rss: {
220
- type: 'application/rss+xml',
221
- path: 'rss.xml',
222
- title: `${feedTitle} RSS Feed`,
223
- },
224
- atom: {
225
- type: 'application/atom+xml',
226
- path: 'atom.xml',
227
- title: `${feedTitle} Atom Feed`,
228
- },
229
- json: {
230
- type: 'application/json',
231
- path: 'feed.json',
232
- title: `${feedTitle} JSON Feed`,
233
- },
234
- };
235
- const headTags = [];
236
- feedTypes.forEach((feedType) => {
237
- const { type, path: feedConfigPath, title: feedConfigTitle, } = feedsConfig[feedType];
238
- headTags.push({
239
- tagName: 'link',
240
- attributes: {
241
- rel: 'alternate',
242
- type,
243
- href: (0, utils_1.normalizeUrl)([
244
- baseUrl,
245
- options.routeBasePath,
246
- feedConfigPath,
247
- ]),
248
- title: feedConfigTitle,
249
- },
250
- });
251
- });
252
- return {
253
- headTags,
254
- };
222
+ return { headTags: (0, feed_1.createFeedHtmlHeadTags)({ context, options }) };
255
223
  },
256
224
  };
257
225
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@docusaurus/plugin-content-blog",
3
- "version": "0.0.0-5943",
3
+ "version": "0.0.0-5946",
4
4
  "description": "Blog plugin for Docusaurus.",
5
5
  "main": "lib/index.js",
6
6
  "types": "src/plugin-content-blog.d.ts",
@@ -31,13 +31,13 @@
31
31
  },
32
32
  "license": "MIT",
33
33
  "dependencies": {
34
- "@docusaurus/core": "0.0.0-5943",
35
- "@docusaurus/logger": "0.0.0-5943",
36
- "@docusaurus/mdx-loader": "0.0.0-5943",
37
- "@docusaurus/types": "0.0.0-5943",
38
- "@docusaurus/utils": "0.0.0-5943",
39
- "@docusaurus/utils-common": "0.0.0-5943",
40
- "@docusaurus/utils-validation": "0.0.0-5943",
34
+ "@docusaurus/core": "0.0.0-5946",
35
+ "@docusaurus/logger": "0.0.0-5946",
36
+ "@docusaurus/mdx-loader": "0.0.0-5946",
37
+ "@docusaurus/types": "0.0.0-5946",
38
+ "@docusaurus/utils": "0.0.0-5946",
39
+ "@docusaurus/utils-common": "0.0.0-5946",
40
+ "@docusaurus/utils-validation": "0.0.0-5946",
41
41
  "cheerio": "^1.0.0-rc.12",
42
42
  "feed": "^4.2.2",
43
43
  "fs-extra": "^11.1.1",
@@ -59,5 +59,5 @@
59
59
  "devDependencies": {
60
60
  "@total-typescript/shoehorn": "^0.1.2"
61
61
  },
62
- "gitHead": "dedcca39baa1c594fc3a99781942242fd165534f"
62
+ "gitHead": "22332e32d47aea6bc27ca36b2ef50f12cd1427c8"
63
63
  }
package/src/feed.ts CHANGED
@@ -16,7 +16,7 @@ import {
16
16
  applyTrailingSlash,
17
17
  } from '@docusaurus/utils-common';
18
18
  import {load as cheerioLoad} from 'cheerio';
19
- import type {DocusaurusConfig} from '@docusaurus/types';
19
+ import type {DocusaurusConfig, HtmlTags, LoadContext} from '@docusaurus/types';
20
20
  import type {
21
21
  FeedType,
22
22
  PluginOptions,
@@ -254,3 +254,59 @@ export async function createBlogFeedFiles({
254
254
  ),
255
255
  );
256
256
  }
257
+
258
+ export function createFeedHtmlHeadTags({
259
+ context,
260
+ options,
261
+ }: {
262
+ context: LoadContext;
263
+ options: PluginOptions;
264
+ }): HtmlTags {
265
+ const feedTypes = options.feedOptions.type;
266
+ if (!feedTypes) {
267
+ return [];
268
+ }
269
+ const feedTitle = options.feedOptions.title ?? context.siteConfig.title;
270
+ const feedsConfig = {
271
+ rss: {
272
+ type: 'application/rss+xml',
273
+ path: 'rss.xml',
274
+ title: `${feedTitle} RSS Feed`,
275
+ },
276
+ atom: {
277
+ type: 'application/atom+xml',
278
+ path: 'atom.xml',
279
+ title: `${feedTitle} Atom Feed`,
280
+ },
281
+ json: {
282
+ type: 'application/json',
283
+ path: 'feed.json',
284
+ title: `${feedTitle} JSON Feed`,
285
+ },
286
+ };
287
+ const headTags: HtmlTags = [];
288
+
289
+ feedTypes.forEach((feedType) => {
290
+ const {
291
+ type,
292
+ path: feedConfigPath,
293
+ title: feedConfigTitle,
294
+ } = feedsConfig[feedType];
295
+
296
+ headTags.push({
297
+ tagName: 'link',
298
+ attributes: {
299
+ rel: 'alternate',
300
+ type,
301
+ href: normalizeUrl([
302
+ context.siteConfig.baseUrl,
303
+ options.routeBasePath,
304
+ feedConfigPath,
305
+ ]),
306
+ title: feedConfigTitle,
307
+ },
308
+ });
309
+ });
310
+
311
+ return headTags;
312
+ }
package/src/index.ts CHANGED
@@ -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
  }