eleventy-plugin-asciidoc 3.1.0 → 3.1.2
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/README.md +14 -4
- package/lib/eleventy-asciidoc.js +50 -9
- package/lib/utils.js +25 -0
- package/package.json +16 -14
package/README.md
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
# eleventy-plugin-asciidoc
|
|
2
2
|
|
|
3
|
-
Eleventy plugin to add support for [AsciiDoc](https://asciidoc.org/).
|
|
3
|
+
Eleventy plugin to add support for [AsciiDoc](https://asciidoc.org/).
|
|
4
|
+
You don't need to use to shortcodes.
|
|
5
|
+
You can directly use AsciiDoc files (`.adoc`), just like Markdown (`.md`).
|
|
4
6
|
|
|
5
7
|
The plugin uses [Asciidoctor.js](https://docs.asciidoctor.org/asciidoctor.js) under the hood.
|
|
6
8
|
|
|
@@ -35,7 +37,8 @@ module.exports = function (eleventyConfig) {
|
|
|
35
37
|
|
|
36
38
|
### Customize with Options
|
|
37
39
|
|
|
38
|
-
You can pass options to `convert()` of Asciidoctor.js as second argument in `addPlugin()`.
|
|
40
|
+
You can pass options to `convert()` of Asciidoctor.js as second argument in `addPlugin()`.
|
|
41
|
+
These are the [available options](https://docs.asciidoctor.org/asciidoctor.js/latest/processor/convert-options/).
|
|
39
42
|
|
|
40
43
|
```js
|
|
41
44
|
const eleventyAsciidoc = require("eleventy-plugin-asciidoc");
|
|
@@ -52,7 +55,13 @@ module.exports = function (eleventyConfig) {
|
|
|
52
55
|
|
|
53
56
|
#### `base_dir`
|
|
54
57
|
|
|
55
|
-
The `base_dir` of [convert options](https://docs.asciidoctor.org/asciidoctor.js/latest/processor/convert-options/) is relative to the document.
|
|
58
|
+
The `base_dir` of [convert options](https://docs.asciidoctor.org/asciidoctor.js/latest/processor/convert-options/) is relative to the document.
|
|
59
|
+
This can be changed using the above [options](#customize-with-options).
|
|
60
|
+
|
|
61
|
+
#### `attributes.outdir`
|
|
62
|
+
|
|
63
|
+
By default, [`attributes.outdir`](https://docs.asciidoctor.org/asciidoc/latest/attributes/document-attributes-ref/#intrinsic-attributes) will be the path to the output directory (`permalink`) of the document.
|
|
64
|
+
This can be changed using the above [options](#customize-with-options).
|
|
56
65
|
|
|
57
66
|
#### `extension_registry` (⚠️ deprecated)
|
|
58
67
|
|
|
@@ -87,7 +96,8 @@ Refer to [Asciidoctor.js documentation](https://docs.asciidoctor.org/asciidoctor
|
|
|
87
96
|
|
|
88
97
|
The plugin does not include any CSS styles. It is up to you to style the content.
|
|
89
98
|
|
|
90
|
-
The
|
|
99
|
+
The quickest way to style the content is to use the CSS file from Asciidoctor.js.
|
|
100
|
+
The CSS file is [available on cdnjs](https://cdnjs.com/libraries/asciidoctor.js).
|
|
91
101
|
|
|
92
102
|
## Enhancements
|
|
93
103
|
|
package/lib/eleventy-asciidoc.js
CHANGED
|
@@ -7,6 +7,7 @@ const fs = require("fs");
|
|
|
7
7
|
const matter = require("gray-matter");
|
|
8
8
|
const path = require("path");
|
|
9
9
|
const nunjucks = require("nunjucks");
|
|
10
|
+
const { parseDocumentAttributes } = require("./utils.js");
|
|
10
11
|
|
|
11
12
|
// @ts-ignore
|
|
12
13
|
const processor = asciidoctor();
|
|
@@ -18,21 +19,28 @@ const processor = asciidoctor();
|
|
|
18
19
|
* Reads a file synchronously.
|
|
19
20
|
*
|
|
20
21
|
* @param {string} inputPath The input path
|
|
21
|
-
* @return {GrayMatterFile}
|
|
22
|
+
* @return {GrayMatterFile}
|
|
22
23
|
*/
|
|
23
24
|
const readFileSync = (inputPath) => {
|
|
24
25
|
return matter(fs.readFileSync(inputPath, "utf8"));
|
|
25
26
|
};
|
|
26
27
|
|
|
27
|
-
/**
|
|
28
|
+
/** @typedef {(inputPath: string) => Object.<string, any>} GetDataFn
|
|
28
29
|
* Gets front-matter data from the file synchronously
|
|
30
|
+
*/
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Creates getData function with options initialised.
|
|
29
34
|
*
|
|
30
|
-
* @param {
|
|
31
|
-
* @return {
|
|
35
|
+
* @param {ProcessorOptions} converterOptions The converter options
|
|
36
|
+
* @return {GetDataFn}
|
|
32
37
|
*/
|
|
33
|
-
const
|
|
38
|
+
const generateGetData = (converterOptions) => (inputPath) => {
|
|
34
39
|
const { data, content } = readFileSync(inputPath);
|
|
35
|
-
const doc = processor.load(content
|
|
40
|
+
const doc = processor.load(content, {
|
|
41
|
+
...converterOptions,
|
|
42
|
+
base_dir: getBaseDir(inputPath, converterOptions.base_dir),
|
|
43
|
+
});
|
|
36
44
|
const attributes = doc.getAttributes();
|
|
37
45
|
const title = doc.getDocumentTitle();
|
|
38
46
|
debug(`Document title ${title}`);
|
|
@@ -45,6 +53,17 @@ const getData = (inputPath) => {
|
|
|
45
53
|
};
|
|
46
54
|
};
|
|
47
55
|
|
|
56
|
+
/**
|
|
57
|
+
* Gets the base directory if available, otherwise from input path
|
|
58
|
+
*
|
|
59
|
+
* @param {string} inputPath The input path
|
|
60
|
+
* @param {string=} base_dir The base directory
|
|
61
|
+
* @return {string} The base dir.
|
|
62
|
+
*/
|
|
63
|
+
function getBaseDir(inputPath, base_dir) {
|
|
64
|
+
return base_dir === undefined ? path.dirname(inputPath) : base_dir;
|
|
65
|
+
}
|
|
66
|
+
|
|
48
67
|
/**
|
|
49
68
|
* Generates Eleventy template renderer for AsciiDoctor
|
|
50
69
|
*
|
|
@@ -71,11 +90,32 @@ function eleventyAsciidoctor(convertOptions = {}) {
|
|
|
71
90
|
const { content } = readFileSync(inputPath);
|
|
72
91
|
|
|
73
92
|
let { base_dir, configure_extension_registry } = options;
|
|
74
|
-
|
|
93
|
+
const attributes = parseDocumentAttributes(options.attributes ?? {});
|
|
94
|
+
let { outdir } = attributes;
|
|
95
|
+
|
|
96
|
+
base_dir = getBaseDir(inputPath, base_dir);
|
|
97
|
+
|
|
98
|
+
if (outdir === undefined) {
|
|
99
|
+
const { page } = data ?? {};
|
|
100
|
+
const { outputPath } = page ?? {};
|
|
101
|
+
if (outputPath !== undefined) {
|
|
102
|
+
outdir = path.dirname(outputPath);
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
const converterOptions = {
|
|
107
|
+
...options,
|
|
108
|
+
attributes: {
|
|
109
|
+
...attributes,
|
|
110
|
+
outdir,
|
|
111
|
+
},
|
|
112
|
+
base_dir,
|
|
113
|
+
};
|
|
75
114
|
|
|
76
115
|
if (content) {
|
|
77
116
|
debug(`Converting:\n ${content}`);
|
|
78
117
|
debug(`base_dir: ${base_dir}`);
|
|
118
|
+
debug(`attributes:\n ${JSON.stringify(attributes)}`);
|
|
79
119
|
|
|
80
120
|
let registry;
|
|
81
121
|
if (typeof configure_extension_registry === "function") {
|
|
@@ -85,13 +125,14 @@ function eleventyAsciidoctor(convertOptions = {}) {
|
|
|
85
125
|
}
|
|
86
126
|
|
|
87
127
|
return processor.convert(content, {
|
|
88
|
-
...
|
|
89
|
-
base_dir,
|
|
128
|
+
...converterOptions,
|
|
90
129
|
extension_registry: registry,
|
|
91
130
|
});
|
|
92
131
|
}
|
|
93
132
|
};
|
|
94
133
|
|
|
134
|
+
const getData = generateGetData(options);
|
|
135
|
+
|
|
95
136
|
return {
|
|
96
137
|
read: false,
|
|
97
138
|
getData,
|
package/lib/utils.js
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
// @ts-check
|
|
2
|
+
|
|
3
|
+
/** @typedef {import('@asciidoctor/core').Attributes} Attributes */
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Parses AsciiDoc Document attributes into object
|
|
7
|
+
*
|
|
8
|
+
* @param {Attributes | string[] | string} attrs AsciiDoc Document Attributes
|
|
9
|
+
* @return {Attributes} Attributes as Object
|
|
10
|
+
*/
|
|
11
|
+
function parseDocumentAttributes(attrs) {
|
|
12
|
+
if (Array.isArray(attrs)) {
|
|
13
|
+
return Object.fromEntries(attrs.map((a) => a.split("=")));
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
if (typeof attrs === "string") {
|
|
17
|
+
return Object.fromEntries([attrs.split("=")]);
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
return attrs;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
module.exports = {
|
|
24
|
+
parseDocumentAttributes,
|
|
25
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "eleventy-plugin-asciidoc",
|
|
3
|
-
"version": "3.1.
|
|
3
|
+
"version": "3.1.2",
|
|
4
4
|
"description": "Adds support for AsciiDoc to Eleventy",
|
|
5
5
|
"main": ".eleventy.js",
|
|
6
6
|
"repository": {
|
|
@@ -25,23 +25,23 @@
|
|
|
25
25
|
"compatibility": ">=1.0.0"
|
|
26
26
|
},
|
|
27
27
|
"dependencies": {
|
|
28
|
-
"@asciidoctor/core": "^3.0.
|
|
28
|
+
"@asciidoctor/core": "^3.0.4",
|
|
29
29
|
"debug": "^4.3.4",
|
|
30
30
|
"gray-matter": "^4.0.3",
|
|
31
31
|
"nunjucks": "^3.2.4"
|
|
32
32
|
},
|
|
33
33
|
"devDependencies": {
|
|
34
34
|
"@11ty/eleventy": "^2.0.1",
|
|
35
|
-
"ava": "^
|
|
36
|
-
"eslint": "^8.
|
|
37
|
-
"eslint-config-prettier": "^
|
|
38
|
-
"eslint-config-xo-space": "^0.
|
|
39
|
-
"eslint-plugin-prettier": "^5.
|
|
40
|
-
"husky": "^
|
|
41
|
-
"lint-staged": "^
|
|
35
|
+
"ava": "^6.1.1",
|
|
36
|
+
"eslint": "^8.56.0",
|
|
37
|
+
"eslint-config-prettier": "^9.1.0",
|
|
38
|
+
"eslint-config-xo-space": "^0.35.0",
|
|
39
|
+
"eslint-plugin-prettier": "^5.1.3",
|
|
40
|
+
"husky": "^9.0.11",
|
|
41
|
+
"lint-staged": "^15.2.2",
|
|
42
42
|
"nyc": "^15.1.0",
|
|
43
|
-
"prettier": "^3.
|
|
44
|
-
"rimraf": "^5.0.
|
|
43
|
+
"prettier": "^3.2.5",
|
|
44
|
+
"rimraf": "^5.0.5"
|
|
45
45
|
},
|
|
46
46
|
"lint-staged": {
|
|
47
47
|
"*.js": "eslint --cache --fix --ignore-pattern \"!.eleventy.js\"",
|
|
@@ -53,8 +53,10 @@
|
|
|
53
53
|
"!tests/fixtures/",
|
|
54
54
|
"!tests/utils.js"
|
|
55
55
|
],
|
|
56
|
-
"
|
|
57
|
-
"
|
|
58
|
-
|
|
56
|
+
"watchMode": {
|
|
57
|
+
"ignoreChanges": [
|
|
58
|
+
"tests/output/**"
|
|
59
|
+
]
|
|
60
|
+
}
|
|
59
61
|
}
|
|
60
62
|
}
|