@docusaurus/plugin-content-blog 0.0.0-5848 → 0.0.0-5853
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.d.ts +4 -0
- package/lib/blogUtils.js +9 -1
- package/lib/index.js +5 -1
- package/lib/options.js +4 -0
- package/package.json +12 -9
- package/src/blogUtils.ts +16 -0
- package/src/index.ts +7 -2
- package/src/options.ts +4 -0
- package/src/plugin-content-blog.d.ts +9 -0
package/lib/blogUtils.d.ts
CHANGED
|
@@ -39,4 +39,8 @@ export type LinkifyParams = {
|
|
|
39
39
|
fileString: string;
|
|
40
40
|
} & Pick<BlogMarkdownLoaderOptions, 'sourceToPermalink' | 'siteDir' | 'contentPaths' | 'onBrokenMarkdownLink'>;
|
|
41
41
|
export declare function linkify({ filePath, contentPaths, fileString, siteDir, sourceToPermalink, onBrokenMarkdownLink, }: LinkifyParams): string;
|
|
42
|
+
export declare function applyProcessBlogPosts({ blogPosts, processBlogPosts, }: {
|
|
43
|
+
blogPosts: BlogPost[];
|
|
44
|
+
processBlogPosts: PluginOptions['processBlogPosts'];
|
|
45
|
+
}): Promise<BlogPost[]>;
|
|
42
46
|
export {};
|
package/lib/blogUtils.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.linkify = exports.generateBlogPosts = exports.parseBlogFileName = exports.getBlogTags = exports.shouldBeListed = exports.paginateBlogPosts = exports.getSourceToPermalink = exports.truncate = void 0;
|
|
9
|
+
exports.applyProcessBlogPosts = exports.linkify = exports.generateBlogPosts = exports.parseBlogFileName = exports.getBlogTags = exports.shouldBeListed = exports.paginateBlogPosts = exports.getSourceToPermalink = exports.truncate = void 0;
|
|
10
10
|
const tslib_1 = require("tslib");
|
|
11
11
|
const fs_extra_1 = tslib_1.__importDefault(require("fs-extra"));
|
|
12
12
|
const path_1 = tslib_1.__importDefault(require("path"));
|
|
@@ -261,3 +261,11 @@ function linkify({ filePath, contentPaths, fileString, siteDir, sourceToPermalin
|
|
|
261
261
|
return newContent;
|
|
262
262
|
}
|
|
263
263
|
exports.linkify = linkify;
|
|
264
|
+
async function applyProcessBlogPosts({ blogPosts, processBlogPosts, }) {
|
|
265
|
+
const processedBlogPosts = await processBlogPosts({ blogPosts });
|
|
266
|
+
if (Array.isArray(processedBlogPosts)) {
|
|
267
|
+
return processedBlogPosts;
|
|
268
|
+
}
|
|
269
|
+
return blogPosts;
|
|
270
|
+
}
|
|
271
|
+
exports.applyProcessBlogPosts = applyProcessBlogPosts;
|
package/lib/index.js
CHANGED
|
@@ -50,7 +50,11 @@ async function pluginContentBlog(context, options) {
|
|
|
50
50
|
const { postsPerPage: postsPerPageOption, routeBasePath, tagsBasePath, blogDescription, blogTitle, blogSidebarTitle, pageBasePath, } = options;
|
|
51
51
|
const baseBlogUrl = (0, utils_1.normalizeUrl)([baseUrl, routeBasePath]);
|
|
52
52
|
const blogTagsListPath = (0, utils_1.normalizeUrl)([baseBlogUrl, tagsBasePath]);
|
|
53
|
-
|
|
53
|
+
let blogPosts = await (0, blogUtils_1.generateBlogPosts)(contentPaths, context, options);
|
|
54
|
+
blogPosts = await (0, blogUtils_1.applyProcessBlogPosts)({
|
|
55
|
+
blogPosts,
|
|
56
|
+
processBlogPosts: options.processBlogPosts,
|
|
57
|
+
});
|
|
54
58
|
const listedBlogPosts = blogPosts.filter(blogUtils_1.shouldBeListed);
|
|
55
59
|
if (!blogPosts.length) {
|
|
56
60
|
return {
|
package/lib/options.js
CHANGED
|
@@ -39,6 +39,7 @@ exports.DEFAULT_OPTIONS = {
|
|
|
39
39
|
authorsMapPath: 'authors.yml',
|
|
40
40
|
readingTime: ({ content, defaultReadingTime }) => defaultReadingTime({ content }),
|
|
41
41
|
sortPosts: 'descending',
|
|
42
|
+
processBlogPosts: async () => undefined,
|
|
42
43
|
};
|
|
43
44
|
const PluginOptionSchema = utils_validation_1.Joi.object({
|
|
44
45
|
path: utils_validation_1.Joi.string().default(exports.DEFAULT_OPTIONS.path),
|
|
@@ -103,6 +104,9 @@ const PluginOptionSchema = utils_validation_1.Joi.object({
|
|
|
103
104
|
sortPosts: utils_validation_1.Joi.string()
|
|
104
105
|
.valid('descending', 'ascending')
|
|
105
106
|
.default(exports.DEFAULT_OPTIONS.sortPosts),
|
|
107
|
+
processBlogPosts: utils_validation_1.Joi.function()
|
|
108
|
+
.optional()
|
|
109
|
+
.default(() => exports.DEFAULT_OPTIONS.processBlogPosts),
|
|
106
110
|
}).default(exports.DEFAULT_OPTIONS);
|
|
107
111
|
function validateOptions({ validate, options, }) {
|
|
108
112
|
const validatedOptions = validate(PluginOptionSchema, options);
|
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-5853",
|
|
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-
|
|
35
|
-
"@docusaurus/logger": "0.0.0-
|
|
36
|
-
"@docusaurus/mdx-loader": "0.0.0-
|
|
37
|
-
"@docusaurus/types": "0.0.0-
|
|
38
|
-
"@docusaurus/utils": "0.0.0-
|
|
39
|
-
"@docusaurus/utils-common": "0.0.0-
|
|
40
|
-
"@docusaurus/utils-validation": "0.0.0-
|
|
34
|
+
"@docusaurus/core": "0.0.0-5853",
|
|
35
|
+
"@docusaurus/logger": "0.0.0-5853",
|
|
36
|
+
"@docusaurus/mdx-loader": "0.0.0-5853",
|
|
37
|
+
"@docusaurus/types": "0.0.0-5853",
|
|
38
|
+
"@docusaurus/utils": "0.0.0-5853",
|
|
39
|
+
"@docusaurus/utils-common": "0.0.0-5853",
|
|
40
|
+
"@docusaurus/utils-validation": "0.0.0-5853",
|
|
41
41
|
"cheerio": "^1.0.0-rc.12",
|
|
42
42
|
"feed": "^4.2.2",
|
|
43
43
|
"fs-extra": "^11.1.1",
|
|
@@ -56,5 +56,8 @@
|
|
|
56
56
|
"engines": {
|
|
57
57
|
"node": ">=18.0"
|
|
58
58
|
},
|
|
59
|
-
"
|
|
59
|
+
"devDependencies": {
|
|
60
|
+
"@total-typescript/shoehorn": "^0.1.2"
|
|
61
|
+
},
|
|
62
|
+
"gitHead": "46a93e74e883666a9027425bab1862f859019e3e"
|
|
60
63
|
}
|
package/src/blogUtils.ts
CHANGED
|
@@ -422,3 +422,19 @@ export function linkify({
|
|
|
422
422
|
|
|
423
423
|
return newContent;
|
|
424
424
|
}
|
|
425
|
+
|
|
426
|
+
export async function applyProcessBlogPosts({
|
|
427
|
+
blogPosts,
|
|
428
|
+
processBlogPosts,
|
|
429
|
+
}: {
|
|
430
|
+
blogPosts: BlogPost[];
|
|
431
|
+
processBlogPosts: PluginOptions['processBlogPosts'];
|
|
432
|
+
}): Promise<BlogPost[]> {
|
|
433
|
+
const processedBlogPosts = await processBlogPosts({blogPosts});
|
|
434
|
+
|
|
435
|
+
if (Array.isArray(processedBlogPosts)) {
|
|
436
|
+
return processedBlogPosts;
|
|
437
|
+
}
|
|
438
|
+
|
|
439
|
+
return blogPosts;
|
|
440
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -20,11 +20,12 @@ import {
|
|
|
20
20
|
DEFAULT_PLUGIN_ID,
|
|
21
21
|
} from '@docusaurus/utils';
|
|
22
22
|
import {
|
|
23
|
-
generateBlogPosts,
|
|
24
23
|
getSourceToPermalink,
|
|
25
24
|
getBlogTags,
|
|
26
25
|
paginateBlogPosts,
|
|
27
26
|
shouldBeListed,
|
|
27
|
+
applyProcessBlogPosts,
|
|
28
|
+
generateBlogPosts,
|
|
28
29
|
} from './blogUtils';
|
|
29
30
|
import footnoteIDFixer from './remark/footnoteIDFixer';
|
|
30
31
|
import {translateContent, getTranslationFiles} from './translations';
|
|
@@ -113,7 +114,11 @@ export default async function pluginContentBlog(
|
|
|
113
114
|
|
|
114
115
|
const baseBlogUrl = normalizeUrl([baseUrl, routeBasePath]);
|
|
115
116
|
const blogTagsListPath = normalizeUrl([baseBlogUrl, tagsBasePath]);
|
|
116
|
-
|
|
117
|
+
let blogPosts = await generateBlogPosts(contentPaths, context, options);
|
|
118
|
+
blogPosts = await applyProcessBlogPosts({
|
|
119
|
+
blogPosts,
|
|
120
|
+
processBlogPosts: options.processBlogPosts,
|
|
121
|
+
});
|
|
117
122
|
const listedBlogPosts = blogPosts.filter(shouldBeListed);
|
|
118
123
|
|
|
119
124
|
if (!blogPosts.length) {
|
package/src/options.ts
CHANGED
|
@@ -51,6 +51,7 @@ export const DEFAULT_OPTIONS: PluginOptions = {
|
|
|
51
51
|
authorsMapPath: 'authors.yml',
|
|
52
52
|
readingTime: ({content, defaultReadingTime}) => defaultReadingTime({content}),
|
|
53
53
|
sortPosts: 'descending',
|
|
54
|
+
processBlogPosts: async () => undefined,
|
|
54
55
|
};
|
|
55
56
|
|
|
56
57
|
const PluginOptionSchema = Joi.object<PluginOptions>({
|
|
@@ -134,6 +135,9 @@ const PluginOptionSchema = Joi.object<PluginOptions>({
|
|
|
134
135
|
sortPosts: Joi.string()
|
|
135
136
|
.valid('descending', 'ascending')
|
|
136
137
|
.default(DEFAULT_OPTIONS.sortPosts),
|
|
138
|
+
processBlogPosts: Joi.function()
|
|
139
|
+
.optional()
|
|
140
|
+
.default(() => DEFAULT_OPTIONS.processBlogPosts),
|
|
137
141
|
}).default(DEFAULT_OPTIONS);
|
|
138
142
|
|
|
139
143
|
export function validateOptions({
|
|
@@ -330,6 +330,11 @@ yarn workspace v1.22.19image` is a collocated image path, this entry will be the
|
|
|
330
330
|
defaultReadingTime: ReadingTimeFunction;
|
|
331
331
|
},
|
|
332
332
|
) => number | undefined;
|
|
333
|
+
|
|
334
|
+
export type ProcessBlogPostsFn = (params: {
|
|
335
|
+
blogPosts: BlogPost[];
|
|
336
|
+
}) => Promise<void | BlogPost[]>;
|
|
337
|
+
|
|
333
338
|
/**
|
|
334
339
|
* Plugin options after normalization.
|
|
335
340
|
*/
|
|
@@ -421,6 +426,10 @@ yarn workspace v1.22.19image` is a collocated image path, this entry will be the
|
|
|
421
426
|
readingTime: ReadingTimeFunctionOption;
|
|
422
427
|
/** Governs the direction of blog post sorting. */
|
|
423
428
|
sortPosts: 'ascending' | 'descending';
|
|
429
|
+
/** An optional function which can be used to transform blog posts
|
|
430
|
+
* (filter, modify, delete, etc...).
|
|
431
|
+
*/
|
|
432
|
+
processBlogPosts: ProcessBlogPostsFn;
|
|
424
433
|
};
|
|
425
434
|
|
|
426
435
|
/**
|