@docusaurus/plugin-content-blog 0.0.0-4339 → 0.0.0-4350
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/authors.d.ts +3 -6
- package/lib/authors.js +8 -46
- package/lib/blogUtils.d.ts +0 -1
- package/lib/blogUtils.js +2 -7
- package/lib/index.js +4 -5
- package/package.json +8 -9
- package/src/authors.ts +11 -57
- package/src/blogUtils.ts +1 -5
- package/src/index.ts +4 -4
package/lib/authors.d.ts
CHANGED
|
@@ -7,14 +7,11 @@
|
|
|
7
7
|
import { Author, BlogContentPaths } from './types';
|
|
8
8
|
import { BlogPostFrontMatter } from './blogFrontMatter';
|
|
9
9
|
export declare type AuthorsMap = Record<string, Author>;
|
|
10
|
-
export declare function
|
|
11
|
-
export declare function
|
|
12
|
-
declare type AuthorsMapParams = {
|
|
10
|
+
export declare function validateAuthorsMap(content: unknown): AuthorsMap;
|
|
11
|
+
export declare function getAuthorsMap(params: {
|
|
13
12
|
authorsMapPath: string;
|
|
14
13
|
contentPaths: BlogContentPaths;
|
|
15
|
-
}
|
|
16
|
-
export declare function getAuthorsMapFilePath({ authorsMapPath, contentPaths, }: AuthorsMapParams): Promise<string | undefined>;
|
|
17
|
-
export declare function getAuthorsMap(params: AuthorsMapParams): Promise<AuthorsMap | undefined>;
|
|
14
|
+
}): Promise<AuthorsMap | undefined>;
|
|
18
15
|
declare type AuthorsParam = {
|
|
19
16
|
frontMatter: BlogPostFrontMatter;
|
|
20
17
|
authorsMap: AuthorsMap | undefined;
|
package/lib/authors.js
CHANGED
|
@@ -6,15 +6,9 @@
|
|
|
6
6
|
* LICENSE file in the root directory of this source tree.
|
|
7
7
|
*/
|
|
8
8
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
-
exports.getBlogPostAuthors = exports.getAuthorsMap = exports.
|
|
10
|
-
const tslib_1 = require("tslib");
|
|
11
|
-
const fs_extra_1 = (0, tslib_1.__importDefault)(require("fs-extra"));
|
|
12
|
-
const logger_1 = (0, tslib_1.__importDefault)(require("@docusaurus/logger"));
|
|
13
|
-
const path_1 = (0, tslib_1.__importDefault)(require("path"));
|
|
9
|
+
exports.getBlogPostAuthors = exports.getAuthorsMap = exports.validateAuthorsMap = void 0;
|
|
14
10
|
const utils_1 = require("@docusaurus/utils");
|
|
15
11
|
const utils_validation_1 = require("@docusaurus/utils-validation");
|
|
16
|
-
const blogUtils_1 = require("./blogUtils");
|
|
17
|
-
const js_yaml_1 = (0, tslib_1.__importDefault)(require("js-yaml"));
|
|
18
12
|
const AuthorsMapSchema = utils_validation_1.Joi.object().pattern(utils_validation_1.Joi.string(), utils_validation_1.Joi.object({
|
|
19
13
|
name: utils_validation_1.Joi.string().required(),
|
|
20
14
|
url: utils_validation_1.URISchema,
|
|
@@ -24,48 +18,16 @@ const AuthorsMapSchema = utils_validation_1.Joi.object().pattern(utils_validatio
|
|
|
24
18
|
.rename('image_url', 'imageURL')
|
|
25
19
|
.unknown()
|
|
26
20
|
.required());
|
|
27
|
-
function
|
|
21
|
+
function validateAuthorsMap(content) {
|
|
28
22
|
return utils_validation_1.Joi.attempt(content, AuthorsMapSchema);
|
|
29
23
|
}
|
|
30
|
-
exports.
|
|
31
|
-
async function readAuthorsMapFile(filePath) {
|
|
32
|
-
if (await fs_extra_1.default.pathExists(filePath)) {
|
|
33
|
-
const contentString = await fs_extra_1.default.readFile(filePath, { encoding: 'utf8' });
|
|
34
|
-
try {
|
|
35
|
-
const unsafeContent = js_yaml_1.default.load(contentString);
|
|
36
|
-
return validateAuthorsMapFile(unsafeContent);
|
|
37
|
-
}
|
|
38
|
-
catch (e) {
|
|
39
|
-
// TODO replace later by error cause: see https://v8.dev/features/error-cause
|
|
40
|
-
logger_1.default.error('The author list file looks invalid!');
|
|
41
|
-
throw e;
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
return undefined;
|
|
45
|
-
}
|
|
46
|
-
exports.readAuthorsMapFile = readAuthorsMapFile;
|
|
47
|
-
async function getAuthorsMapFilePath({ authorsMapPath, contentPaths, }) {
|
|
48
|
-
// Useful to load an eventually localize authors map
|
|
49
|
-
const contentPath = await (0, utils_1.findFolderContainingFile)((0, blogUtils_1.getContentPathList)(contentPaths), authorsMapPath);
|
|
50
|
-
if (contentPath) {
|
|
51
|
-
return path_1.default.join(contentPath, authorsMapPath);
|
|
52
|
-
}
|
|
53
|
-
return undefined;
|
|
54
|
-
}
|
|
55
|
-
exports.getAuthorsMapFilePath = getAuthorsMapFilePath;
|
|
24
|
+
exports.validateAuthorsMap = validateAuthorsMap;
|
|
56
25
|
async function getAuthorsMap(params) {
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
return await readAuthorsMapFile(filePath);
|
|
63
|
-
}
|
|
64
|
-
catch (e) {
|
|
65
|
-
// TODO replace later by error cause, see https://v8.dev/features/error-cause
|
|
66
|
-
logger_1.default.error `Couldn't read blog authors map at path=${filePath}`;
|
|
67
|
-
throw e;
|
|
68
|
-
}
|
|
26
|
+
return (0, utils_1.getDataFileData)({
|
|
27
|
+
filePath: params.authorsMapPath,
|
|
28
|
+
contentPaths: params.contentPaths,
|
|
29
|
+
fileType: 'authors map',
|
|
30
|
+
}, validateAuthorsMap);
|
|
69
31
|
}
|
|
70
32
|
exports.getAuthorsMap = getAuthorsMap;
|
|
71
33
|
// Legacy v1/early-v2 frontmatter fields
|
package/lib/blogUtils.d.ts
CHANGED
|
@@ -21,5 +21,4 @@ export declare type LinkifyParams = {
|
|
|
21
21
|
fileString: string;
|
|
22
22
|
} & Pick<BlogMarkdownLoaderOptions, 'sourceToPermalink' | 'siteDir' | 'contentPaths' | 'onBrokenMarkdownLink'>;
|
|
23
23
|
export declare function linkify({ filePath, contentPaths, fileString, siteDir, sourceToPermalink, onBrokenMarkdownLink, }: LinkifyParams): string;
|
|
24
|
-
export declare function getContentPathList(contentPaths: BlogContentPaths): string[];
|
|
25
24
|
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.
|
|
9
|
+
exports.linkify = exports.generateBlogPosts = exports.parseBlogFileName = exports.getBlogTags = exports.getSourceToPermalink = exports.truncate = void 0;
|
|
10
10
|
const tslib_1 = require("tslib");
|
|
11
11
|
const fs_extra_1 = (0, tslib_1.__importDefault)(require("fs-extra"));
|
|
12
12
|
const path_1 = (0, tslib_1.__importDefault)(require("path"));
|
|
@@ -80,7 +80,7 @@ async function processBlogSourceFile(blogSourceRelative, contentPaths, context,
|
|
|
80
80
|
const { siteConfig: { baseUrl }, siteDir, i18n, } = context;
|
|
81
81
|
const { routeBasePath, tagsBasePath: tagsRouteBasePath, truncateMarker, showReadingTime, editUrl, } = options;
|
|
82
82
|
// Lookup in localized folder in priority
|
|
83
|
-
const blogDirPath = await (0, utils_1.getFolderContainingFile)(getContentPathList(contentPaths), blogSourceRelative);
|
|
83
|
+
const blogDirPath = await (0, utils_1.getFolderContainingFile)((0, utils_1.getContentPathList)(contentPaths), blogSourceRelative);
|
|
84
84
|
const blogSourceAbsolute = path_1.default.join(blogDirPath, blogSourceRelative);
|
|
85
85
|
const { frontMatter, content, contentTitle, excerpt } = await parseBlogPostMarkdownFile(blogSourceAbsolute);
|
|
86
86
|
const aliasedSource = (0, utils_1.aliasedSitePath)(blogSourceAbsolute, siteDir);
|
|
@@ -203,8 +203,3 @@ function linkify({ filePath, contentPaths, fileString, siteDir, sourceToPermalin
|
|
|
203
203
|
return newContent;
|
|
204
204
|
}
|
|
205
205
|
exports.linkify = linkify;
|
|
206
|
-
// Order matters: we look in priority in localized folder
|
|
207
|
-
function getContentPathList(contentPaths) {
|
|
208
|
-
return [contentPaths.contentPathLocalized, contentPaths.contentPath];
|
|
209
|
-
}
|
|
210
|
-
exports.getContentPathList = getContentPathList;
|
package/lib/index.js
CHANGED
|
@@ -15,7 +15,6 @@ const translations_1 = require("./translations");
|
|
|
15
15
|
const pluginOptionSchema_1 = require("./pluginOptionSchema");
|
|
16
16
|
const blogUtils_1 = require("./blogUtils");
|
|
17
17
|
const feed_1 = require("./feed");
|
|
18
|
-
const authors_1 = require("./authors");
|
|
19
18
|
async function pluginContentBlog(context, options) {
|
|
20
19
|
var _a;
|
|
21
20
|
if (options.admonitions) {
|
|
@@ -38,15 +37,15 @@ async function pluginContentBlog(context, options) {
|
|
|
38
37
|
const pluginDataDirRoot = path_1.default.join(generatedFilesDir, 'docusaurus-plugin-content-blog');
|
|
39
38
|
const dataDir = path_1.default.join(pluginDataDirRoot, pluginId);
|
|
40
39
|
const aliasedSource = (source) => `~blog/${(0, utils_1.posixPath)(path_1.default.relative(pluginDataDirRoot, source))}`;
|
|
41
|
-
const authorsMapFilePath = await (0,
|
|
42
|
-
|
|
40
|
+
const authorsMapFilePath = await (0, utils_1.getDataFilePath)({
|
|
41
|
+
filePath: options.authorsMapPath,
|
|
43
42
|
contentPaths,
|
|
44
43
|
});
|
|
45
44
|
return {
|
|
46
45
|
name: 'docusaurus-plugin-content-blog',
|
|
47
46
|
getPathsToWatch() {
|
|
48
47
|
const { include } = options;
|
|
49
|
-
const contentMarkdownGlobs = (0,
|
|
48
|
+
const contentMarkdownGlobs = (0, utils_1.getContentPathList)(contentPaths).flatMap((contentPath) => include.map((pattern) => `${contentPath}/${pattern}`));
|
|
50
49
|
return [authorsMapFilePath, ...contentMarkdownGlobs].filter(Boolean);
|
|
51
50
|
},
|
|
52
51
|
async getTranslationFiles() {
|
|
@@ -275,7 +274,7 @@ async function pluginContentBlog(context, options) {
|
|
|
275
274
|
(0, utils_1.reportMessage)(`Blog markdown link couldn't be resolved: (${brokenMarkdownLink.link}) in ${brokenMarkdownLink.filePath}`, onBrokenMarkdownLinks);
|
|
276
275
|
},
|
|
277
276
|
};
|
|
278
|
-
const contentDirs = (0,
|
|
277
|
+
const contentDirs = (0, utils_1.getContentPathList)(contentPaths);
|
|
279
278
|
return {
|
|
280
279
|
resolve: {
|
|
281
280
|
alias: {
|
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-4350",
|
|
4
4
|
"description": "Blog plugin for Docusaurus.",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"types": "src/plugin-content-blog.d.ts",
|
|
@@ -18,16 +18,15 @@
|
|
|
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-4350",
|
|
22
|
+
"@docusaurus/logger": "0.0.0-4350",
|
|
23
|
+
"@docusaurus/mdx-loader": "0.0.0-4350",
|
|
24
|
+
"@docusaurus/utils": "0.0.0-4350",
|
|
25
|
+
"@docusaurus/utils-validation": "0.0.0-4350",
|
|
26
26
|
"escape-string-regexp": "^4.0.0",
|
|
27
27
|
"feed": "^4.2.2",
|
|
28
28
|
"fs-extra": "^10.0.0",
|
|
29
29
|
"globby": "^11.0.2",
|
|
30
|
-
"js-yaml": "^4.0.0",
|
|
31
30
|
"loader-utils": "^2.0.0",
|
|
32
31
|
"lodash": "^4.17.20",
|
|
33
32
|
"reading-time": "^1.5.0",
|
|
@@ -37,7 +36,7 @@
|
|
|
37
36
|
"webpack": "^5.61.0"
|
|
38
37
|
},
|
|
39
38
|
"devDependencies": {
|
|
40
|
-
"@docusaurus/types": "0.0.0-
|
|
39
|
+
"@docusaurus/types": "0.0.0-4350"
|
|
41
40
|
},
|
|
42
41
|
"peerDependencies": {
|
|
43
42
|
"react": "^16.8.4 || ^17.0.0",
|
|
@@ -46,5 +45,5 @@
|
|
|
46
45
|
"engines": {
|
|
47
46
|
"node": ">=14"
|
|
48
47
|
},
|
|
49
|
-
"gitHead": "
|
|
48
|
+
"gitHead": "395433a6f915dd0e6d73223228968fdc58761fd0"
|
|
50
49
|
}
|
package/src/authors.ts
CHANGED
|
@@ -5,19 +5,14 @@
|
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
|
-
import fs from 'fs-extra';
|
|
9
|
-
import logger from '@docusaurus/logger';
|
|
10
|
-
import path from 'path';
|
|
11
8
|
import {Author, BlogContentPaths} from './types';
|
|
12
|
-
import {
|
|
9
|
+
import {getDataFileData} from '@docusaurus/utils';
|
|
13
10
|
import {Joi, URISchema} from '@docusaurus/utils-validation';
|
|
14
11
|
import {
|
|
15
12
|
BlogPostFrontMatter,
|
|
16
13
|
BlogPostFrontMatterAuthor,
|
|
17
14
|
BlogPostFrontMatterAuthors,
|
|
18
15
|
} from './blogFrontMatter';
|
|
19
|
-
import {getContentPathList} from './blogUtils';
|
|
20
|
-
import Yaml from 'js-yaml';
|
|
21
16
|
|
|
22
17
|
export type AuthorsMap = Record<string, Author>;
|
|
23
18
|
|
|
@@ -34,63 +29,22 @@ const AuthorsMapSchema = Joi.object<AuthorsMap>().pattern(
|
|
|
34
29
|
.required(),
|
|
35
30
|
);
|
|
36
31
|
|
|
37
|
-
export function
|
|
32
|
+
export function validateAuthorsMap(content: unknown): AuthorsMap {
|
|
38
33
|
return Joi.attempt(content, AuthorsMapSchema);
|
|
39
34
|
}
|
|
40
35
|
|
|
41
|
-
export async function
|
|
42
|
-
filePath: string,
|
|
43
|
-
): Promise<AuthorsMap | undefined> {
|
|
44
|
-
if (await fs.pathExists(filePath)) {
|
|
45
|
-
const contentString = await fs.readFile(filePath, {encoding: 'utf8'});
|
|
46
|
-
try {
|
|
47
|
-
const unsafeContent = Yaml.load(contentString);
|
|
48
|
-
return validateAuthorsMapFile(unsafeContent);
|
|
49
|
-
} catch (e) {
|
|
50
|
-
// TODO replace later by error cause: see https://v8.dev/features/error-cause
|
|
51
|
-
logger.error('The author list file looks invalid!');
|
|
52
|
-
throw e;
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
return undefined;
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
type AuthorsMapParams = {
|
|
36
|
+
export async function getAuthorsMap(params: {
|
|
59
37
|
authorsMapPath: string;
|
|
60
38
|
contentPaths: BlogContentPaths;
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
getContentPathList(contentPaths),
|
|
70
|
-
authorsMapPath,
|
|
39
|
+
}): Promise<AuthorsMap | undefined> {
|
|
40
|
+
return getDataFileData(
|
|
41
|
+
{
|
|
42
|
+
filePath: params.authorsMapPath,
|
|
43
|
+
contentPaths: params.contentPaths,
|
|
44
|
+
fileType: 'authors map',
|
|
45
|
+
},
|
|
46
|
+
validateAuthorsMap,
|
|
71
47
|
);
|
|
72
|
-
|
|
73
|
-
if (contentPath) {
|
|
74
|
-
return path.join(contentPath, authorsMapPath);
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
return undefined;
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
export async function getAuthorsMap(
|
|
81
|
-
params: AuthorsMapParams,
|
|
82
|
-
): Promise<AuthorsMap | undefined> {
|
|
83
|
-
const filePath = await getAuthorsMapFilePath(params);
|
|
84
|
-
if (!filePath) {
|
|
85
|
-
return undefined;
|
|
86
|
-
}
|
|
87
|
-
try {
|
|
88
|
-
return await readAuthorsMapFile(filePath);
|
|
89
|
-
} catch (e) {
|
|
90
|
-
// TODO replace later by error cause, see https://v8.dev/features/error-cause
|
|
91
|
-
logger.error`Couldn't read blog authors map at path=${filePath}`;
|
|
92
|
-
throw e;
|
|
93
|
-
}
|
|
94
48
|
}
|
|
95
49
|
|
|
96
50
|
type AuthorsParam = {
|
package/src/blogUtils.ts
CHANGED
|
@@ -28,6 +28,7 @@ import {
|
|
|
28
28
|
Globby,
|
|
29
29
|
normalizeFrontMatterTags,
|
|
30
30
|
groupTaggedItems,
|
|
31
|
+
getContentPathList,
|
|
31
32
|
} from '@docusaurus/utils';
|
|
32
33
|
import {LoadContext} from '@docusaurus/types';
|
|
33
34
|
import {validateBlogPostFrontMatter} from './blogFrontMatter';
|
|
@@ -318,8 +319,3 @@ export function linkify({
|
|
|
318
319
|
|
|
319
320
|
return newContent;
|
|
320
321
|
}
|
|
321
|
-
|
|
322
|
-
// Order matters: we look in priority in localized folder
|
|
323
|
-
export function getContentPathList(contentPaths: BlogContentPaths): string[] {
|
|
324
|
-
return [contentPaths.contentPathLocalized, contentPaths.contentPath];
|
|
325
|
-
}
|
package/src/index.ts
CHANGED
|
@@ -16,6 +16,8 @@ import {
|
|
|
16
16
|
posixPath,
|
|
17
17
|
addTrailingPathSeparator,
|
|
18
18
|
createAbsoluteFilePathMatcher,
|
|
19
|
+
getContentPathList,
|
|
20
|
+
getDataFilePath,
|
|
19
21
|
DEFAULT_PLUGIN_ID,
|
|
20
22
|
} from '@docusaurus/utils';
|
|
21
23
|
import {translateContent, getTranslationFiles} from './translations';
|
|
@@ -45,13 +47,11 @@ import {
|
|
|
45
47
|
import {Configuration} from 'webpack';
|
|
46
48
|
import {
|
|
47
49
|
generateBlogPosts,
|
|
48
|
-
getContentPathList,
|
|
49
50
|
getSourceToPermalink,
|
|
50
51
|
getBlogTags,
|
|
51
52
|
} from './blogUtils';
|
|
52
53
|
import {BlogPostFrontMatter} from './blogFrontMatter';
|
|
53
54
|
import {createBlogFeedFiles} from './feed';
|
|
54
|
-
import {getAuthorsMapFilePath} from './authors';
|
|
55
55
|
|
|
56
56
|
export default async function pluginContentBlog(
|
|
57
57
|
context: LoadContext,
|
|
@@ -90,8 +90,8 @@ export default async function pluginContentBlog(
|
|
|
90
90
|
const aliasedSource = (source: string) =>
|
|
91
91
|
`~blog/${posixPath(path.relative(pluginDataDirRoot, source))}`;
|
|
92
92
|
|
|
93
|
-
const authorsMapFilePath = await
|
|
94
|
-
|
|
93
|
+
const authorsMapFilePath = await getDataFilePath({
|
|
94
|
+
filePath: options.authorsMapPath,
|
|
95
95
|
contentPaths,
|
|
96
96
|
});
|
|
97
97
|
|