@docusaurus/plugin-content-blog 0.0.0-4432 → 0.0.0-4436
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.d.ts +0 -6
- package/lib/feed.js +6 -6
- package/package.json +8 -8
- package/src/feed.ts +17 -7
package/lib/feed.d.ts
CHANGED
|
@@ -4,15 +4,9 @@
|
|
|
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 { Feed } from 'feed';
|
|
8
7
|
import type { BlogPost } from './types';
|
|
9
8
|
import type { DocusaurusConfig } from '@docusaurus/types';
|
|
10
9
|
import type { PluginOptions } from '@docusaurus/plugin-content-blog';
|
|
11
|
-
export declare function generateBlogFeed({ blogPosts, options, siteConfig, }: {
|
|
12
|
-
blogPosts: BlogPost[];
|
|
13
|
-
options: PluginOptions;
|
|
14
|
-
siteConfig: DocusaurusConfig;
|
|
15
|
-
}): Promise<Feed | null>;
|
|
16
10
|
export declare function createBlogFeedFiles({ blogPosts, options, siteConfig, outDir, }: {
|
|
17
11
|
blogPosts: BlogPost[];
|
|
18
12
|
options: PluginOptions;
|
package/lib/feed.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.createBlogFeedFiles =
|
|
9
|
+
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");
|
|
@@ -32,8 +32,7 @@ async function generateBlogFeed({ blogPosts, options, siteConfig, }) {
|
|
|
32
32
|
const { feedOptions, routeBasePath } = options;
|
|
33
33
|
const { url: siteUrl, baseUrl, title, favicon } = siteConfig;
|
|
34
34
|
const blogBaseUrl = (0, utils_1.normalizeUrl)([siteUrl, baseUrl, routeBasePath]);
|
|
35
|
-
const updated =
|
|
36
|
-
new Date('2015-10-25T16:29:00.000-07:00'); // weird legacy magic date
|
|
35
|
+
const updated = blogPosts[0] && blogPosts[0].metadata.date;
|
|
37
36
|
const feed = new feed_1.Feed({
|
|
38
37
|
id: blogBaseUrl,
|
|
39
38
|
title: feedOptions.title || `${title} Blog`,
|
|
@@ -50,13 +49,15 @@ async function generateBlogFeed({ blogPosts, options, siteConfig, }) {
|
|
|
50
49
|
return { name: author.name, link: author.url };
|
|
51
50
|
}
|
|
52
51
|
blogPosts.forEach((post) => {
|
|
53
|
-
const { id, metadata: { title: metadataTitle, permalink, date, description, authors }, } = post;
|
|
52
|
+
const { id, metadata: { title: metadataTitle, permalink, date, description, authors, tags, }, } = post;
|
|
54
53
|
const feedItem = {
|
|
55
54
|
title: metadataTitle,
|
|
56
55
|
id,
|
|
57
56
|
link: (0, utils_1.normalizeUrl)([siteUrl, permalink]),
|
|
58
57
|
date,
|
|
59
58
|
description,
|
|
59
|
+
// Atom feed demands the "term", while other feeds use "name"
|
|
60
|
+
category: tags.map((tag) => ({ name: tag.label, term: tag.label })),
|
|
60
61
|
content: mdxToFeedContent(post.content),
|
|
61
62
|
};
|
|
62
63
|
// json1() method takes the first item of authors array
|
|
@@ -69,7 +70,6 @@ async function generateBlogFeed({ blogPosts, options, siteConfig, }) {
|
|
|
69
70
|
});
|
|
70
71
|
return feed;
|
|
71
72
|
}
|
|
72
|
-
exports.generateBlogFeed = generateBlogFeed;
|
|
73
73
|
async function createBlogFeedFile({ feed, feedType, generatePath, }) {
|
|
74
74
|
const [feedContent, feedPath] = (() => {
|
|
75
75
|
switch (feedType) {
|
|
@@ -84,7 +84,7 @@ async function createBlogFeedFile({ feed, feedType, generatePath, }) {
|
|
|
84
84
|
}
|
|
85
85
|
})();
|
|
86
86
|
try {
|
|
87
|
-
await fs_extra_1.default.outputFile(path_1.default.join(generatePath, feedPath), feedContent);
|
|
87
|
+
await fs_extra_1.default.outputFile((0, utils_1.posixPath)(path_1.default.join(generatePath, feedPath)), feedContent);
|
|
88
88
|
}
|
|
89
89
|
catch (err) {
|
|
90
90
|
throw new Error(`Generating ${feedType} feed failed: ${err}.`);
|
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-4436",
|
|
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,11 @@
|
|
|
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-4436",
|
|
22
|
+
"@docusaurus/logger": "0.0.0-4436",
|
|
23
|
+
"@docusaurus/mdx-loader": "0.0.0-4436",
|
|
24
|
+
"@docusaurus/utils": "0.0.0-4436",
|
|
25
|
+
"@docusaurus/utils-validation": "0.0.0-4436",
|
|
26
26
|
"escape-string-regexp": "^4.0.0",
|
|
27
27
|
"feed": "^4.2.2",
|
|
28
28
|
"fs-extra": "^10.0.0",
|
|
@@ -36,7 +36,7 @@
|
|
|
36
36
|
"webpack": "^5.61.0"
|
|
37
37
|
},
|
|
38
38
|
"devDependencies": {
|
|
39
|
-
"@docusaurus/types": "0.0.0-
|
|
39
|
+
"@docusaurus/types": "0.0.0-4436"
|
|
40
40
|
},
|
|
41
41
|
"peerDependencies": {
|
|
42
42
|
"react": "^16.8.4 || ^17.0.0",
|
|
@@ -45,5 +45,5 @@
|
|
|
45
45
|
"engines": {
|
|
46
46
|
"node": ">=14"
|
|
47
47
|
},
|
|
48
|
-
"gitHead": "
|
|
48
|
+
"gitHead": "3b2e15935a716c69bd530fe10942e1620b36ddc4"
|
|
49
49
|
}
|
package/src/feed.ts
CHANGED
|
@@ -7,7 +7,7 @@
|
|
|
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 {normalizeUrl, mdxToHtml} from '@docusaurus/utils';
|
|
10
|
+
import {normalizeUrl, mdxToHtml, posixPath} from '@docusaurus/utils';
|
|
11
11
|
import type {DocusaurusConfig} from '@docusaurus/types';
|
|
12
12
|
import path from 'path';
|
|
13
13
|
import fs from 'fs-extra';
|
|
@@ -30,7 +30,7 @@ function mdxToFeedContent(mdxContent: string): string | undefined {
|
|
|
30
30
|
}
|
|
31
31
|
}
|
|
32
32
|
|
|
33
|
-
|
|
33
|
+
async function generateBlogFeed({
|
|
34
34
|
blogPosts,
|
|
35
35
|
options,
|
|
36
36
|
siteConfig,
|
|
@@ -47,9 +47,7 @@ export async function generateBlogFeed({
|
|
|
47
47
|
const {url: siteUrl, baseUrl, title, favicon} = siteConfig;
|
|
48
48
|
const blogBaseUrl = normalizeUrl([siteUrl, baseUrl, routeBasePath]);
|
|
49
49
|
|
|
50
|
-
const updated =
|
|
51
|
-
(blogPosts[0] && blogPosts[0].metadata.date) ||
|
|
52
|
-
new Date('2015-10-25T16:29:00.000-07:00'); // weird legacy magic date
|
|
50
|
+
const updated = blogPosts[0] && blogPosts[0].metadata.date;
|
|
53
51
|
|
|
54
52
|
const feed = new Feed({
|
|
55
53
|
id: blogBaseUrl,
|
|
@@ -71,7 +69,14 @@ export async function generateBlogFeed({
|
|
|
71
69
|
blogPosts.forEach((post) => {
|
|
72
70
|
const {
|
|
73
71
|
id,
|
|
74
|
-
metadata: {
|
|
72
|
+
metadata: {
|
|
73
|
+
title: metadataTitle,
|
|
74
|
+
permalink,
|
|
75
|
+
date,
|
|
76
|
+
description,
|
|
77
|
+
authors,
|
|
78
|
+
tags,
|
|
79
|
+
},
|
|
75
80
|
} = post;
|
|
76
81
|
|
|
77
82
|
const feedItem: FeedItem = {
|
|
@@ -80,6 +85,8 @@ export async function generateBlogFeed({
|
|
|
80
85
|
link: normalizeUrl([siteUrl, permalink]),
|
|
81
86
|
date,
|
|
82
87
|
description,
|
|
88
|
+
// Atom feed demands the "term", while other feeds use "name"
|
|
89
|
+
category: tags.map((tag) => ({name: tag.label, term: tag.label})),
|
|
83
90
|
content: mdxToFeedContent(post.content),
|
|
84
91
|
};
|
|
85
92
|
|
|
@@ -118,7 +125,10 @@ async function createBlogFeedFile({
|
|
|
118
125
|
}
|
|
119
126
|
})();
|
|
120
127
|
try {
|
|
121
|
-
await fs.outputFile(
|
|
128
|
+
await fs.outputFile(
|
|
129
|
+
posixPath(path.join(generatePath, feedPath)),
|
|
130
|
+
feedContent,
|
|
131
|
+
);
|
|
122
132
|
} catch (err) {
|
|
123
133
|
throw new Error(`Generating ${feedType} feed failed: ${err}.`);
|
|
124
134
|
}
|