@docusaurus/plugin-content-blog 0.0.0-4892 → 0.0.0-4895
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/index.js +5 -1
- package/lib/remark/footnoteIDFixer.d.ts +14 -0
- package/lib/remark/footnoteIDFixer.js +29 -0
- package/package.json +10 -9
- package/src/index.ts +5 -1
- package/src/remark/footnoteIDFixer.ts +29 -0
package/lib/index.js
CHANGED
|
@@ -10,6 +10,7 @@ exports.validateOptions = void 0;
|
|
|
10
10
|
const tslib_1 = require("tslib");
|
|
11
11
|
const path_1 = tslib_1.__importDefault(require("path"));
|
|
12
12
|
const remark_admonitions_1 = tslib_1.__importDefault(require("remark-admonitions"));
|
|
13
|
+
const footnoteIDFixer_1 = tslib_1.__importDefault(require("./remark/footnoteIDFixer"));
|
|
13
14
|
const utils_1 = require("@docusaurus/utils");
|
|
14
15
|
const translations_1 = require("./translations");
|
|
15
16
|
const blogUtils_1 = require("./blogUtils");
|
|
@@ -281,7 +282,10 @@ async function pluginContentBlog(context, options) {
|
|
|
281
282
|
options: {
|
|
282
283
|
remarkPlugins,
|
|
283
284
|
rehypePlugins,
|
|
284
|
-
beforeDefaultRemarkPlugins
|
|
285
|
+
beforeDefaultRemarkPlugins: [
|
|
286
|
+
footnoteIDFixer_1.default,
|
|
287
|
+
...beforeDefaultRemarkPlugins,
|
|
288
|
+
],
|
|
285
289
|
beforeDefaultRehypePlugins,
|
|
286
290
|
staticDirs: siteConfig.staticDirectories.map((dir) => path_1.default.resolve(siteDir, dir)),
|
|
287
291
|
siteDir,
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*/
|
|
7
|
+
import type { Transformer } from 'unified';
|
|
8
|
+
/**
|
|
9
|
+
* In the blog list view, each post will be compiled separately. However, they
|
|
10
|
+
* may use the same footnote IDs. This leads to duplicated DOM IDs and inability
|
|
11
|
+
* to navigate to footnote references. This plugin fixes it by appending a
|
|
12
|
+
* unique hash to each reference/definition.
|
|
13
|
+
*/
|
|
14
|
+
export default function plugin(): Transformer;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
4
|
+
*
|
|
5
|
+
* This source code is licensed under the MIT license found in the
|
|
6
|
+
* LICENSE file in the root directory of this source tree.
|
|
7
|
+
*/
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
const tslib_1 = require("tslib");
|
|
10
|
+
const unist_util_visit_1 = tslib_1.__importDefault(require("unist-util-visit"));
|
|
11
|
+
const utils_1 = require("@docusaurus/utils");
|
|
12
|
+
/**
|
|
13
|
+
* In the blog list view, each post will be compiled separately. However, they
|
|
14
|
+
* may use the same footnote IDs. This leads to duplicated DOM IDs and inability
|
|
15
|
+
* to navigate to footnote references. This plugin fixes it by appending a
|
|
16
|
+
* unique hash to each reference/definition.
|
|
17
|
+
*/
|
|
18
|
+
function plugin() {
|
|
19
|
+
return (root, vfile) => {
|
|
20
|
+
const suffix = `-${(0, utils_1.simpleHash)(vfile.path, 6)}`;
|
|
21
|
+
(0, unist_util_visit_1.default)(root, 'footnoteReference', (node) => {
|
|
22
|
+
node.identifier += suffix;
|
|
23
|
+
});
|
|
24
|
+
(0, unist_util_visit_1.default)(root, 'footnoteDefinition', (node) => {
|
|
25
|
+
node.identifier += suffix;
|
|
26
|
+
});
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
exports.default = plugin;
|
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-4895",
|
|
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-4895",
|
|
22
|
+
"@docusaurus/logger": "0.0.0-4895",
|
|
23
|
+
"@docusaurus/mdx-loader": "0.0.0-4895",
|
|
24
|
+
"@docusaurus/utils": "0.0.0-4895",
|
|
25
|
+
"@docusaurus/utils-common": "0.0.0-4895",
|
|
26
|
+
"@docusaurus/utils-validation": "0.0.0-4895",
|
|
27
27
|
"cheerio": "^1.0.0-rc.10",
|
|
28
28
|
"feed": "^4.2.2",
|
|
29
29
|
"fs-extra": "^10.1.0",
|
|
@@ -31,11 +31,12 @@
|
|
|
31
31
|
"reading-time": "^1.5.0",
|
|
32
32
|
"remark-admonitions": "^1.2.1",
|
|
33
33
|
"tslib": "^2.3.1",
|
|
34
|
+
"unist-util-visit": "^2.0.3",
|
|
34
35
|
"utility-types": "^3.10.0",
|
|
35
36
|
"webpack": "^5.72.0"
|
|
36
37
|
},
|
|
37
38
|
"devDependencies": {
|
|
38
|
-
"@docusaurus/types": "0.0.0-
|
|
39
|
+
"@docusaurus/types": "0.0.0-4895",
|
|
39
40
|
"escape-string-regexp": "^4.0.0"
|
|
40
41
|
},
|
|
41
42
|
"peerDependencies": {
|
|
@@ -45,5 +46,5 @@
|
|
|
45
46
|
"engines": {
|
|
46
47
|
"node": ">=14"
|
|
47
48
|
},
|
|
48
|
-
"gitHead": "
|
|
49
|
+
"gitHead": "8845bdf725b98ed6da91b2270a8a3d268bce3fa4"
|
|
49
50
|
}
|
package/src/index.ts
CHANGED
|
@@ -7,6 +7,7 @@
|
|
|
7
7
|
|
|
8
8
|
import path from 'path';
|
|
9
9
|
import admonitions from 'remark-admonitions';
|
|
10
|
+
import footnoteIDFixer from './remark/footnoteIDFixer';
|
|
10
11
|
import {
|
|
11
12
|
normalizeUrl,
|
|
12
13
|
docuHash,
|
|
@@ -435,7 +436,10 @@ export default async function pluginContentBlog(
|
|
|
435
436
|
options: {
|
|
436
437
|
remarkPlugins,
|
|
437
438
|
rehypePlugins,
|
|
438
|
-
beforeDefaultRemarkPlugins
|
|
439
|
+
beforeDefaultRemarkPlugins: [
|
|
440
|
+
footnoteIDFixer,
|
|
441
|
+
...beforeDefaultRemarkPlugins,
|
|
442
|
+
],
|
|
439
443
|
beforeDefaultRehypePlugins,
|
|
440
444
|
staticDirs: siteConfig.staticDirectories.map((dir) =>
|
|
441
445
|
path.resolve(siteDir, dir),
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import visit from 'unist-util-visit';
|
|
9
|
+
import {simpleHash} from '@docusaurus/utils';
|
|
10
|
+
import type {Transformer} from 'unified';
|
|
11
|
+
import type {FootnoteReference, FootnoteDefinition} from 'mdast';
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* In the blog list view, each post will be compiled separately. However, they
|
|
15
|
+
* may use the same footnote IDs. This leads to duplicated DOM IDs and inability
|
|
16
|
+
* to navigate to footnote references. This plugin fixes it by appending a
|
|
17
|
+
* unique hash to each reference/definition.
|
|
18
|
+
*/
|
|
19
|
+
export default function plugin(): Transformer {
|
|
20
|
+
return (root, vfile) => {
|
|
21
|
+
const suffix = `-${simpleHash(vfile.path!, 6)}`;
|
|
22
|
+
visit(root, 'footnoteReference', (node: FootnoteReference) => {
|
|
23
|
+
node.identifier += suffix;
|
|
24
|
+
});
|
|
25
|
+
visit(root, 'footnoteDefinition', (node: FootnoteDefinition) => {
|
|
26
|
+
node.identifier += suffix;
|
|
27
|
+
});
|
|
28
|
+
};
|
|
29
|
+
}
|