@docusaurus/plugin-content-blog 0.0.0-4485 → 0.0.0-4489
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/feed.js +13 -17
- package/lib/index.js +2 -4
- package/package.json +10 -8
- package/src/feed.ts +25 -17
- package/src/index.ts +2 -6
package/lib/feed.js
CHANGED
|
@@ -10,22 +10,11 @@ exports.createBlogFeedFiles = void 0;
|
|
|
10
10
|
const tslib_1 = require("tslib");
|
|
11
11
|
const feed_1 = require("feed");
|
|
12
12
|
const utils_1 = require("@docusaurus/utils");
|
|
13
|
+
const cheerio_1 = (0, tslib_1.__importDefault)(require("cheerio"));
|
|
13
14
|
const path_1 = (0, tslib_1.__importDefault)(require("path"));
|
|
14
15
|
const fs_extra_1 = (0, tslib_1.__importDefault)(require("fs-extra"));
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
// See https://github.com/facebook/docusaurus/issues/5664
|
|
18
|
-
function mdxToFeedContent(mdxContent) {
|
|
19
|
-
try {
|
|
20
|
-
return (0, utils_1.mdxToHtml)(mdxContent);
|
|
21
|
-
}
|
|
22
|
-
catch (e) {
|
|
23
|
-
// TODO will we need a plugin option to configure how to handle such an error
|
|
24
|
-
// Swallow the error on purpose for now, until we understand better the problem space
|
|
25
|
-
return undefined;
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
async function generateBlogFeed({ blogPosts, options, siteConfig, }) {
|
|
16
|
+
const utils_common_1 = require("@docusaurus/utils-common");
|
|
17
|
+
async function generateBlogFeed({ blogPosts, options, siteConfig, outDir, }) {
|
|
29
18
|
if (!blogPosts.length) {
|
|
30
19
|
return null;
|
|
31
20
|
}
|
|
@@ -48,8 +37,10 @@ async function generateBlogFeed({ blogPosts, options, siteConfig, }) {
|
|
|
48
37
|
// RSS feed requires email to render authors
|
|
49
38
|
return { name: author.name, link: author.url };
|
|
50
39
|
}
|
|
51
|
-
|
|
40
|
+
await (0, utils_1.mapAsyncSequential)(blogPosts, async (post) => {
|
|
52
41
|
const { id, metadata: { title: metadataTitle, permalink, date, description, authors, tags, }, } = post;
|
|
42
|
+
const content = await (0, utils_1.readOutputHTMLFile)(permalink.replace(siteConfig.baseUrl, ''), outDir, siteConfig.trailingSlash);
|
|
43
|
+
const $ = cheerio_1.default.load(content);
|
|
53
44
|
const feedItem = {
|
|
54
45
|
title: metadataTitle,
|
|
55
46
|
id,
|
|
@@ -58,7 +49,7 @@ async function generateBlogFeed({ blogPosts, options, siteConfig, }) {
|
|
|
58
49
|
description,
|
|
59
50
|
// Atom feed demands the "term", while other feeds use "name"
|
|
60
51
|
category: tags.map((tag) => ({ name: tag.label, term: tag.label })),
|
|
61
|
-
content:
|
|
52
|
+
content: $(`#${utils_common_1.blogPostContainerID}`).html(),
|
|
62
53
|
};
|
|
63
54
|
// json1() method takes the first item of authors array
|
|
64
55
|
// it causes an error when authors array is empty
|
|
@@ -91,7 +82,12 @@ async function createBlogFeedFile({ feed, feedType, generatePath, }) {
|
|
|
91
82
|
}
|
|
92
83
|
}
|
|
93
84
|
async function createBlogFeedFiles({ blogPosts, options, siteConfig, outDir, }) {
|
|
94
|
-
const feed = await generateBlogFeed({
|
|
85
|
+
const feed = await generateBlogFeed({
|
|
86
|
+
blogPosts,
|
|
87
|
+
options,
|
|
88
|
+
siteConfig,
|
|
89
|
+
outDir,
|
|
90
|
+
});
|
|
95
91
|
const feedTypes = options.feedOptions.type;
|
|
96
92
|
if (!feed || !feedTypes) {
|
|
97
93
|
return;
|
package/lib/index.js
CHANGED
|
@@ -328,13 +328,11 @@ async function pluginContentBlog(context, options) {
|
|
|
328
328
|
},
|
|
329
329
|
};
|
|
330
330
|
},
|
|
331
|
-
async postBuild({ outDir }) {
|
|
331
|
+
async postBuild({ outDir, content }) {
|
|
332
332
|
if (!options.feedOptions.type) {
|
|
333
333
|
return;
|
|
334
334
|
}
|
|
335
|
-
|
|
336
|
-
// postBuild should receive loadedContent
|
|
337
|
-
const blogPosts = await (0, blogUtils_1.generateBlogPosts)(contentPaths, context, options);
|
|
335
|
+
const { blogPosts } = content;
|
|
338
336
|
if (!blogPosts.length) {
|
|
339
337
|
return;
|
|
340
338
|
}
|
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-4489",
|
|
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,13 @@
|
|
|
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-
|
|
21
|
+
"@docusaurus/core": "0.0.0-4489",
|
|
22
|
+
"@docusaurus/logger": "0.0.0-4489",
|
|
23
|
+
"@docusaurus/mdx-loader": "0.0.0-4489",
|
|
24
|
+
"@docusaurus/utils": "0.0.0-4489",
|
|
25
|
+
"@docusaurus/utils-common": "0.0.0-4489",
|
|
26
|
+
"@docusaurus/utils-validation": "0.0.0-4489",
|
|
27
|
+
"cheerio": "^1.0.0-rc.10",
|
|
26
28
|
"feed": "^4.2.2",
|
|
27
29
|
"fs-extra": "^10.0.0",
|
|
28
30
|
"lodash": "^4.17.20",
|
|
@@ -33,7 +35,7 @@
|
|
|
33
35
|
"webpack": "^5.61.0"
|
|
34
36
|
},
|
|
35
37
|
"devDependencies": {
|
|
36
|
-
"@docusaurus/types": "0.0.0-
|
|
38
|
+
"@docusaurus/types": "0.0.0-4489",
|
|
37
39
|
"escape-string-regexp": "^4.0.0"
|
|
38
40
|
},
|
|
39
41
|
"peerDependencies": {
|
|
@@ -43,5 +45,5 @@
|
|
|
43
45
|
"engines": {
|
|
44
46
|
"node": ">=14"
|
|
45
47
|
},
|
|
46
|
-
"gitHead": "
|
|
48
|
+
"gitHead": "f4020aaf26717ce5e5085a949cf3b7e088bc386f"
|
|
47
49
|
}
|
package/src/feed.ts
CHANGED
|
@@ -7,7 +7,13 @@
|
|
|
7
7
|
|
|
8
8
|
import {Feed, type Author as FeedAuthor, type Item as FeedItem} from 'feed';
|
|
9
9
|
import type {BlogPost} from './types';
|
|
10
|
-
import {
|
|
10
|
+
import {
|
|
11
|
+
normalizeUrl,
|
|
12
|
+
posixPath,
|
|
13
|
+
mapAsyncSequential,
|
|
14
|
+
readOutputHTMLFile,
|
|
15
|
+
} from '@docusaurus/utils';
|
|
16
|
+
import cheerio from 'cheerio';
|
|
11
17
|
import type {DocusaurusConfig} from '@docusaurus/types';
|
|
12
18
|
import path from 'path';
|
|
13
19
|
import fs from 'fs-extra';
|
|
@@ -16,28 +22,18 @@ import type {
|
|
|
16
22
|
PluginOptions,
|
|
17
23
|
Author,
|
|
18
24
|
} from '@docusaurus/plugin-content-blog';
|
|
19
|
-
|
|
20
|
-
// TODO this is temporary until we handle mdxToHtml better
|
|
21
|
-
// It's hard to convert reliably JSX/require calls to an html feed content
|
|
22
|
-
// See https://github.com/facebook/docusaurus/issues/5664
|
|
23
|
-
function mdxToFeedContent(mdxContent: string): string | undefined {
|
|
24
|
-
try {
|
|
25
|
-
return mdxToHtml(mdxContent);
|
|
26
|
-
} catch (e) {
|
|
27
|
-
// TODO will we need a plugin option to configure how to handle such an error
|
|
28
|
-
// Swallow the error on purpose for now, until we understand better the problem space
|
|
29
|
-
return undefined;
|
|
30
|
-
}
|
|
31
|
-
}
|
|
25
|
+
import {blogPostContainerID} from '@docusaurus/utils-common';
|
|
32
26
|
|
|
33
27
|
async function generateBlogFeed({
|
|
34
28
|
blogPosts,
|
|
35
29
|
options,
|
|
36
30
|
siteConfig,
|
|
31
|
+
outDir,
|
|
37
32
|
}: {
|
|
38
33
|
blogPosts: BlogPost[];
|
|
39
34
|
options: PluginOptions;
|
|
40
35
|
siteConfig: DocusaurusConfig;
|
|
36
|
+
outDir: string;
|
|
41
37
|
}): Promise<Feed | null> {
|
|
42
38
|
if (!blogPosts.length) {
|
|
43
39
|
return null;
|
|
@@ -66,7 +62,7 @@ async function generateBlogFeed({
|
|
|
66
62
|
return {name: author.name, link: author.url};
|
|
67
63
|
}
|
|
68
64
|
|
|
69
|
-
blogPosts
|
|
65
|
+
await mapAsyncSequential(blogPosts, async (post) => {
|
|
70
66
|
const {
|
|
71
67
|
id,
|
|
72
68
|
metadata: {
|
|
@@ -79,6 +75,13 @@ async function generateBlogFeed({
|
|
|
79
75
|
},
|
|
80
76
|
} = post;
|
|
81
77
|
|
|
78
|
+
const content = await readOutputHTMLFile(
|
|
79
|
+
permalink.replace(siteConfig.baseUrl, ''),
|
|
80
|
+
outDir,
|
|
81
|
+
siteConfig.trailingSlash,
|
|
82
|
+
);
|
|
83
|
+
const $ = cheerio.load(content);
|
|
84
|
+
|
|
82
85
|
const feedItem: FeedItem = {
|
|
83
86
|
title: metadataTitle,
|
|
84
87
|
id,
|
|
@@ -87,7 +90,7 @@ async function generateBlogFeed({
|
|
|
87
90
|
description,
|
|
88
91
|
// Atom feed demands the "term", while other feeds use "name"
|
|
89
92
|
category: tags.map((tag) => ({name: tag.label, term: tag.label})),
|
|
90
|
-
content:
|
|
93
|
+
content: $(`#${blogPostContainerID}`).html()!,
|
|
91
94
|
};
|
|
92
95
|
|
|
93
96
|
// json1() method takes the first item of authors array
|
|
@@ -145,7 +148,12 @@ export async function createBlogFeedFiles({
|
|
|
145
148
|
siteConfig: DocusaurusConfig;
|
|
146
149
|
outDir: string;
|
|
147
150
|
}): Promise<void> {
|
|
148
|
-
const feed = await generateBlogFeed({
|
|
151
|
+
const feed = await generateBlogFeed({
|
|
152
|
+
blogPosts,
|
|
153
|
+
options,
|
|
154
|
+
siteConfig,
|
|
155
|
+
outDir,
|
|
156
|
+
});
|
|
149
157
|
|
|
150
158
|
const feedTypes = options.feedOptions.type;
|
|
151
159
|
if (!feed || !feedTypes) {
|
package/src/index.ts
CHANGED
|
@@ -36,7 +36,6 @@ import {PluginOptionSchema} from './pluginOptionSchema';
|
|
|
36
36
|
import type {
|
|
37
37
|
LoadContext,
|
|
38
38
|
ConfigureWebpackUtils,
|
|
39
|
-
Props,
|
|
40
39
|
Plugin,
|
|
41
40
|
HtmlTags,
|
|
42
41
|
OptionValidationContext,
|
|
@@ -512,14 +511,11 @@ export default async function pluginContentBlog(
|
|
|
512
511
|
};
|
|
513
512
|
},
|
|
514
513
|
|
|
515
|
-
async postBuild({outDir}
|
|
514
|
+
async postBuild({outDir, content}) {
|
|
516
515
|
if (!options.feedOptions.type) {
|
|
517
516
|
return;
|
|
518
517
|
}
|
|
519
|
-
|
|
520
|
-
// TODO: we shouldn't need to re-read the posts here!
|
|
521
|
-
// postBuild should receive loadedContent
|
|
522
|
-
const blogPosts = await generateBlogPosts(contentPaths, context, options);
|
|
518
|
+
const {blogPosts} = content;
|
|
523
519
|
if (!blogPosts.length) {
|
|
524
520
|
return;
|
|
525
521
|
}
|