@docusaurus/plugin-content-blog 0.0.0-6021 → 0.0.0-6023
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 +14 -0
- package/lib/index.js +4 -0
- package/lib/options.js +4 -0
- package/package.json +10 -10
- package/src/blogUtils.ts +23 -0
- package/src/index.ts +5 -0
- package/src/options.ts +4 -0
- package/src/plugin-content-blog.d.ts +2 -0
package/lib/blogUtils.d.ts
CHANGED
|
@@ -8,6 +8,10 @@ import type { LoadContext } from '@docusaurus/types';
|
|
|
8
8
|
import type { AuthorsMap, PluginOptions, BlogPost, BlogTags, BlogPaginated } from '@docusaurus/plugin-content-blog';
|
|
9
9
|
import type { BlogContentPaths } from './types';
|
|
10
10
|
export declare function truncate(fileString: string, truncateMarker: RegExp): string;
|
|
11
|
+
export declare function reportUntruncatedBlogPosts({ blogPosts, onUntruncatedBlogPosts, }: {
|
|
12
|
+
blogPosts: BlogPost[];
|
|
13
|
+
onUntruncatedBlogPosts: PluginOptions['onUntruncatedBlogPosts'];
|
|
14
|
+
}): void;
|
|
11
15
|
export declare function paginateBlogPosts({ blogPosts, basePageUrl, blogTitle, blogDescription, postsPerPageOption, pageBasePath, }: {
|
|
12
16
|
blogPosts: BlogPost[];
|
|
13
17
|
basePageUrl: string;
|
package/lib/blogUtils.js
CHANGED
|
@@ -7,6 +7,7 @@
|
|
|
7
7
|
*/
|
|
8
8
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
9
|
exports.truncate = truncate;
|
|
10
|
+
exports.reportUntruncatedBlogPosts = reportUntruncatedBlogPosts;
|
|
10
11
|
exports.paginateBlogPosts = paginateBlogPosts;
|
|
11
12
|
exports.shouldBeListed = shouldBeListed;
|
|
12
13
|
exports.getBlogTags = getBlogTags;
|
|
@@ -27,6 +28,19 @@ const authorsProblems_1 = require("./authorsProblems");
|
|
|
27
28
|
function truncate(fileString, truncateMarker) {
|
|
28
29
|
return fileString.split(truncateMarker, 1).shift();
|
|
29
30
|
}
|
|
31
|
+
function reportUntruncatedBlogPosts({ blogPosts, onUntruncatedBlogPosts, }) {
|
|
32
|
+
const untruncatedBlogPosts = blogPosts.filter((p) => !p.metadata.hasTruncateMarker);
|
|
33
|
+
if (onUntruncatedBlogPosts !== 'ignore' && untruncatedBlogPosts.length > 0) {
|
|
34
|
+
const message = logger_1.default.interpolate `Docusaurus found blog posts without truncation markers:
|
|
35
|
+
- ${untruncatedBlogPosts
|
|
36
|
+
.map((p) => logger_1.default.path((0, utils_1.aliasedSitePathToRelativePath)(p.metadata.source)))
|
|
37
|
+
.join('\n- ')}
|
|
38
|
+
|
|
39
|
+
We recommend using truncation markers (code=${`<!-- truncate -->`} or code=${`{/* truncate */}`}) in blog posts to create shorter previews on blog paginated lists.
|
|
40
|
+
Tip: turn this security off with the code=${`onUntruncatedBlogPosts: 'ignore'`} blog plugin option.`;
|
|
41
|
+
logger_1.default.report(onUntruncatedBlogPosts)(message);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
30
44
|
function paginateBlogPosts({ blogPosts, basePageUrl, blogTitle, blogDescription, postsPerPageOption, pageBasePath, }) {
|
|
31
45
|
const totalCount = blogPosts.length;
|
|
32
46
|
const postsPerPage = postsPerPageOption === 'ALL' ? totalCount : postsPerPageOption;
|
package/lib/index.js
CHANGED
|
@@ -107,6 +107,10 @@ async function pluginContentBlog(context, options) {
|
|
|
107
107
|
blogPosts,
|
|
108
108
|
processBlogPosts: options.processBlogPosts,
|
|
109
109
|
});
|
|
110
|
+
(0, blogUtils_1.reportUntruncatedBlogPosts)({
|
|
111
|
+
blogPosts,
|
|
112
|
+
onUntruncatedBlogPosts: options.onUntruncatedBlogPosts,
|
|
113
|
+
});
|
|
110
114
|
const listedBlogPosts = blogPosts.filter(blogUtils_1.shouldBeListed);
|
|
111
115
|
if (!blogPosts.length) {
|
|
112
116
|
return {
|
package/lib/options.js
CHANGED
|
@@ -60,6 +60,7 @@ exports.DEFAULT_OPTIONS = {
|
|
|
60
60
|
tags: undefined,
|
|
61
61
|
authorsBasePath: 'authors',
|
|
62
62
|
onInlineAuthors: 'warn',
|
|
63
|
+
onUntruncatedBlogPosts: 'warn',
|
|
63
64
|
};
|
|
64
65
|
exports.XSLTBuiltInPaths = {
|
|
65
66
|
rss: path_1.default.resolve(__dirname, '..', 'assets', 'rss.xsl'),
|
|
@@ -189,6 +190,9 @@ const PluginOptionSchema = utils_validation_1.Joi.object({
|
|
|
189
190
|
onInlineAuthors: utils_validation_1.Joi.string()
|
|
190
191
|
.equal('ignore', 'log', 'warn', 'throw')
|
|
191
192
|
.default(exports.DEFAULT_OPTIONS.onInlineAuthors),
|
|
193
|
+
onUntruncatedBlogPosts: utils_validation_1.Joi.string()
|
|
194
|
+
.equal('ignore', 'log', 'warn', 'throw')
|
|
195
|
+
.default(exports.DEFAULT_OPTIONS.onUntruncatedBlogPosts),
|
|
192
196
|
}).default(exports.DEFAULT_OPTIONS);
|
|
193
197
|
function validateOptions({ validate, options, }) {
|
|
194
198
|
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-6023",
|
|
4
4
|
"description": "Blog plugin for Docusaurus.",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"types": "src/plugin-content-blog.d.ts",
|
|
@@ -31,14 +31,14 @@
|
|
|
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/theme-common": "0.0.0-
|
|
38
|
-
"@docusaurus/types": "0.0.0-
|
|
39
|
-
"@docusaurus/utils": "0.0.0-
|
|
40
|
-
"@docusaurus/utils-common": "0.0.0-
|
|
41
|
-
"@docusaurus/utils-validation": "0.0.0-
|
|
34
|
+
"@docusaurus/core": "0.0.0-6023",
|
|
35
|
+
"@docusaurus/logger": "0.0.0-6023",
|
|
36
|
+
"@docusaurus/mdx-loader": "0.0.0-6023",
|
|
37
|
+
"@docusaurus/theme-common": "0.0.0-6023",
|
|
38
|
+
"@docusaurus/types": "0.0.0-6023",
|
|
39
|
+
"@docusaurus/utils": "0.0.0-6023",
|
|
40
|
+
"@docusaurus/utils-common": "0.0.0-6023",
|
|
41
|
+
"@docusaurus/utils-validation": "0.0.0-6023",
|
|
42
42
|
"cheerio": "^1.0.0-rc.12",
|
|
43
43
|
"feed": "^4.2.2",
|
|
44
44
|
"fs-extra": "^11.1.1",
|
|
@@ -62,5 +62,5 @@
|
|
|
62
62
|
"@total-typescript/shoehorn": "^0.1.2",
|
|
63
63
|
"tree-node-cli": "^1.6.0"
|
|
64
64
|
},
|
|
65
|
-
"gitHead": "
|
|
65
|
+
"gitHead": "b639416f1286febfd49285f17a964371d2735afb"
|
|
66
66
|
}
|
package/src/blogUtils.ts
CHANGED
|
@@ -26,6 +26,7 @@ import {
|
|
|
26
26
|
isDraft,
|
|
27
27
|
readLastUpdateData,
|
|
28
28
|
normalizeTags,
|
|
29
|
+
aliasedSitePathToRelativePath,
|
|
29
30
|
} from '@docusaurus/utils';
|
|
30
31
|
import {getTagsFile} from '@docusaurus/utils-validation';
|
|
31
32
|
import {validateBlogPostFrontMatter} from './frontMatter';
|
|
@@ -47,6 +48,28 @@ export function truncate(fileString: string, truncateMarker: RegExp): string {
|
|
|
47
48
|
return fileString.split(truncateMarker, 1).shift()!;
|
|
48
49
|
}
|
|
49
50
|
|
|
51
|
+
export function reportUntruncatedBlogPosts({
|
|
52
|
+
blogPosts,
|
|
53
|
+
onUntruncatedBlogPosts,
|
|
54
|
+
}: {
|
|
55
|
+
blogPosts: BlogPost[];
|
|
56
|
+
onUntruncatedBlogPosts: PluginOptions['onUntruncatedBlogPosts'];
|
|
57
|
+
}): void {
|
|
58
|
+
const untruncatedBlogPosts = blogPosts.filter(
|
|
59
|
+
(p) => !p.metadata.hasTruncateMarker,
|
|
60
|
+
);
|
|
61
|
+
if (onUntruncatedBlogPosts !== 'ignore' && untruncatedBlogPosts.length > 0) {
|
|
62
|
+
const message = logger.interpolate`Docusaurus found blog posts without truncation markers:
|
|
63
|
+
- ${untruncatedBlogPosts
|
|
64
|
+
.map((p) => logger.path(aliasedSitePathToRelativePath(p.metadata.source)))
|
|
65
|
+
.join('\n- ')}
|
|
66
|
+
|
|
67
|
+
We recommend using truncation markers (code=${`<!-- truncate -->`} or code=${`{/* truncate */}`}) in blog posts to create shorter previews on blog paginated lists.
|
|
68
|
+
Tip: turn this security off with the code=${`onUntruncatedBlogPosts: 'ignore'`} blog plugin option.`;
|
|
69
|
+
logger.report(onUntruncatedBlogPosts)(message);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
|
|
50
73
|
export function paginateBlogPosts({
|
|
51
74
|
blogPosts,
|
|
52
75
|
basePageUrl,
|
package/src/index.ts
CHANGED
|
@@ -28,6 +28,7 @@ import {
|
|
|
28
28
|
shouldBeListed,
|
|
29
29
|
applyProcessBlogPosts,
|
|
30
30
|
generateBlogPosts,
|
|
31
|
+
reportUntruncatedBlogPosts,
|
|
31
32
|
} from './blogUtils';
|
|
32
33
|
import footnoteIDFixer from './remark/footnoteIDFixer';
|
|
33
34
|
import {translateContent, getTranslationFiles} from './translations';
|
|
@@ -189,6 +190,10 @@ export default async function pluginContentBlog(
|
|
|
189
190
|
blogPosts,
|
|
190
191
|
processBlogPosts: options.processBlogPosts,
|
|
191
192
|
});
|
|
193
|
+
reportUntruncatedBlogPosts({
|
|
194
|
+
blogPosts,
|
|
195
|
+
onUntruncatedBlogPosts: options.onUntruncatedBlogPosts,
|
|
196
|
+
});
|
|
192
197
|
const listedBlogPosts = blogPosts.filter(shouldBeListed);
|
|
193
198
|
|
|
194
199
|
if (!blogPosts.length) {
|
package/src/options.ts
CHANGED
|
@@ -72,6 +72,7 @@ export const DEFAULT_OPTIONS: PluginOptions = {
|
|
|
72
72
|
tags: undefined,
|
|
73
73
|
authorsBasePath: 'authors',
|
|
74
74
|
onInlineAuthors: 'warn',
|
|
75
|
+
onUntruncatedBlogPosts: 'warn',
|
|
75
76
|
};
|
|
76
77
|
|
|
77
78
|
export const XSLTBuiltInPaths = {
|
|
@@ -240,6 +241,9 @@ const PluginOptionSchema = Joi.object<PluginOptions>({
|
|
|
240
241
|
onInlineAuthors: Joi.string()
|
|
241
242
|
.equal('ignore', 'log', 'warn', 'throw')
|
|
242
243
|
.default(DEFAULT_OPTIONS.onInlineAuthors),
|
|
244
|
+
onUntruncatedBlogPosts: Joi.string()
|
|
245
|
+
.equal('ignore', 'log', 'warn', 'throw')
|
|
246
|
+
.default(DEFAULT_OPTIONS.onUntruncatedBlogPosts),
|
|
243
247
|
}).default(DEFAULT_OPTIONS);
|
|
244
248
|
|
|
245
249
|
export function validateOptions({
|
|
@@ -521,6 +521,8 @@ declare module '@docusaurus/plugin-content-blog' {
|
|
|
521
521
|
authorsBasePath: string;
|
|
522
522
|
/** The behavior of Docusaurus when it finds inline authors. */
|
|
523
523
|
onInlineAuthors: 'ignore' | 'log' | 'warn' | 'throw';
|
|
524
|
+
/** The behavior of Docusaurus when it finds untruncated blog posts. */
|
|
525
|
+
onUntruncatedBlogPosts: 'ignore' | 'log' | 'warn' | 'throw';
|
|
524
526
|
};
|
|
525
527
|
|
|
526
528
|
export type UserFeedXSLTOptions =
|