@docusaurus/plugin-content-blog 0.0.0-5956 → 0.0.0-5957
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 +1 -6
- package/lib/blogUtils.js +1 -13
- package/lib/index.js +59 -50
- package/lib/markdownLoader.js +2 -6
- package/lib/types.d.ts +1 -8
- package/package.json +9 -9
- package/src/blogUtils.ts +1 -31
- package/src/index.ts +78 -70
- package/src/markdownLoader.ts +3 -7
- package/src/types.ts +1 -6
package/lib/blogUtils.d.ts
CHANGED
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
/// <reference path="../src/plugin-content-blog.d.ts" />
|
|
8
8
|
import type { LoadContext } from '@docusaurus/types';
|
|
9
9
|
import type { PluginOptions, BlogPost, BlogTags, BlogPaginated } from '@docusaurus/plugin-content-blog';
|
|
10
|
-
import type { BlogContentPaths
|
|
10
|
+
import type { BlogContentPaths } from './types';
|
|
11
11
|
export declare function truncate(fileString: string, truncateMarker: RegExp): string;
|
|
12
12
|
export declare function getSourceToPermalink(blogPosts: BlogPost[]): {
|
|
13
13
|
[aliasedPath: string]: string;
|
|
@@ -35,11 +35,6 @@ type ParsedBlogFileName = {
|
|
|
35
35
|
};
|
|
36
36
|
export declare function parseBlogFileName(blogSourceRelative: string): ParsedBlogFileName;
|
|
37
37
|
export declare function generateBlogPosts(contentPaths: BlogContentPaths, context: LoadContext, options: PluginOptions): Promise<BlogPost[]>;
|
|
38
|
-
export type LinkifyParams = {
|
|
39
|
-
filePath: string;
|
|
40
|
-
fileString: string;
|
|
41
|
-
} & Pick<BlogMarkdownLoaderOptions, 'sourceToPermalink' | 'siteDir' | 'contentPaths' | 'onBrokenMarkdownLink'>;
|
|
42
|
-
export declare function linkify({ filePath, contentPaths, fileString, siteDir, sourceToPermalink, onBrokenMarkdownLink, }: LinkifyParams): string;
|
|
43
38
|
export declare function applyProcessBlogPosts({ blogPosts, processBlogPosts, }: {
|
|
44
39
|
blogPosts: BlogPost[];
|
|
45
40
|
processBlogPosts: PluginOptions['processBlogPosts'];
|
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.applyProcessBlogPosts = exports.
|
|
9
|
+
exports.applyProcessBlogPosts = exports.generateBlogPosts = exports.parseBlogFileName = exports.getBlogTags = exports.shouldBeListed = exports.paginateBlogPosts = exports.getSourceToPermalink = exports.truncate = void 0;
|
|
10
10
|
const tslib_1 = require("tslib");
|
|
11
11
|
const fs_extra_1 = tslib_1.__importDefault(require("fs-extra"));
|
|
12
12
|
const path_1 = tslib_1.__importDefault(require("path"));
|
|
@@ -252,18 +252,6 @@ async function generateBlogPosts(contentPaths, context, options) {
|
|
|
252
252
|
return blogPosts;
|
|
253
253
|
}
|
|
254
254
|
exports.generateBlogPosts = generateBlogPosts;
|
|
255
|
-
function linkify({ filePath, contentPaths, fileString, siteDir, sourceToPermalink, onBrokenMarkdownLink, }) {
|
|
256
|
-
const { newContent, brokenMarkdownLinks } = (0, utils_1.replaceMarkdownLinks)({
|
|
257
|
-
siteDir,
|
|
258
|
-
fileString,
|
|
259
|
-
filePath,
|
|
260
|
-
contentPaths,
|
|
261
|
-
sourceToPermalink,
|
|
262
|
-
});
|
|
263
|
-
brokenMarkdownLinks.forEach((l) => onBrokenMarkdownLink(l));
|
|
264
|
-
return newContent;
|
|
265
|
-
}
|
|
266
|
-
exports.linkify = linkify;
|
|
267
255
|
async function applyProcessBlogPosts({ blogPosts, processBlogPosts, }) {
|
|
268
256
|
const processedBlogPosts = await processBlogPosts({ blogPosts });
|
|
269
257
|
if (Array.isArray(processedBlogPosts)) {
|
package/lib/index.js
CHANGED
|
@@ -130,19 +130,65 @@ async function pluginContentBlog(context, options) {
|
|
|
130
130
|
},
|
|
131
131
|
configureWebpack(_config, isServer, utils, content) {
|
|
132
132
|
const { admonitions, rehypePlugins, remarkPlugins, truncateMarker, beforeDefaultRemarkPlugins, beforeDefaultRehypePlugins, } = options;
|
|
133
|
-
const
|
|
134
|
-
siteDir,
|
|
135
|
-
contentPaths,
|
|
136
|
-
truncateMarker,
|
|
137
|
-
sourceToPermalink: (0, blogUtils_1.getSourceToPermalink)(content.blogPosts),
|
|
138
|
-
onBrokenMarkdownLink: (brokenMarkdownLink) => {
|
|
139
|
-
if (onBrokenMarkdownLinks === 'ignore') {
|
|
140
|
-
return;
|
|
141
|
-
}
|
|
142
|
-
logger_1.default.report(onBrokenMarkdownLinks) `Blog markdown link couldn't be resolved: (url=${brokenMarkdownLink.link}) in path=${brokenMarkdownLink.filePath}`;
|
|
143
|
-
},
|
|
144
|
-
};
|
|
133
|
+
const sourceToPermalink = (0, blogUtils_1.getSourceToPermalink)(content.blogPosts);
|
|
145
134
|
const contentDirs = (0, utils_1.getContentPathList)(contentPaths);
|
|
135
|
+
function createMDXLoader() {
|
|
136
|
+
const loaderOptions = {
|
|
137
|
+
admonitions,
|
|
138
|
+
remarkPlugins,
|
|
139
|
+
rehypePlugins,
|
|
140
|
+
beforeDefaultRemarkPlugins: [
|
|
141
|
+
footnoteIDFixer_1.default,
|
|
142
|
+
...beforeDefaultRemarkPlugins,
|
|
143
|
+
],
|
|
144
|
+
beforeDefaultRehypePlugins,
|
|
145
|
+
staticDirs: siteConfig.staticDirectories.map((dir) => path_1.default.resolve(siteDir, dir)),
|
|
146
|
+
siteDir,
|
|
147
|
+
isMDXPartial: (0, utils_1.createAbsoluteFilePathMatcher)(options.exclude, contentDirs),
|
|
148
|
+
metadataPath: (mdxPath) => {
|
|
149
|
+
// Note that metadataPath must be the same/in-sync as
|
|
150
|
+
// the path from createData for each MDX.
|
|
151
|
+
const aliasedPath = (0, utils_1.aliasedSitePath)(mdxPath, siteDir);
|
|
152
|
+
return path_1.default.join(dataDir, `${(0, utils_1.docuHash)(aliasedPath)}.json`);
|
|
153
|
+
},
|
|
154
|
+
// For blog posts a title in markdown is always removed
|
|
155
|
+
// Blog posts title are rendered separately
|
|
156
|
+
removeContentTitle: true,
|
|
157
|
+
// Assets allow to convert some relative images paths to
|
|
158
|
+
// require() calls
|
|
159
|
+
// @ts-expect-error: TODO fix typing issue
|
|
160
|
+
createAssets: ({ frontMatter, metadata, }) => ({
|
|
161
|
+
image: frontMatter.image,
|
|
162
|
+
authorsImageUrls: metadata.authors.map((author) => author.imageURL),
|
|
163
|
+
}),
|
|
164
|
+
markdownConfig: siteConfig.markdown,
|
|
165
|
+
resolveMarkdownLink: ({ linkPathname, sourceFilePath }) => {
|
|
166
|
+
const permalink = (0, utils_1.resolveMarkdownLinkPathname)(linkPathname, {
|
|
167
|
+
sourceFilePath,
|
|
168
|
+
sourceToPermalink,
|
|
169
|
+
siteDir,
|
|
170
|
+
contentPaths,
|
|
171
|
+
});
|
|
172
|
+
if (permalink === null) {
|
|
173
|
+
logger_1.default.report(onBrokenMarkdownLinks) `Blog markdown link couldn't be resolved: (url=${linkPathname}) in source file path=${sourceFilePath}`;
|
|
174
|
+
}
|
|
175
|
+
return permalink;
|
|
176
|
+
},
|
|
177
|
+
};
|
|
178
|
+
return {
|
|
179
|
+
loader: require.resolve('@docusaurus/mdx-loader'),
|
|
180
|
+
options: loaderOptions,
|
|
181
|
+
};
|
|
182
|
+
}
|
|
183
|
+
function createBlogMarkdownLoader() {
|
|
184
|
+
const loaderOptions = {
|
|
185
|
+
truncateMarker,
|
|
186
|
+
};
|
|
187
|
+
return {
|
|
188
|
+
loader: path_1.default.resolve(__dirname, './markdownLoader.js'),
|
|
189
|
+
options: loaderOptions,
|
|
190
|
+
};
|
|
191
|
+
}
|
|
146
192
|
return {
|
|
147
193
|
resolve: {
|
|
148
194
|
alias: {
|
|
@@ -156,44 +202,7 @@ async function pluginContentBlog(context, options) {
|
|
|
156
202
|
include: contentDirs
|
|
157
203
|
// Trailing slash is important, see https://github.com/facebook/docusaurus/pull/3970
|
|
158
204
|
.map(utils_1.addTrailingPathSeparator),
|
|
159
|
-
use: [
|
|
160
|
-
{
|
|
161
|
-
loader: require.resolve('@docusaurus/mdx-loader'),
|
|
162
|
-
options: {
|
|
163
|
-
admonitions,
|
|
164
|
-
remarkPlugins,
|
|
165
|
-
rehypePlugins,
|
|
166
|
-
beforeDefaultRemarkPlugins: [
|
|
167
|
-
footnoteIDFixer_1.default,
|
|
168
|
-
...beforeDefaultRemarkPlugins,
|
|
169
|
-
],
|
|
170
|
-
beforeDefaultRehypePlugins,
|
|
171
|
-
staticDirs: siteConfig.staticDirectories.map((dir) => path_1.default.resolve(siteDir, dir)),
|
|
172
|
-
siteDir,
|
|
173
|
-
isMDXPartial: (0, utils_1.createAbsoluteFilePathMatcher)(options.exclude, contentDirs),
|
|
174
|
-
metadataPath: (mdxPath) => {
|
|
175
|
-
// Note that metadataPath must be the same/in-sync as
|
|
176
|
-
// the path from createData for each MDX.
|
|
177
|
-
const aliasedPath = (0, utils_1.aliasedSitePath)(mdxPath, siteDir);
|
|
178
|
-
return path_1.default.join(dataDir, `${(0, utils_1.docuHash)(aliasedPath)}.json`);
|
|
179
|
-
},
|
|
180
|
-
// For blog posts a title in markdown is always removed
|
|
181
|
-
// Blog posts title are rendered separately
|
|
182
|
-
removeContentTitle: true,
|
|
183
|
-
// Assets allow to convert some relative images paths to
|
|
184
|
-
// require() calls
|
|
185
|
-
createAssets: ({ frontMatter, metadata, }) => ({
|
|
186
|
-
image: frontMatter.image,
|
|
187
|
-
authorsImageUrls: metadata.authors.map((author) => author.imageURL),
|
|
188
|
-
}),
|
|
189
|
-
markdownConfig: siteConfig.markdown,
|
|
190
|
-
},
|
|
191
|
-
},
|
|
192
|
-
{
|
|
193
|
-
loader: path_1.default.resolve(__dirname, './markdownLoader.js'),
|
|
194
|
-
options: markdownLoaderOptions,
|
|
195
|
-
},
|
|
196
|
-
].filter(Boolean),
|
|
205
|
+
use: [createMDXLoader(), createBlogMarkdownLoader()],
|
|
197
206
|
},
|
|
198
207
|
],
|
|
199
208
|
},
|
package/lib/markdownLoader.js
CHANGED
|
@@ -8,20 +8,16 @@
|
|
|
8
8
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
9
|
const blogUtils_1 = require("./blogUtils");
|
|
10
10
|
function markdownLoader(source) {
|
|
11
|
-
const filePath = this.resourcePath;
|
|
12
11
|
const fileString = source;
|
|
13
12
|
const callback = this.async();
|
|
14
13
|
const markdownLoaderOptions = this.getOptions();
|
|
15
14
|
// Linkify blog posts
|
|
16
|
-
let finalContent =
|
|
17
|
-
fileString,
|
|
18
|
-
filePath,
|
|
19
|
-
...markdownLoaderOptions,
|
|
20
|
-
});
|
|
15
|
+
let finalContent = fileString;
|
|
21
16
|
// Truncate content if requested (e.g: file.md?truncated=true).
|
|
22
17
|
const truncated = this.resourceQuery
|
|
23
18
|
? !!new URLSearchParams(this.resourceQuery.slice(1)).get('truncated')
|
|
24
19
|
: undefined;
|
|
20
|
+
// TODO truncate with the AST instead of the string ?
|
|
25
21
|
if (truncated) {
|
|
26
22
|
finalContent = (0, blogUtils_1.truncate)(finalContent, markdownLoaderOptions.truncateMarker);
|
|
27
23
|
}
|
package/lib/types.d.ts
CHANGED
|
@@ -4,15 +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 type {
|
|
7
|
+
import type { ContentPaths } from '@docusaurus/utils';
|
|
8
8
|
export type BlogContentPaths = ContentPaths;
|
|
9
|
-
export type BlogBrokenMarkdownLink = BrokenMarkdownLink<BlogContentPaths>;
|
|
10
9
|
export type BlogMarkdownLoaderOptions = {
|
|
11
|
-
siteDir: string;
|
|
12
|
-
contentPaths: BlogContentPaths;
|
|
13
10
|
truncateMarker: RegExp;
|
|
14
|
-
sourceToPermalink: {
|
|
15
|
-
[aliasedPath: string]: string;
|
|
16
|
-
};
|
|
17
|
-
onBrokenMarkdownLink: (brokenMarkdownLink: BlogBrokenMarkdownLink) => void;
|
|
18
11
|
};
|
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-5957",
|
|
4
4
|
"description": "Blog plugin for Docusaurus.",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"types": "src/plugin-content-blog.d.ts",
|
|
@@ -31,13 +31,13 @@
|
|
|
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/types": "0.0.0-
|
|
38
|
-
"@docusaurus/utils": "0.0.0-
|
|
39
|
-
"@docusaurus/utils-common": "0.0.0-
|
|
40
|
-
"@docusaurus/utils-validation": "0.0.0-
|
|
34
|
+
"@docusaurus/core": "0.0.0-5957",
|
|
35
|
+
"@docusaurus/logger": "0.0.0-5957",
|
|
36
|
+
"@docusaurus/mdx-loader": "0.0.0-5957",
|
|
37
|
+
"@docusaurus/types": "0.0.0-5957",
|
|
38
|
+
"@docusaurus/utils": "0.0.0-5957",
|
|
39
|
+
"@docusaurus/utils-common": "0.0.0-5957",
|
|
40
|
+
"@docusaurus/utils-validation": "0.0.0-5957",
|
|
41
41
|
"cheerio": "^1.0.0-rc.12",
|
|
42
42
|
"feed": "^4.2.2",
|
|
43
43
|
"fs-extra": "^11.1.1",
|
|
@@ -59,5 +59,5 @@
|
|
|
59
59
|
"devDependencies": {
|
|
60
60
|
"@total-typescript/shoehorn": "^0.1.2"
|
|
61
61
|
},
|
|
62
|
-
"gitHead": "
|
|
62
|
+
"gitHead": "edb3a453b0b3a853eadfc4e9ec44d47ea76d5002"
|
|
63
63
|
}
|
package/src/blogUtils.ts
CHANGED
|
@@ -17,7 +17,6 @@ import {
|
|
|
17
17
|
getEditUrl,
|
|
18
18
|
getFolderContainingFile,
|
|
19
19
|
posixPath,
|
|
20
|
-
replaceMarkdownLinks,
|
|
21
20
|
Globby,
|
|
22
21
|
normalizeFrontMatterTags,
|
|
23
22
|
groupTaggedItems,
|
|
@@ -38,7 +37,7 @@ import type {
|
|
|
38
37
|
BlogTags,
|
|
39
38
|
BlogPaginated,
|
|
40
39
|
} from '@docusaurus/plugin-content-blog';
|
|
41
|
-
import type {BlogContentPaths
|
|
40
|
+
import type {BlogContentPaths} from './types';
|
|
42
41
|
|
|
43
42
|
export function truncate(fileString: string, truncateMarker: RegExp): string {
|
|
44
43
|
return fileString.split(truncateMarker, 1).shift()!;
|
|
@@ -403,35 +402,6 @@ export async function generateBlogPosts(
|
|
|
403
402
|
return blogPosts;
|
|
404
403
|
}
|
|
405
404
|
|
|
406
|
-
export type LinkifyParams = {
|
|
407
|
-
filePath: string;
|
|
408
|
-
fileString: string;
|
|
409
|
-
} & Pick<
|
|
410
|
-
BlogMarkdownLoaderOptions,
|
|
411
|
-
'sourceToPermalink' | 'siteDir' | 'contentPaths' | 'onBrokenMarkdownLink'
|
|
412
|
-
>;
|
|
413
|
-
|
|
414
|
-
export function linkify({
|
|
415
|
-
filePath,
|
|
416
|
-
contentPaths,
|
|
417
|
-
fileString,
|
|
418
|
-
siteDir,
|
|
419
|
-
sourceToPermalink,
|
|
420
|
-
onBrokenMarkdownLink,
|
|
421
|
-
}: LinkifyParams): string {
|
|
422
|
-
const {newContent, brokenMarkdownLinks} = replaceMarkdownLinks({
|
|
423
|
-
siteDir,
|
|
424
|
-
fileString,
|
|
425
|
-
filePath,
|
|
426
|
-
contentPaths,
|
|
427
|
-
sourceToPermalink,
|
|
428
|
-
});
|
|
429
|
-
|
|
430
|
-
brokenMarkdownLinks.forEach((l) => onBrokenMarkdownLink(l));
|
|
431
|
-
|
|
432
|
-
return newContent;
|
|
433
|
-
}
|
|
434
|
-
|
|
435
405
|
export async function applyProcessBlogPosts({
|
|
436
406
|
blogPosts,
|
|
437
407
|
processBlogPosts,
|
package/src/index.ts
CHANGED
|
@@ -18,6 +18,7 @@ import {
|
|
|
18
18
|
getContentPathList,
|
|
19
19
|
getDataFilePath,
|
|
20
20
|
DEFAULT_PLUGIN_ID,
|
|
21
|
+
resolveMarkdownLinkPathname,
|
|
21
22
|
} from '@docusaurus/utils';
|
|
22
23
|
import {
|
|
23
24
|
getSourceToPermalink,
|
|
@@ -43,6 +44,8 @@ import type {
|
|
|
43
44
|
BlogContent,
|
|
44
45
|
BlogPaginated,
|
|
45
46
|
} from '@docusaurus/plugin-content-blog';
|
|
47
|
+
import type {Options as MDXLoaderOptions} from '@docusaurus/mdx-loader/lib/loader';
|
|
48
|
+
import type {RuleSetUseItem} from 'webpack';
|
|
46
49
|
|
|
47
50
|
const PluginName = 'docusaurus-plugin-content-blog';
|
|
48
51
|
|
|
@@ -213,22 +216,81 @@ export default async function pluginContentBlog(
|
|
|
213
216
|
beforeDefaultRehypePlugins,
|
|
214
217
|
} = options;
|
|
215
218
|
|
|
216
|
-
const
|
|
217
|
-
siteDir,
|
|
218
|
-
contentPaths,
|
|
219
|
-
truncateMarker,
|
|
220
|
-
sourceToPermalink: getSourceToPermalink(content.blogPosts),
|
|
221
|
-
onBrokenMarkdownLink: (brokenMarkdownLink) => {
|
|
222
|
-
if (onBrokenMarkdownLinks === 'ignore') {
|
|
223
|
-
return;
|
|
224
|
-
}
|
|
225
|
-
logger.report(
|
|
226
|
-
onBrokenMarkdownLinks,
|
|
227
|
-
)`Blog markdown link couldn't be resolved: (url=${brokenMarkdownLink.link}) in path=${brokenMarkdownLink.filePath}`;
|
|
228
|
-
},
|
|
229
|
-
};
|
|
230
|
-
|
|
219
|
+
const sourceToPermalink = getSourceToPermalink(content.blogPosts);
|
|
231
220
|
const contentDirs = getContentPathList(contentPaths);
|
|
221
|
+
|
|
222
|
+
function createMDXLoader(): RuleSetUseItem {
|
|
223
|
+
const loaderOptions: MDXLoaderOptions = {
|
|
224
|
+
admonitions,
|
|
225
|
+
remarkPlugins,
|
|
226
|
+
rehypePlugins,
|
|
227
|
+
beforeDefaultRemarkPlugins: [
|
|
228
|
+
footnoteIDFixer,
|
|
229
|
+
...beforeDefaultRemarkPlugins,
|
|
230
|
+
],
|
|
231
|
+
beforeDefaultRehypePlugins,
|
|
232
|
+
staticDirs: siteConfig.staticDirectories.map((dir) =>
|
|
233
|
+
path.resolve(siteDir, dir),
|
|
234
|
+
),
|
|
235
|
+
siteDir,
|
|
236
|
+
isMDXPartial: createAbsoluteFilePathMatcher(
|
|
237
|
+
options.exclude,
|
|
238
|
+
contentDirs,
|
|
239
|
+
),
|
|
240
|
+
metadataPath: (mdxPath: string) => {
|
|
241
|
+
// Note that metadataPath must be the same/in-sync as
|
|
242
|
+
// the path from createData for each MDX.
|
|
243
|
+
const aliasedPath = aliasedSitePath(mdxPath, siteDir);
|
|
244
|
+
return path.join(dataDir, `${docuHash(aliasedPath)}.json`);
|
|
245
|
+
},
|
|
246
|
+
// For blog posts a title in markdown is always removed
|
|
247
|
+
// Blog posts title are rendered separately
|
|
248
|
+
removeContentTitle: true,
|
|
249
|
+
// Assets allow to convert some relative images paths to
|
|
250
|
+
// require() calls
|
|
251
|
+
// @ts-expect-error: TODO fix typing issue
|
|
252
|
+
createAssets: ({
|
|
253
|
+
frontMatter,
|
|
254
|
+
metadata,
|
|
255
|
+
}: {
|
|
256
|
+
frontMatter: BlogPostFrontMatter;
|
|
257
|
+
metadata: BlogPostMetadata;
|
|
258
|
+
}): Assets => ({
|
|
259
|
+
image: frontMatter.image,
|
|
260
|
+
authorsImageUrls: metadata.authors.map((author) => author.imageURL),
|
|
261
|
+
}),
|
|
262
|
+
markdownConfig: siteConfig.markdown,
|
|
263
|
+
resolveMarkdownLink: ({linkPathname, sourceFilePath}) => {
|
|
264
|
+
const permalink = resolveMarkdownLinkPathname(linkPathname, {
|
|
265
|
+
sourceFilePath,
|
|
266
|
+
sourceToPermalink,
|
|
267
|
+
siteDir,
|
|
268
|
+
contentPaths,
|
|
269
|
+
});
|
|
270
|
+
if (permalink === null) {
|
|
271
|
+
logger.report(
|
|
272
|
+
onBrokenMarkdownLinks,
|
|
273
|
+
)`Blog markdown link couldn't be resolved: (url=${linkPathname}) in source file path=${sourceFilePath}`;
|
|
274
|
+
}
|
|
275
|
+
return permalink;
|
|
276
|
+
},
|
|
277
|
+
};
|
|
278
|
+
return {
|
|
279
|
+
loader: require.resolve('@docusaurus/mdx-loader'),
|
|
280
|
+
options: loaderOptions,
|
|
281
|
+
};
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
function createBlogMarkdownLoader(): RuleSetUseItem {
|
|
285
|
+
const loaderOptions: BlogMarkdownLoaderOptions = {
|
|
286
|
+
truncateMarker,
|
|
287
|
+
};
|
|
288
|
+
return {
|
|
289
|
+
loader: path.resolve(__dirname, './markdownLoader.js'),
|
|
290
|
+
options: loaderOptions,
|
|
291
|
+
};
|
|
292
|
+
}
|
|
293
|
+
|
|
232
294
|
return {
|
|
233
295
|
resolve: {
|
|
234
296
|
alias: {
|
|
@@ -242,61 +304,7 @@ export default async function pluginContentBlog(
|
|
|
242
304
|
include: contentDirs
|
|
243
305
|
// Trailing slash is important, see https://github.com/facebook/docusaurus/pull/3970
|
|
244
306
|
.map(addTrailingPathSeparator),
|
|
245
|
-
use: [
|
|
246
|
-
{
|
|
247
|
-
loader: require.resolve('@docusaurus/mdx-loader'),
|
|
248
|
-
options: {
|
|
249
|
-
admonitions,
|
|
250
|
-
remarkPlugins,
|
|
251
|
-
rehypePlugins,
|
|
252
|
-
beforeDefaultRemarkPlugins: [
|
|
253
|
-
footnoteIDFixer,
|
|
254
|
-
...beforeDefaultRemarkPlugins,
|
|
255
|
-
],
|
|
256
|
-
beforeDefaultRehypePlugins,
|
|
257
|
-
staticDirs: siteConfig.staticDirectories.map((dir) =>
|
|
258
|
-
path.resolve(siteDir, dir),
|
|
259
|
-
),
|
|
260
|
-
siteDir,
|
|
261
|
-
isMDXPartial: createAbsoluteFilePathMatcher(
|
|
262
|
-
options.exclude,
|
|
263
|
-
contentDirs,
|
|
264
|
-
),
|
|
265
|
-
metadataPath: (mdxPath: string) => {
|
|
266
|
-
// Note that metadataPath must be the same/in-sync as
|
|
267
|
-
// the path from createData for each MDX.
|
|
268
|
-
const aliasedPath = aliasedSitePath(mdxPath, siteDir);
|
|
269
|
-
return path.join(
|
|
270
|
-
dataDir,
|
|
271
|
-
`${docuHash(aliasedPath)}.json`,
|
|
272
|
-
);
|
|
273
|
-
},
|
|
274
|
-
// For blog posts a title in markdown is always removed
|
|
275
|
-
// Blog posts title are rendered separately
|
|
276
|
-
removeContentTitle: true,
|
|
277
|
-
|
|
278
|
-
// Assets allow to convert some relative images paths to
|
|
279
|
-
// require() calls
|
|
280
|
-
createAssets: ({
|
|
281
|
-
frontMatter,
|
|
282
|
-
metadata,
|
|
283
|
-
}: {
|
|
284
|
-
frontMatter: BlogPostFrontMatter;
|
|
285
|
-
metadata: BlogPostMetadata;
|
|
286
|
-
}): Assets => ({
|
|
287
|
-
image: frontMatter.image,
|
|
288
|
-
authorsImageUrls: metadata.authors.map(
|
|
289
|
-
(author) => author.imageURL,
|
|
290
|
-
),
|
|
291
|
-
}),
|
|
292
|
-
markdownConfig: siteConfig.markdown,
|
|
293
|
-
},
|
|
294
|
-
},
|
|
295
|
-
{
|
|
296
|
-
loader: path.resolve(__dirname, './markdownLoader.js'),
|
|
297
|
-
options: markdownLoaderOptions,
|
|
298
|
-
},
|
|
299
|
-
].filter(Boolean),
|
|
307
|
+
use: [createMDXLoader(), createBlogMarkdownLoader()],
|
|
300
308
|
},
|
|
301
309
|
],
|
|
302
310
|
},
|
package/src/markdownLoader.ts
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
|
-
import {truncate
|
|
8
|
+
import {truncate} from './blogUtils';
|
|
9
9
|
import type {BlogMarkdownLoaderOptions} from './types';
|
|
10
10
|
import type {LoaderContext} from 'webpack';
|
|
11
11
|
|
|
@@ -13,23 +13,19 @@ export default function markdownLoader(
|
|
|
13
13
|
this: LoaderContext<BlogMarkdownLoaderOptions>,
|
|
14
14
|
source: string,
|
|
15
15
|
): void {
|
|
16
|
-
const filePath = this.resourcePath;
|
|
17
16
|
const fileString = source;
|
|
18
17
|
const callback = this.async();
|
|
19
18
|
const markdownLoaderOptions = this.getOptions();
|
|
20
19
|
|
|
21
20
|
// Linkify blog posts
|
|
22
|
-
let finalContent =
|
|
23
|
-
fileString,
|
|
24
|
-
filePath,
|
|
25
|
-
...markdownLoaderOptions,
|
|
26
|
-
});
|
|
21
|
+
let finalContent = fileString;
|
|
27
22
|
|
|
28
23
|
// Truncate content if requested (e.g: file.md?truncated=true).
|
|
29
24
|
const truncated: boolean | undefined = this.resourceQuery
|
|
30
25
|
? !!new URLSearchParams(this.resourceQuery.slice(1)).get('truncated')
|
|
31
26
|
: undefined;
|
|
32
27
|
|
|
28
|
+
// TODO truncate with the AST instead of the string ?
|
|
33
29
|
if (truncated) {
|
|
34
30
|
finalContent = truncate(finalContent, markdownLoaderOptions.truncateMarker);
|
|
35
31
|
}
|
package/src/types.ts
CHANGED
|
@@ -5,15 +5,10 @@
|
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
|
-
import type {
|
|
8
|
+
import type {ContentPaths} from '@docusaurus/utils';
|
|
9
9
|
|
|
10
10
|
export type BlogContentPaths = ContentPaths;
|
|
11
11
|
|
|
12
|
-
export type BlogBrokenMarkdownLink = BrokenMarkdownLink<BlogContentPaths>;
|
|
13
12
|
export type BlogMarkdownLoaderOptions = {
|
|
14
|
-
siteDir: string;
|
|
15
|
-
contentPaths: BlogContentPaths;
|
|
16
13
|
truncateMarker: RegExp;
|
|
17
|
-
sourceToPermalink: {[aliasedPath: string]: string};
|
|
18
|
-
onBrokenMarkdownLink: (brokenMarkdownLink: BlogBrokenMarkdownLink) => void;
|
|
19
14
|
};
|