@docusaurus/plugin-content-blog 0.0.0-4347 → 0.0.0-4355
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 +5 -8
- package/lib/authors.js +8 -46
- package/lib/blogUtils.d.ts +2 -3
- package/lib/blogUtils.js +8 -8
- package/lib/feed.d.ts +2 -2
- package/lib/index.d.ts +2 -2
- package/lib/index.js +4 -5
- package/lib/markdownLoader.d.ts +1 -1
- package/lib/pluginOptionSchema.d.ts +1 -1
- package/lib/types.d.ts +2 -2
- package/package.json +8 -9
- package/src/authors.ts +13 -59
- package/src/blogUtils.ts +10 -9
- package/src/feed.ts +3 -3
- package/src/index.ts +8 -8
- package/src/markdownLoader.ts +1 -1
- package/src/pluginOptionSchema.ts +1 -1
- package/src/types.ts +2 -2
package/lib/authors.d.ts
CHANGED
|
@@ -4,17 +4,14 @@
|
|
|
4
4
|
* This source code is licensed under the MIT license found in the
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*/
|
|
7
|
-
import { Author, BlogContentPaths } from './types';
|
|
8
|
-
import { BlogPostFrontMatter } from './blogFrontMatter';
|
|
7
|
+
import type { Author, BlogContentPaths } from './types';
|
|
8
|
+
import type { 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
|
@@ -4,8 +4,8 @@
|
|
|
4
4
|
* This source code is licensed under the MIT license found in the
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*/
|
|
7
|
-
import { PluginOptions, BlogPost, BlogContentPaths, BlogMarkdownLoaderOptions, BlogTags } from './types';
|
|
8
|
-
import { LoadContext } from '@docusaurus/types';
|
|
7
|
+
import type { PluginOptions, BlogPost, BlogContentPaths, BlogMarkdownLoaderOptions, BlogTags } from './types';
|
|
8
|
+
import type { LoadContext } from '@docusaurus/types';
|
|
9
9
|
export declare function truncate(fileString: string, truncateMarker: RegExp): string;
|
|
10
10
|
export declare function getSourceToPermalink(blogPosts: BlogPost[]): Record<string, string>;
|
|
11
11
|
export declare function getBlogTags(blogPosts: BlogPost[]): BlogTags;
|
|
@@ -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);
|
|
@@ -94,7 +94,12 @@ async function processBlogSourceFile(blogSourceRelative, contentPaths, context,
|
|
|
94
94
|
async function getDate() {
|
|
95
95
|
// Prefer user-defined date.
|
|
96
96
|
if (frontMatter.date) {
|
|
97
|
-
|
|
97
|
+
if (typeof frontMatter.date === 'string') {
|
|
98
|
+
// Always treat dates as UTC by adding the `Z`
|
|
99
|
+
return new Date(`${frontMatter.date}Z`);
|
|
100
|
+
}
|
|
101
|
+
// YAML only converts YYYY-MM-DD to dates and leaves others as strings.
|
|
102
|
+
return frontMatter.date;
|
|
98
103
|
}
|
|
99
104
|
else if (parsedBlogFileName.date) {
|
|
100
105
|
return parsedBlogFileName.date;
|
|
@@ -203,8 +208,3 @@ function linkify({ filePath, contentPaths, fileString, siteDir, sourceToPermalin
|
|
|
203
208
|
return newContent;
|
|
204
209
|
}
|
|
205
210
|
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/feed.d.ts
CHANGED
|
@@ -5,8 +5,8 @@
|
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*/
|
|
7
7
|
import { Feed } from 'feed';
|
|
8
|
-
import { PluginOptions, BlogPost } from './types';
|
|
9
|
-
import { DocusaurusConfig } from '@docusaurus/types';
|
|
8
|
+
import type { PluginOptions, BlogPost } from './types';
|
|
9
|
+
import type { DocusaurusConfig } from '@docusaurus/types';
|
|
10
10
|
export declare function generateBlogFeed({ blogPosts, options, siteConfig, }: {
|
|
11
11
|
blogPosts: BlogPost[];
|
|
12
12
|
options: PluginOptions;
|
package/lib/index.d.ts
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* This source code is licensed under the MIT license found in the
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*/
|
|
7
|
-
import { PluginOptions, BlogContent } from './types';
|
|
8
|
-
import { LoadContext, Plugin, OptionValidationContext, ValidationResult } from '@docusaurus/types';
|
|
7
|
+
import type { PluginOptions, BlogContent } from './types';
|
|
8
|
+
import type { LoadContext, Plugin, OptionValidationContext, ValidationResult } from '@docusaurus/types';
|
|
9
9
|
export default function pluginContentBlog(context: LoadContext, options: PluginOptions): Promise<Plugin<BlogContent>>;
|
|
10
10
|
export declare function validateOptions({ validate, options, }: OptionValidationContext<PluginOptions>): ValidationResult<PluginOptions>;
|
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/lib/markdownLoader.d.ts
CHANGED
|
@@ -4,6 +4,6 @@
|
|
|
4
4
|
* This source code is licensed under the MIT license found in the
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*/
|
|
7
|
-
import { BlogMarkdownLoaderOptions } from './types';
|
|
7
|
+
import type { BlogMarkdownLoaderOptions } from './types';
|
|
8
8
|
import type { LoaderContext } from 'webpack';
|
|
9
9
|
export default function markdownLoader(this: LoaderContext<BlogMarkdownLoaderOptions>, source: string): void;
|
|
@@ -5,6 +5,6 @@
|
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*/
|
|
7
7
|
import { Joi } from '@docusaurus/utils-validation';
|
|
8
|
-
import { PluginOptions } from './types';
|
|
8
|
+
import type { PluginOptions } from './types';
|
|
9
9
|
export declare const DEFAULT_OPTIONS: PluginOptions;
|
|
10
10
|
export declare const PluginOptionSchema: Joi.ObjectSchema<PluginOptions>;
|
package/lib/types.d.ts
CHANGED
|
@@ -7,8 +7,8 @@
|
|
|
7
7
|
import type { RemarkAndRehypePluginOptions } from '@docusaurus/mdx-loader';
|
|
8
8
|
import type { Tag } from '@docusaurus/utils';
|
|
9
9
|
import type { BrokenMarkdownLink, ContentPaths } from '@docusaurus/utils/lib/markdownLinks';
|
|
10
|
-
import { Overwrite } from 'utility-types';
|
|
11
|
-
import { BlogPostFrontMatter } from './blogFrontMatter';
|
|
10
|
+
import type { Overwrite } from 'utility-types';
|
|
11
|
+
import type { BlogPostFrontMatter } from './blogFrontMatter';
|
|
12
12
|
export declare type BlogContentPaths = ContentPaths;
|
|
13
13
|
export interface BlogContent {
|
|
14
14
|
blogSidebarTitle: string;
|
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-4355",
|
|
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-4355",
|
|
22
|
+
"@docusaurus/logger": "0.0.0-4355",
|
|
23
|
+
"@docusaurus/mdx-loader": "0.0.0-4355",
|
|
24
|
+
"@docusaurus/utils": "0.0.0-4355",
|
|
25
|
+
"@docusaurus/utils-validation": "0.0.0-4355",
|
|
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-4355"
|
|
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": "4ad639a600a7aa5415733d798ed53a5a99ac7da0"
|
|
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
|
|
9
|
-
import
|
|
10
|
-
import path from 'path';
|
|
11
|
-
import {Author, BlogContentPaths} from './types';
|
|
12
|
-
import {findFolderContainingFile} from '@docusaurus/utils';
|
|
8
|
+
import type {Author, BlogContentPaths} from './types';
|
|
9
|
+
import {getDataFileData} from '@docusaurus/utils';
|
|
13
10
|
import {Joi, URISchema} from '@docusaurus/utils-validation';
|
|
14
|
-
import {
|
|
11
|
+
import type {
|
|
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
|
@@ -9,7 +9,7 @@ import fs from 'fs-extra';
|
|
|
9
9
|
import path from 'path';
|
|
10
10
|
import readingTime from 'reading-time';
|
|
11
11
|
import {keyBy, mapValues} from 'lodash';
|
|
12
|
-
import {
|
|
12
|
+
import type {
|
|
13
13
|
PluginOptions,
|
|
14
14
|
BlogPost,
|
|
15
15
|
BlogContentPaths,
|
|
@@ -28,10 +28,11 @@ import {
|
|
|
28
28
|
Globby,
|
|
29
29
|
normalizeFrontMatterTags,
|
|
30
30
|
groupTaggedItems,
|
|
31
|
+
getContentPathList,
|
|
31
32
|
} from '@docusaurus/utils';
|
|
32
|
-
import {LoadContext} from '@docusaurus/types';
|
|
33
|
+
import type {LoadContext} from '@docusaurus/types';
|
|
33
34
|
import {validateBlogPostFrontMatter} from './blogFrontMatter';
|
|
34
|
-
import {AuthorsMap, getAuthorsMap, getBlogPostAuthors} from './authors';
|
|
35
|
+
import {type AuthorsMap, getAuthorsMap, getBlogPostAuthors} from './authors';
|
|
35
36
|
import logger from '@docusaurus/logger';
|
|
36
37
|
|
|
37
38
|
export function truncate(fileString: string, truncateMarker: RegExp): string {
|
|
@@ -159,7 +160,12 @@ async function processBlogSourceFile(
|
|
|
159
160
|
async function getDate(): Promise<Date> {
|
|
160
161
|
// Prefer user-defined date.
|
|
161
162
|
if (frontMatter.date) {
|
|
162
|
-
|
|
163
|
+
if (typeof frontMatter.date === 'string') {
|
|
164
|
+
// Always treat dates as UTC by adding the `Z`
|
|
165
|
+
return new Date(`${frontMatter.date}Z`);
|
|
166
|
+
}
|
|
167
|
+
// YAML only converts YYYY-MM-DD to dates and leaves others as strings.
|
|
168
|
+
return frontMatter.date;
|
|
163
169
|
} else if (parsedBlogFileName.date) {
|
|
164
170
|
return parsedBlogFileName.date;
|
|
165
171
|
}
|
|
@@ -318,8 +324,3 @@ export function linkify({
|
|
|
318
324
|
|
|
319
325
|
return newContent;
|
|
320
326
|
}
|
|
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/feed.ts
CHANGED
|
@@ -5,10 +5,10 @@
|
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
|
-
import {Feed, Author as FeedAuthor, Item as FeedItem} from 'feed';
|
|
9
|
-
import {PluginOptions, Author, BlogPost, FeedType} from './types';
|
|
8
|
+
import {Feed, type Author as FeedAuthor, type Item as FeedItem} from 'feed';
|
|
9
|
+
import type {PluginOptions, Author, BlogPost, FeedType} from './types';
|
|
10
10
|
import {normalizeUrl, mdxToHtml} from '@docusaurus/utils';
|
|
11
|
-
import {DocusaurusConfig} from '@docusaurus/types';
|
|
11
|
+
import type {DocusaurusConfig} from '@docusaurus/types';
|
|
12
12
|
import path from 'path';
|
|
13
13
|
import fs from 'fs-extra';
|
|
14
14
|
|
package/src/index.ts
CHANGED
|
@@ -16,11 +16,13 @@ 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';
|
|
22
24
|
|
|
23
|
-
import {
|
|
25
|
+
import type {
|
|
24
26
|
PluginOptions,
|
|
25
27
|
BlogTags,
|
|
26
28
|
BlogContent,
|
|
@@ -33,7 +35,7 @@ import {
|
|
|
33
35
|
Assets,
|
|
34
36
|
} from './types';
|
|
35
37
|
import {PluginOptionSchema} from './pluginOptionSchema';
|
|
36
|
-
import {
|
|
38
|
+
import type {
|
|
37
39
|
LoadContext,
|
|
38
40
|
ConfigureWebpackUtils,
|
|
39
41
|
Props,
|
|
@@ -42,16 +44,14 @@ import {
|
|
|
42
44
|
OptionValidationContext,
|
|
43
45
|
ValidationResult,
|
|
44
46
|
} from '@docusaurus/types';
|
|
45
|
-
import {Configuration} from 'webpack';
|
|
47
|
+
import type {Configuration} from 'webpack';
|
|
46
48
|
import {
|
|
47
49
|
generateBlogPosts,
|
|
48
|
-
getContentPathList,
|
|
49
50
|
getSourceToPermalink,
|
|
50
51
|
getBlogTags,
|
|
51
52
|
} from './blogUtils';
|
|
52
|
-
import {BlogPostFrontMatter} from './blogFrontMatter';
|
|
53
|
+
import type {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
|
|
package/src/markdownLoader.ts
CHANGED
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
|
|
8
8
|
import {truncate, linkify} from './blogUtils';
|
|
9
9
|
import {parseQuery} from 'loader-utils';
|
|
10
|
-
import {BlogMarkdownLoaderOptions} from './types';
|
|
10
|
+
import type {BlogMarkdownLoaderOptions} from './types';
|
|
11
11
|
import type {LoaderContext} from 'webpack';
|
|
12
12
|
|
|
13
13
|
export default function markdownLoader(
|
|
@@ -13,7 +13,7 @@ import {
|
|
|
13
13
|
URISchema,
|
|
14
14
|
} from '@docusaurus/utils-validation';
|
|
15
15
|
import {GlobExcludeDefault} from '@docusaurus/utils';
|
|
16
|
-
import {PluginOptions} from './types';
|
|
16
|
+
import type {PluginOptions} from './types';
|
|
17
17
|
|
|
18
18
|
export const DEFAULT_OPTIONS: PluginOptions = {
|
|
19
19
|
feedOptions: {type: ['rss', 'atom'], copyright: ''},
|
package/src/types.ts
CHANGED
|
@@ -11,8 +11,8 @@ import type {
|
|
|
11
11
|
BrokenMarkdownLink,
|
|
12
12
|
ContentPaths,
|
|
13
13
|
} from '@docusaurus/utils/lib/markdownLinks';
|
|
14
|
-
import {Overwrite} from 'utility-types';
|
|
15
|
-
import {BlogPostFrontMatter} from './blogFrontMatter';
|
|
14
|
+
import type {Overwrite} from 'utility-types';
|
|
15
|
+
import type {BlogPostFrontMatter} from './blogFrontMatter';
|
|
16
16
|
|
|
17
17
|
export type BlogContentPaths = ContentPaths;
|
|
18
18
|
|