@docusaurus/plugin-content-blog 0.0.0-4445 → 0.0.0-4452
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/blogUtils.js +3 -4
- package/lib/index.js +17 -15
- package/lib/pluginOptionSchema.js +3 -1
- package/package.json +8 -8
- package/src/blogUtils.ts +3 -4
- package/src/index.ts +20 -19
- package/src/plugin-content-blog.d.ts +1 -1
- package/src/pluginOptionSchema.ts +3 -1
package/lib/blogUtils.js
CHANGED
|
@@ -33,16 +33,15 @@ function getBlogTags(blogPosts) {
|
|
|
33
33
|
}));
|
|
34
34
|
}
|
|
35
35
|
exports.getBlogTags = getBlogTags;
|
|
36
|
-
const DATE_FILENAME_REGEX = /^(?<date>\d{4}[-/]\d{1,2}[-/]\d{1,2})[-/]?(?<text>.*?)(\/index)?.mdx?$/;
|
|
36
|
+
const DATE_FILENAME_REGEX = /^(?<folder>.*)(?<date>\d{4}[-/]\d{1,2}[-/]\d{1,2})[-/]?(?<text>.*?)(\/index)?.mdx?$/;
|
|
37
37
|
function parseBlogFileName(blogSourceRelative) {
|
|
38
38
|
const dateFilenameMatch = blogSourceRelative.match(DATE_FILENAME_REGEX);
|
|
39
39
|
if (dateFilenameMatch) {
|
|
40
|
-
const dateString = dateFilenameMatch.groups
|
|
41
|
-
const text = dateFilenameMatch.groups.text;
|
|
40
|
+
const { folder, text, date: dateString } = dateFilenameMatch.groups;
|
|
42
41
|
// Always treat dates as UTC by adding the `Z`
|
|
43
42
|
const date = new Date(`${dateString}Z`);
|
|
44
43
|
const slugDate = dateString.replace(/-/g, '/');
|
|
45
|
-
const slug = `/${slugDate}/${text}`;
|
|
44
|
+
const slug = `/${slugDate}/${folder}${text}`;
|
|
46
45
|
return { date, text, slug };
|
|
47
46
|
}
|
|
48
47
|
else {
|
package/lib/index.js
CHANGED
|
@@ -135,21 +135,23 @@ async function pluginContentBlog(context, options) {
|
|
|
135
135
|
const sidebarBlogPosts = options.blogSidebarCount === 'ALL'
|
|
136
136
|
? blogPosts
|
|
137
137
|
: blogPosts.slice(0, options.blogSidebarCount);
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
138
|
+
if (archiveBasePath) {
|
|
139
|
+
const archiveUrl = (0, utils_1.normalizeUrl)([
|
|
140
|
+
baseUrl,
|
|
141
|
+
routeBasePath,
|
|
142
|
+
archiveBasePath,
|
|
143
|
+
]);
|
|
144
|
+
// creates a blog archive route
|
|
145
|
+
const archiveProp = await createData(`${(0, utils_1.docuHash)(archiveUrl)}.json`, JSON.stringify({ blogPosts }, null, 2));
|
|
146
|
+
addRoute({
|
|
147
|
+
path: archiveUrl,
|
|
148
|
+
component: '@theme/BlogArchivePage',
|
|
149
|
+
exact: true,
|
|
150
|
+
modules: {
|
|
151
|
+
archive: aliasedSource(archiveProp),
|
|
152
|
+
},
|
|
153
|
+
});
|
|
154
|
+
}
|
|
153
155
|
// This prop is useful to provide the blog list sidebar
|
|
154
156
|
const sidebarProp = await createData(
|
|
155
157
|
// Note that this created data path must be in sync with
|
|
@@ -40,7 +40,9 @@ exports.DEFAULT_OPTIONS = {
|
|
|
40
40
|
};
|
|
41
41
|
exports.PluginOptionSchema = utils_validation_1.Joi.object({
|
|
42
42
|
path: utils_validation_1.Joi.string().default(exports.DEFAULT_OPTIONS.path),
|
|
43
|
-
archiveBasePath: utils_validation_1.Joi.string()
|
|
43
|
+
archiveBasePath: utils_validation_1.Joi.string()
|
|
44
|
+
.default(exports.DEFAULT_OPTIONS.archiveBasePath)
|
|
45
|
+
.allow(null),
|
|
44
46
|
routeBasePath: utils_validation_1.Joi.string()
|
|
45
47
|
// '' not allowed, see https://github.com/facebook/docusaurus/issues/3374
|
|
46
48
|
// .allow('')
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@docusaurus/plugin-content-blog",
|
|
3
|
-
"version": "0.0.0-
|
|
3
|
+
"version": "0.0.0-4452",
|
|
4
4
|
"description": "Blog plugin for Docusaurus.",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"types": "src/plugin-content-blog.d.ts",
|
|
@@ -18,11 +18,11 @@
|
|
|
18
18
|
},
|
|
19
19
|
"license": "MIT",
|
|
20
20
|
"dependencies": {
|
|
21
|
-
"@docusaurus/core": "0.0.0-
|
|
22
|
-
"@docusaurus/logger": "0.0.0-
|
|
23
|
-
"@docusaurus/mdx-loader": "0.0.0-
|
|
24
|
-
"@docusaurus/utils": "0.0.0-
|
|
25
|
-
"@docusaurus/utils-validation": "0.0.0-
|
|
21
|
+
"@docusaurus/core": "0.0.0-4452",
|
|
22
|
+
"@docusaurus/logger": "0.0.0-4452",
|
|
23
|
+
"@docusaurus/mdx-loader": "0.0.0-4452",
|
|
24
|
+
"@docusaurus/utils": "0.0.0-4452",
|
|
25
|
+
"@docusaurus/utils-validation": "0.0.0-4452",
|
|
26
26
|
"escape-string-regexp": "^4.0.0",
|
|
27
27
|
"feed": "^4.2.2",
|
|
28
28
|
"fs-extra": "^10.0.0",
|
|
@@ -36,7 +36,7 @@
|
|
|
36
36
|
"webpack": "^5.61.0"
|
|
37
37
|
},
|
|
38
38
|
"devDependencies": {
|
|
39
|
-
"@docusaurus/types": "0.0.0-
|
|
39
|
+
"@docusaurus/types": "0.0.0-4452"
|
|
40
40
|
},
|
|
41
41
|
"peerDependencies": {
|
|
42
42
|
"react": "^16.8.4 || ^17.0.0",
|
|
@@ -45,5 +45,5 @@
|
|
|
45
45
|
"engines": {
|
|
46
46
|
"node": ">=14"
|
|
47
47
|
},
|
|
48
|
-
"gitHead": "
|
|
48
|
+
"gitHead": "48cae5712e0a40d5f7e5c2669edcf2de8ae2533f"
|
|
49
49
|
}
|
package/src/blogUtils.ts
CHANGED
|
@@ -63,7 +63,7 @@ export function getBlogTags(blogPosts: BlogPost[]): BlogTags {
|
|
|
63
63
|
}
|
|
64
64
|
|
|
65
65
|
const DATE_FILENAME_REGEX =
|
|
66
|
-
/^(?<date>\d{4}[-/]\d{1,2}[-/]\d{1,2})[-/]?(?<text>.*?)(\/index)?.mdx?$/;
|
|
66
|
+
/^(?<folder>.*)(?<date>\d{4}[-/]\d{1,2}[-/]\d{1,2})[-/]?(?<text>.*?)(\/index)?.mdx?$/;
|
|
67
67
|
|
|
68
68
|
type ParsedBlogFileName = {
|
|
69
69
|
date: Date | undefined;
|
|
@@ -76,12 +76,11 @@ export function parseBlogFileName(
|
|
|
76
76
|
): ParsedBlogFileName {
|
|
77
77
|
const dateFilenameMatch = blogSourceRelative.match(DATE_FILENAME_REGEX);
|
|
78
78
|
if (dateFilenameMatch) {
|
|
79
|
-
const dateString = dateFilenameMatch.groups
|
|
80
|
-
const text = dateFilenameMatch.groups!.text!;
|
|
79
|
+
const {folder, text, date: dateString} = dateFilenameMatch.groups!;
|
|
81
80
|
// Always treat dates as UTC by adding the `Z`
|
|
82
81
|
const date = new Date(`${dateString}Z`);
|
|
83
82
|
const slugDate = dateString.replace(/-/g, '/');
|
|
84
|
-
const slug = `/${slugDate}/${text}`;
|
|
83
|
+
const slug = `/${slugDate}/${folder}${text}`;
|
|
85
84
|
return {date, text, slug};
|
|
86
85
|
} else {
|
|
87
86
|
const text = blogSourceRelative.replace(/(\/index)?\.mdx?$/, '');
|
package/src/index.ts
CHANGED
|
@@ -242,25 +242,26 @@ export default async function pluginContentBlog(
|
|
|
242
242
|
? blogPosts
|
|
243
243
|
: blogPosts.slice(0, options.blogSidebarCount);
|
|
244
244
|
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
245
|
+
if (archiveBasePath) {
|
|
246
|
+
const archiveUrl = normalizeUrl([
|
|
247
|
+
baseUrl,
|
|
248
|
+
routeBasePath,
|
|
249
|
+
archiveBasePath,
|
|
250
|
+
]);
|
|
251
|
+
// creates a blog archive route
|
|
252
|
+
const archiveProp = await createData(
|
|
253
|
+
`${docuHash(archiveUrl)}.json`,
|
|
254
|
+
JSON.stringify({blogPosts}, null, 2),
|
|
255
|
+
);
|
|
256
|
+
addRoute({
|
|
257
|
+
path: archiveUrl,
|
|
258
|
+
component: '@theme/BlogArchivePage',
|
|
259
|
+
exact: true,
|
|
260
|
+
modules: {
|
|
261
|
+
archive: aliasedSource(archiveProp),
|
|
262
|
+
},
|
|
263
|
+
});
|
|
264
|
+
}
|
|
264
265
|
|
|
265
266
|
// This prop is useful to provide the blog list sidebar
|
|
266
267
|
const sidebarProp = await createData(
|
|
@@ -112,7 +112,7 @@ declare module '@docusaurus/plugin-content-blog' {
|
|
|
112
112
|
path: string;
|
|
113
113
|
routeBasePath: string;
|
|
114
114
|
tagsBasePath: string;
|
|
115
|
-
archiveBasePath: string;
|
|
115
|
+
archiveBasePath: string | null;
|
|
116
116
|
include: string[];
|
|
117
117
|
exclude: string[];
|
|
118
118
|
postsPerPage: number | 'ALL';
|
|
@@ -47,7 +47,9 @@ export const DEFAULT_OPTIONS: PluginOptions = {
|
|
|
47
47
|
|
|
48
48
|
export const PluginOptionSchema = Joi.object<PluginOptions>({
|
|
49
49
|
path: Joi.string().default(DEFAULT_OPTIONS.path),
|
|
50
|
-
archiveBasePath: Joi.string()
|
|
50
|
+
archiveBasePath: Joi.string()
|
|
51
|
+
.default(DEFAULT_OPTIONS.archiveBasePath)
|
|
52
|
+
.allow(null),
|
|
51
53
|
routeBasePath: Joi.string()
|
|
52
54
|
// '' not allowed, see https://github.com/facebook/docusaurus/issues/3374
|
|
53
55
|
// .allow('')
|