@docusaurus/plugin-content-blog 0.0.0-4540 → 0.0.0-4546
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 +14 -2
- package/lib/blogUtils.js +44 -7
- package/lib/index.js +51 -63
- package/lib/types.d.ts +2 -1
- package/package.json +9 -9
- package/src/blogUtils.ts +70 -6
- package/src/index.ts +67 -75
- package/src/plugin-content-blog.d.ts +2 -0
- package/src/types.ts +7 -3
package/lib/blogUtils.d.ts
CHANGED
|
@@ -4,12 +4,24 @@
|
|
|
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 type { BlogPost, BlogContentPaths, BlogMarkdownLoaderOptions, BlogTags } from './types';
|
|
7
|
+
import type { BlogPost, BlogContentPaths, BlogMarkdownLoaderOptions, BlogTags, BlogPaginated } from './types';
|
|
8
8
|
import type { LoadContext } from '@docusaurus/types';
|
|
9
9
|
import type { PluginOptions } from '@docusaurus/plugin-content-blog';
|
|
10
10
|
export declare function truncate(fileString: string, truncateMarker: RegExp): string;
|
|
11
11
|
export declare function getSourceToPermalink(blogPosts: BlogPost[]): Record<string, string>;
|
|
12
|
-
export declare function
|
|
12
|
+
export declare function paginateBlogPosts({ blogPosts, basePageUrl, blogTitle, blogDescription, postsPerPageOption, }: {
|
|
13
|
+
blogPosts: BlogPost[];
|
|
14
|
+
basePageUrl: string;
|
|
15
|
+
blogTitle: string;
|
|
16
|
+
blogDescription: string;
|
|
17
|
+
postsPerPageOption: number | 'ALL';
|
|
18
|
+
}): BlogPaginated[];
|
|
19
|
+
export declare function getBlogTags({ blogPosts, ...params }: {
|
|
20
|
+
blogPosts: BlogPost[];
|
|
21
|
+
blogTitle: string;
|
|
22
|
+
blogDescription: string;
|
|
23
|
+
postsPerPageOption: number | 'ALL';
|
|
24
|
+
}): BlogTags;
|
|
13
25
|
declare type ParsedBlogFileName = {
|
|
14
26
|
date: Date | undefined;
|
|
15
27
|
text: string;
|
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.linkify = exports.generateBlogPosts = exports.parseBlogFileName = exports.getBlogTags = exports.getSourceToPermalink = exports.truncate = void 0;
|
|
9
|
+
exports.linkify = exports.generateBlogPosts = exports.parseBlogFileName = exports.getBlogTags = exports.paginateBlogPosts = 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"));
|
|
@@ -24,13 +24,50 @@ function getSourceToPermalink(blogPosts) {
|
|
|
24
24
|
return (0, lodash_1.mapValues)((0, lodash_1.keyBy)(blogPosts, (item) => item.metadata.source), (v) => v.metadata.permalink);
|
|
25
25
|
}
|
|
26
26
|
exports.getSourceToPermalink = getSourceToPermalink;
|
|
27
|
-
function
|
|
27
|
+
function paginateBlogPosts({ blogPosts, basePageUrl, blogTitle, blogDescription, postsPerPageOption, }) {
|
|
28
|
+
const totalCount = blogPosts.length;
|
|
29
|
+
const postsPerPage = postsPerPageOption === 'ALL' ? totalCount : postsPerPageOption;
|
|
30
|
+
const numberOfPages = Math.ceil(totalCount / postsPerPage);
|
|
31
|
+
const pages = [];
|
|
32
|
+
function permalink(page) {
|
|
33
|
+
return page > 0 ? `${basePageUrl}/page/${page + 1}` : basePageUrl;
|
|
34
|
+
}
|
|
35
|
+
for (let page = 0; page < numberOfPages; page += 1) {
|
|
36
|
+
pages.push({
|
|
37
|
+
items: blogPosts
|
|
38
|
+
.slice(page * postsPerPage, (page + 1) * postsPerPage)
|
|
39
|
+
.map((item) => item.id),
|
|
40
|
+
metadata: {
|
|
41
|
+
permalink: permalink(page),
|
|
42
|
+
page: page + 1,
|
|
43
|
+
postsPerPage,
|
|
44
|
+
totalPages: numberOfPages,
|
|
45
|
+
totalCount,
|
|
46
|
+
previousPage: page !== 0 ? permalink(page - 1) : null,
|
|
47
|
+
nextPage: page < numberOfPages - 1 ? permalink(page + 1) : null,
|
|
48
|
+
blogDescription,
|
|
49
|
+
blogTitle,
|
|
50
|
+
},
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
return pages;
|
|
54
|
+
}
|
|
55
|
+
exports.paginateBlogPosts = paginateBlogPosts;
|
|
56
|
+
function getBlogTags({ blogPosts, ...params }) {
|
|
28
57
|
const groups = (0, utils_1.groupTaggedItems)(blogPosts, (blogPost) => blogPost.metadata.tags);
|
|
29
|
-
return (0, lodash_1.mapValues)(groups, (group) =>
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
58
|
+
return (0, lodash_1.mapValues)(groups, (group) => {
|
|
59
|
+
const { tag, items: tagBlogPosts } = group;
|
|
60
|
+
return {
|
|
61
|
+
name: tag.label,
|
|
62
|
+
items: tagBlogPosts.map((item) => item.id),
|
|
63
|
+
permalink: tag.permalink,
|
|
64
|
+
pages: paginateBlogPosts({
|
|
65
|
+
blogPosts: tagBlogPosts,
|
|
66
|
+
basePageUrl: group.tag.permalink,
|
|
67
|
+
...params,
|
|
68
|
+
}),
|
|
69
|
+
};
|
|
70
|
+
});
|
|
34
71
|
}
|
|
35
72
|
exports.getBlogTags = getBlogTags;
|
|
36
73
|
const DATE_FILENAME_REGEX = /^(?<folder>.*)(?<date>\d{4}[-/]\d{1,2}[-/]\d{1,2})[-/]?(?<text>.*?)(?:\/index)?.mdx?$/;
|
package/lib/index.js
CHANGED
|
@@ -62,6 +62,7 @@ async function pluginContentBlog(context, options) {
|
|
|
62
62
|
blogListPaginated: [],
|
|
63
63
|
blogTags: {},
|
|
64
64
|
blogTagsListPath: null,
|
|
65
|
+
blogTagsPaginated: [],
|
|
65
66
|
};
|
|
66
67
|
}
|
|
67
68
|
// Colocate next and prev metadata.
|
|
@@ -81,39 +82,20 @@ async function pluginContentBlog(context, options) {
|
|
|
81
82
|
};
|
|
82
83
|
}
|
|
83
84
|
});
|
|
84
|
-
// Blog pagination routes.
|
|
85
|
-
// Example: `/blog`, `/blog/page/1`, `/blog/page/2`
|
|
86
|
-
const totalCount = blogPosts.length;
|
|
87
|
-
const postsPerPage = postsPerPageOption === 'ALL' ? totalCount : postsPerPageOption;
|
|
88
|
-
const numberOfPages = Math.ceil(totalCount / postsPerPage);
|
|
89
85
|
const baseBlogUrl = (0, utils_1.normalizeUrl)([baseUrl, routeBasePath]);
|
|
90
|
-
const blogListPaginated =
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
totalCount,
|
|
104
|
-
previousPage: page !== 0 ? blogPaginationPermalink(page - 1) : null,
|
|
105
|
-
nextPage: page < numberOfPages - 1
|
|
106
|
-
? blogPaginationPermalink(page + 1)
|
|
107
|
-
: null,
|
|
108
|
-
blogDescription,
|
|
109
|
-
blogTitle,
|
|
110
|
-
},
|
|
111
|
-
items: blogPosts
|
|
112
|
-
.slice(page * postsPerPage, (page + 1) * postsPerPage)
|
|
113
|
-
.map((item) => item.id),
|
|
114
|
-
});
|
|
115
|
-
}
|
|
116
|
-
const blogTags = (0, blogUtils_1.getBlogTags)(blogPosts);
|
|
86
|
+
const blogListPaginated = (0, blogUtils_1.paginateBlogPosts)({
|
|
87
|
+
blogPosts,
|
|
88
|
+
blogTitle,
|
|
89
|
+
blogDescription,
|
|
90
|
+
postsPerPageOption,
|
|
91
|
+
basePageUrl: baseBlogUrl,
|
|
92
|
+
});
|
|
93
|
+
const blogTags = (0, blogUtils_1.getBlogTags)({
|
|
94
|
+
blogPosts,
|
|
95
|
+
postsPerPageOption,
|
|
96
|
+
blogDescription,
|
|
97
|
+
blogTitle,
|
|
98
|
+
});
|
|
117
99
|
const tagsPath = (0, utils_1.normalizeUrl)([baseBlogUrl, tagsBasePath]);
|
|
118
100
|
const blogTagsListPath = Object.keys(blogTags).length > 0 ? tagsPath : null;
|
|
119
101
|
return {
|
|
@@ -212,40 +194,46 @@ async function pluginContentBlog(context, options) {
|
|
|
212
194
|
if (blogTagsListPath === null) {
|
|
213
195
|
return;
|
|
214
196
|
}
|
|
215
|
-
const tagsModule = {
|
|
216
|
-
|
|
217
|
-
const { name, items, permalink } = blogTags[tag];
|
|
218
|
-
// Refactor all this, see docs implementation
|
|
219
|
-
tagsModule[tag] = {
|
|
197
|
+
const tagsModule = Object.fromEntries(Object.entries(blogTags).map(([tagKey, tag]) => {
|
|
198
|
+
const tagModule = {
|
|
220
199
|
allTagsPath: blogTagsListPath,
|
|
221
|
-
slug:
|
|
222
|
-
name,
|
|
223
|
-
count: items.length,
|
|
224
|
-
permalink,
|
|
200
|
+
slug: tagKey,
|
|
201
|
+
name: tag.name,
|
|
202
|
+
count: tag.items.length,
|
|
203
|
+
permalink: tag.permalink,
|
|
225
204
|
};
|
|
226
|
-
|
|
227
|
-
addRoute({
|
|
228
|
-
path: permalink,
|
|
229
|
-
component: blogTagsPostsComponent,
|
|
230
|
-
exact: true,
|
|
231
|
-
modules: {
|
|
232
|
-
sidebar: aliasedSource(sidebarProp),
|
|
233
|
-
items: items.map((postID) => {
|
|
234
|
-
const metadata = blogItemsToMetadata[postID];
|
|
235
|
-
return {
|
|
236
|
-
content: {
|
|
237
|
-
__import: true,
|
|
238
|
-
path: metadata.source,
|
|
239
|
-
query: {
|
|
240
|
-
truncated: true,
|
|
241
|
-
},
|
|
242
|
-
},
|
|
243
|
-
};
|
|
244
|
-
}),
|
|
245
|
-
metadata: aliasedSource(tagsMetadataPath),
|
|
246
|
-
},
|
|
247
|
-
});
|
|
205
|
+
return [tag.name, tagModule];
|
|
248
206
|
}));
|
|
207
|
+
async function createTagRoutes(tag) {
|
|
208
|
+
await Promise.all(tag.pages.map(async (blogPaginated) => {
|
|
209
|
+
const { metadata, items } = blogPaginated;
|
|
210
|
+
const tagsMetadataPath = await createData(`${(0, utils_1.docuHash)(metadata.permalink)}.json`, JSON.stringify(tagsModule[tag.name], null, 2));
|
|
211
|
+
const listMetadataPath = await createData(`${(0, utils_1.docuHash)(metadata.permalink)}-list.json`, JSON.stringify(metadata, null, 2));
|
|
212
|
+
addRoute({
|
|
213
|
+
path: metadata.permalink,
|
|
214
|
+
component: blogTagsPostsComponent,
|
|
215
|
+
exact: true,
|
|
216
|
+
modules: {
|
|
217
|
+
sidebar: aliasedSource(sidebarProp),
|
|
218
|
+
items: items.map((postID) => {
|
|
219
|
+
const blogPostMetadata = blogItemsToMetadata[postID];
|
|
220
|
+
return {
|
|
221
|
+
content: {
|
|
222
|
+
__import: true,
|
|
223
|
+
path: blogPostMetadata.source,
|
|
224
|
+
query: {
|
|
225
|
+
truncated: true,
|
|
226
|
+
},
|
|
227
|
+
},
|
|
228
|
+
};
|
|
229
|
+
}),
|
|
230
|
+
metadata: aliasedSource(tagsMetadataPath),
|
|
231
|
+
listMetadata: aliasedSource(listMetadataPath),
|
|
232
|
+
},
|
|
233
|
+
});
|
|
234
|
+
}));
|
|
235
|
+
}
|
|
236
|
+
await Promise.all(Object.values(blogTags).map(createTagRoutes));
|
|
249
237
|
// Only create /tags page if there are tags.
|
|
250
238
|
if (Object.keys(blogTags).length > 0) {
|
|
251
239
|
const tagsListPath = await createData(`${(0, utils_1.docuHash)(`${blogTagsListPath}-tags`)}.json`, JSON.stringify(tagsModule, null, 2));
|
package/lib/types.d.ts
CHANGED
|
@@ -16,12 +16,13 @@ export interface BlogContent {
|
|
|
16
16
|
blogTagsListPath: string | null;
|
|
17
17
|
}
|
|
18
18
|
export interface BlogTags {
|
|
19
|
-
[
|
|
19
|
+
[tagKey: string]: BlogTag;
|
|
20
20
|
}
|
|
21
21
|
export interface BlogTag {
|
|
22
22
|
name: string;
|
|
23
23
|
items: string[];
|
|
24
24
|
permalink: string;
|
|
25
|
+
pages: BlogPaginated[];
|
|
25
26
|
}
|
|
26
27
|
export interface BlogPost {
|
|
27
28
|
id: 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-4546",
|
|
4
4
|
"description": "Blog plugin for Docusaurus.",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"types": "src/plugin-content-blog.d.ts",
|
|
@@ -18,12 +18,12 @@
|
|
|
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-common": "0.0.0-
|
|
26
|
-
"@docusaurus/utils-validation": "0.0.0-
|
|
21
|
+
"@docusaurus/core": "0.0.0-4546",
|
|
22
|
+
"@docusaurus/logger": "0.0.0-4546",
|
|
23
|
+
"@docusaurus/mdx-loader": "0.0.0-4546",
|
|
24
|
+
"@docusaurus/utils": "0.0.0-4546",
|
|
25
|
+
"@docusaurus/utils-common": "0.0.0-4546",
|
|
26
|
+
"@docusaurus/utils-validation": "0.0.0-4546",
|
|
27
27
|
"cheerio": "^1.0.0-rc.10",
|
|
28
28
|
"feed": "^4.2.2",
|
|
29
29
|
"fs-extra": "^10.0.0",
|
|
@@ -35,7 +35,7 @@
|
|
|
35
35
|
"webpack": "^5.68.0"
|
|
36
36
|
},
|
|
37
37
|
"devDependencies": {
|
|
38
|
-
"@docusaurus/types": "0.0.0-
|
|
38
|
+
"@docusaurus/types": "0.0.0-4546",
|
|
39
39
|
"escape-string-regexp": "^4.0.0"
|
|
40
40
|
},
|
|
41
41
|
"peerDependencies": {
|
|
@@ -46,5 +46,5 @@
|
|
|
46
46
|
"engines": {
|
|
47
47
|
"node": ">=14"
|
|
48
48
|
},
|
|
49
|
-
"gitHead": "
|
|
49
|
+
"gitHead": "f4dc68b452de796a2afbc90dfa03322c3c579b03"
|
|
50
50
|
}
|
package/src/blogUtils.ts
CHANGED
|
@@ -14,6 +14,7 @@ import type {
|
|
|
14
14
|
BlogContentPaths,
|
|
15
15
|
BlogMarkdownLoaderOptions,
|
|
16
16
|
BlogTags,
|
|
17
|
+
BlogPaginated,
|
|
17
18
|
} from './types';
|
|
18
19
|
import {
|
|
19
20
|
parseMarkdownString,
|
|
@@ -50,16 +51,79 @@ export function getSourceToPermalink(
|
|
|
50
51
|
);
|
|
51
52
|
}
|
|
52
53
|
|
|
53
|
-
export function
|
|
54
|
+
export function paginateBlogPosts({
|
|
55
|
+
blogPosts,
|
|
56
|
+
basePageUrl,
|
|
57
|
+
blogTitle,
|
|
58
|
+
blogDescription,
|
|
59
|
+
postsPerPageOption,
|
|
60
|
+
}: {
|
|
61
|
+
blogPosts: BlogPost[];
|
|
62
|
+
basePageUrl: string;
|
|
63
|
+
blogTitle: string;
|
|
64
|
+
blogDescription: string;
|
|
65
|
+
postsPerPageOption: number | 'ALL';
|
|
66
|
+
}): BlogPaginated[] {
|
|
67
|
+
const totalCount = blogPosts.length;
|
|
68
|
+
const postsPerPage =
|
|
69
|
+
postsPerPageOption === 'ALL' ? totalCount : postsPerPageOption;
|
|
70
|
+
const numberOfPages = Math.ceil(totalCount / postsPerPage);
|
|
71
|
+
|
|
72
|
+
const pages: BlogPaginated[] = [];
|
|
73
|
+
|
|
74
|
+
function permalink(page: number) {
|
|
75
|
+
return page > 0 ? `${basePageUrl}/page/${page + 1}` : basePageUrl;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
for (let page = 0; page < numberOfPages; page += 1) {
|
|
79
|
+
pages.push({
|
|
80
|
+
items: blogPosts
|
|
81
|
+
.slice(page * postsPerPage, (page + 1) * postsPerPage)
|
|
82
|
+
.map((item) => item.id),
|
|
83
|
+
metadata: {
|
|
84
|
+
permalink: permalink(page),
|
|
85
|
+
page: page + 1,
|
|
86
|
+
postsPerPage,
|
|
87
|
+
totalPages: numberOfPages,
|
|
88
|
+
totalCount,
|
|
89
|
+
previousPage: page !== 0 ? permalink(page - 1) : null,
|
|
90
|
+
nextPage: page < numberOfPages - 1 ? permalink(page + 1) : null,
|
|
91
|
+
blogDescription,
|
|
92
|
+
blogTitle,
|
|
93
|
+
},
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
return pages;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
export function getBlogTags({
|
|
101
|
+
blogPosts,
|
|
102
|
+
...params
|
|
103
|
+
}: {
|
|
104
|
+
blogPosts: BlogPost[];
|
|
105
|
+
blogTitle: string;
|
|
106
|
+
blogDescription: string;
|
|
107
|
+
postsPerPageOption: number | 'ALL';
|
|
108
|
+
}): BlogTags {
|
|
54
109
|
const groups = groupTaggedItems(
|
|
55
110
|
blogPosts,
|
|
56
111
|
(blogPost) => blogPost.metadata.tags,
|
|
57
112
|
);
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
items:
|
|
61
|
-
|
|
62
|
-
|
|
113
|
+
|
|
114
|
+
return mapValues(groups, (group) => {
|
|
115
|
+
const {tag, items: tagBlogPosts} = group;
|
|
116
|
+
return {
|
|
117
|
+
name: tag.label,
|
|
118
|
+
items: tagBlogPosts.map((item) => item.id),
|
|
119
|
+
permalink: tag.permalink,
|
|
120
|
+
pages: paginateBlogPosts({
|
|
121
|
+
blogPosts: tagBlogPosts,
|
|
122
|
+
basePageUrl: group.tag.permalink,
|
|
123
|
+
...params,
|
|
124
|
+
}),
|
|
125
|
+
};
|
|
126
|
+
});
|
|
63
127
|
}
|
|
64
128
|
|
|
65
129
|
const DATE_FILENAME_REGEX =
|
package/src/index.ts
CHANGED
|
@@ -23,6 +23,7 @@ import {
|
|
|
23
23
|
import {translateContent, getTranslationFiles} from './translations';
|
|
24
24
|
|
|
25
25
|
import type {
|
|
26
|
+
BlogTag,
|
|
26
27
|
BlogTags,
|
|
27
28
|
BlogContent,
|
|
28
29
|
BlogItemsToMetadata,
|
|
@@ -31,6 +32,7 @@ import type {
|
|
|
31
32
|
BlogContentPaths,
|
|
32
33
|
BlogMarkdownLoaderOptions,
|
|
33
34
|
MetaData,
|
|
35
|
+
TagModule,
|
|
34
36
|
} from './types';
|
|
35
37
|
import {PluginOptionSchema} from './pluginOptionSchema';
|
|
36
38
|
import type {
|
|
@@ -46,6 +48,7 @@ import {
|
|
|
46
48
|
generateBlogPosts,
|
|
47
49
|
getSourceToPermalink,
|
|
48
50
|
getBlogTags,
|
|
51
|
+
paginateBlogPosts,
|
|
49
52
|
} from './blogUtils';
|
|
50
53
|
import {createBlogFeedFiles} from './feed';
|
|
51
54
|
import type {
|
|
@@ -134,6 +137,7 @@ export default async function pluginContentBlog(
|
|
|
134
137
|
blogListPaginated: [],
|
|
135
138
|
blogTags: {},
|
|
136
139
|
blogTagsListPath: null,
|
|
140
|
+
blogTagsPaginated: [],
|
|
137
141
|
};
|
|
138
142
|
}
|
|
139
143
|
|
|
@@ -157,45 +161,22 @@ export default async function pluginContentBlog(
|
|
|
157
161
|
}
|
|
158
162
|
});
|
|
159
163
|
|
|
160
|
-
// Blog pagination routes.
|
|
161
|
-
// Example: `/blog`, `/blog/page/1`, `/blog/page/2`
|
|
162
|
-
const totalCount = blogPosts.length;
|
|
163
|
-
const postsPerPage =
|
|
164
|
-
postsPerPageOption === 'ALL' ? totalCount : postsPerPageOption;
|
|
165
|
-
const numberOfPages = Math.ceil(totalCount / postsPerPage);
|
|
166
164
|
const baseBlogUrl = normalizeUrl([baseUrl, routeBasePath]);
|
|
167
165
|
|
|
168
|
-
const blogListPaginated: BlogPaginated[] =
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
for (let page = 0; page < numberOfPages; page += 1) {
|
|
177
|
-
blogListPaginated.push({
|
|
178
|
-
metadata: {
|
|
179
|
-
permalink: blogPaginationPermalink(page),
|
|
180
|
-
page: page + 1,
|
|
181
|
-
postsPerPage,
|
|
182
|
-
totalPages: numberOfPages,
|
|
183
|
-
totalCount,
|
|
184
|
-
previousPage: page !== 0 ? blogPaginationPermalink(page - 1) : null,
|
|
185
|
-
nextPage:
|
|
186
|
-
page < numberOfPages - 1
|
|
187
|
-
? blogPaginationPermalink(page + 1)
|
|
188
|
-
: null,
|
|
189
|
-
blogDescription,
|
|
190
|
-
blogTitle,
|
|
191
|
-
},
|
|
192
|
-
items: blogPosts
|
|
193
|
-
.slice(page * postsPerPage, (page + 1) * postsPerPage)
|
|
194
|
-
.map((item) => item.id),
|
|
195
|
-
});
|
|
196
|
-
}
|
|
166
|
+
const blogListPaginated: BlogPaginated[] = paginateBlogPosts({
|
|
167
|
+
blogPosts,
|
|
168
|
+
blogTitle,
|
|
169
|
+
blogDescription,
|
|
170
|
+
postsPerPageOption,
|
|
171
|
+
basePageUrl: baseBlogUrl,
|
|
172
|
+
});
|
|
197
173
|
|
|
198
|
-
const blogTags: BlogTags = getBlogTags(
|
|
174
|
+
const blogTags: BlogTags = getBlogTags({
|
|
175
|
+
blogPosts,
|
|
176
|
+
postsPerPageOption,
|
|
177
|
+
blogDescription,
|
|
178
|
+
blogTitle,
|
|
179
|
+
});
|
|
199
180
|
|
|
200
181
|
const tagsPath = normalizeUrl([baseBlogUrl, tagsBasePath]);
|
|
201
182
|
|
|
@@ -345,50 +326,61 @@ export default async function pluginContentBlog(
|
|
|
345
326
|
return;
|
|
346
327
|
}
|
|
347
328
|
|
|
348
|
-
const tagsModule: TagsModule =
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
Object.keys(blogTags).map(async (tag) => {
|
|
352
|
-
const {name, items, permalink} = blogTags[tag];
|
|
353
|
-
|
|
354
|
-
// Refactor all this, see docs implementation
|
|
355
|
-
tagsModule[tag] = {
|
|
329
|
+
const tagsModule: TagsModule = Object.fromEntries(
|
|
330
|
+
Object.entries(blogTags).map(([tagKey, tag]) => {
|
|
331
|
+
const tagModule: TagModule = {
|
|
356
332
|
allTagsPath: blogTagsListPath,
|
|
357
|
-
slug:
|
|
358
|
-
name,
|
|
359
|
-
count: items.length,
|
|
360
|
-
permalink,
|
|
333
|
+
slug: tagKey,
|
|
334
|
+
name: tag.name,
|
|
335
|
+
count: tag.items.length,
|
|
336
|
+
permalink: tag.permalink,
|
|
361
337
|
};
|
|
362
|
-
|
|
363
|
-
const tagsMetadataPath = await createData(
|
|
364
|
-
`${docuHash(permalink)}.json`,
|
|
365
|
-
JSON.stringify(tagsModule[tag], null, 2),
|
|
366
|
-
);
|
|
367
|
-
|
|
368
|
-
addRoute({
|
|
369
|
-
path: permalink,
|
|
370
|
-
component: blogTagsPostsComponent,
|
|
371
|
-
exact: true,
|
|
372
|
-
modules: {
|
|
373
|
-
sidebar: aliasedSource(sidebarProp),
|
|
374
|
-
items: items.map((postID) => {
|
|
375
|
-
const metadata = blogItemsToMetadata[postID];
|
|
376
|
-
return {
|
|
377
|
-
content: {
|
|
378
|
-
__import: true,
|
|
379
|
-
path: metadata.source,
|
|
380
|
-
query: {
|
|
381
|
-
truncated: true,
|
|
382
|
-
},
|
|
383
|
-
},
|
|
384
|
-
};
|
|
385
|
-
}),
|
|
386
|
-
metadata: aliasedSource(tagsMetadataPath),
|
|
387
|
-
},
|
|
388
|
-
});
|
|
338
|
+
return [tag.name, tagModule];
|
|
389
339
|
}),
|
|
390
340
|
);
|
|
391
341
|
|
|
342
|
+
async function createTagRoutes(tag: BlogTag): Promise<void> {
|
|
343
|
+
await Promise.all(
|
|
344
|
+
tag.pages.map(async (blogPaginated) => {
|
|
345
|
+
const {metadata, items} = blogPaginated;
|
|
346
|
+
const tagsMetadataPath = await createData(
|
|
347
|
+
`${docuHash(metadata.permalink)}.json`,
|
|
348
|
+
JSON.stringify(tagsModule[tag.name], null, 2),
|
|
349
|
+
);
|
|
350
|
+
|
|
351
|
+
const listMetadataPath = await createData(
|
|
352
|
+
`${docuHash(metadata.permalink)}-list.json`,
|
|
353
|
+
JSON.stringify(metadata, null, 2),
|
|
354
|
+
);
|
|
355
|
+
|
|
356
|
+
addRoute({
|
|
357
|
+
path: metadata.permalink,
|
|
358
|
+
component: blogTagsPostsComponent,
|
|
359
|
+
exact: true,
|
|
360
|
+
modules: {
|
|
361
|
+
sidebar: aliasedSource(sidebarProp),
|
|
362
|
+
items: items.map((postID) => {
|
|
363
|
+
const blogPostMetadata = blogItemsToMetadata[postID];
|
|
364
|
+
return {
|
|
365
|
+
content: {
|
|
366
|
+
__import: true,
|
|
367
|
+
path: blogPostMetadata.source,
|
|
368
|
+
query: {
|
|
369
|
+
truncated: true,
|
|
370
|
+
},
|
|
371
|
+
},
|
|
372
|
+
};
|
|
373
|
+
}),
|
|
374
|
+
metadata: aliasedSource(tagsMetadataPath),
|
|
375
|
+
listMetadata: aliasedSource(listMetadataPath),
|
|
376
|
+
},
|
|
377
|
+
});
|
|
378
|
+
}),
|
|
379
|
+
);
|
|
380
|
+
}
|
|
381
|
+
|
|
382
|
+
await Promise.all(Object.values(blogTags).map(createTagRoutes));
|
|
383
|
+
|
|
392
384
|
// Only create /tags page if there are tags.
|
|
393
385
|
if (Object.keys(blogTags).length > 0) {
|
|
394
386
|
const tagsListPath = await createData(
|
|
@@ -259,10 +259,12 @@ declare module '@theme/BlogTagsPostsPage' {
|
|
|
259
259
|
import type {BlogSidebar} from '@theme/BlogSidebar';
|
|
260
260
|
import type {Tag} from '@theme/BlogTagsListPage';
|
|
261
261
|
import type {Content} from '@theme/BlogPostPage';
|
|
262
|
+
import type {Metadata} from '@theme/BlogListPage';
|
|
262
263
|
|
|
263
264
|
export interface Props {
|
|
264
265
|
readonly sidebar: BlogSidebar;
|
|
265
266
|
readonly metadata: Tag;
|
|
267
|
+
readonly listMetadata: Metadata;
|
|
266
268
|
readonly items: readonly {readonly content: Content}[];
|
|
267
269
|
}
|
|
268
270
|
|
package/src/types.ts
CHANGED
|
@@ -26,13 +26,17 @@ export interface BlogContent {
|
|
|
26
26
|
}
|
|
27
27
|
|
|
28
28
|
export interface BlogTags {
|
|
29
|
-
|
|
29
|
+
// TODO, the key is the tag slug/permalink
|
|
30
|
+
// This is due to legacy frontmatter: tags: [{label: "xyz", permalink: "/1"}, {label: "xyz", permalink: "/2"}
|
|
31
|
+
// Soon we should forbid declaring permalink through frontmatter
|
|
32
|
+
[tagKey: string]: BlogTag;
|
|
30
33
|
}
|
|
31
34
|
|
|
32
35
|
export interface BlogTag {
|
|
33
36
|
name: string;
|
|
34
|
-
items: string[];
|
|
37
|
+
items: string[]; // blog post permalinks
|
|
35
38
|
permalink: string;
|
|
39
|
+
pages: BlogPaginated[];
|
|
36
40
|
}
|
|
37
41
|
|
|
38
42
|
export interface BlogPost {
|
|
@@ -55,7 +59,7 @@ export interface BlogPaginatedMetadata {
|
|
|
55
59
|
|
|
56
60
|
export interface BlogPaginated {
|
|
57
61
|
metadata: BlogPaginatedMetadata;
|
|
58
|
-
items: string[];
|
|
62
|
+
items: string[]; // blog post permalinks
|
|
59
63
|
}
|
|
60
64
|
|
|
61
65
|
export interface MetaData {
|