eleventy-plugin-asciidoc 3.1.1 → 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 +3 -3
- package/lib/eleventy-asciidoc.js +37 -13
- package/package.json +16 -14
package/README.md
CHANGED
|
@@ -56,12 +56,12 @@ module.exports = function (eleventyConfig) {
|
|
|
56
56
|
#### `base_dir`
|
|
57
57
|
|
|
58
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 above [options](#customize-with-options).
|
|
59
|
+
This can be changed using the above [options](#customize-with-options).
|
|
60
60
|
|
|
61
61
|
#### `attributes.outdir`
|
|
62
62
|
|
|
63
|
-
By default, [`attributes.outdir`](https://docs.asciidoctor.org/asciidoc/latest/attributes/document-attributes-ref/#intrinsic-attributes) will output directory (`permalink`) of the document.
|
|
64
|
-
This can be changed using above [options](#customize-with-options).
|
|
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).
|
|
65
65
|
|
|
66
66
|
#### `extension_registry` (⚠️ deprecated)
|
|
67
67
|
|
package/lib/eleventy-asciidoc.js
CHANGED
|
@@ -19,21 +19,28 @@ const processor = asciidoctor();
|
|
|
19
19
|
* Reads a file synchronously.
|
|
20
20
|
*
|
|
21
21
|
* @param {string} inputPath The input path
|
|
22
|
-
* @return {GrayMatterFile}
|
|
22
|
+
* @return {GrayMatterFile}
|
|
23
23
|
*/
|
|
24
24
|
const readFileSync = (inputPath) => {
|
|
25
25
|
return matter(fs.readFileSync(inputPath, "utf8"));
|
|
26
26
|
};
|
|
27
27
|
|
|
28
|
-
/**
|
|
28
|
+
/** @typedef {(inputPath: string) => Object.<string, any>} GetDataFn
|
|
29
29
|
* Gets front-matter data from the file synchronously
|
|
30
|
+
*/
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Creates getData function with options initialised.
|
|
30
34
|
*
|
|
31
|
-
* @param {
|
|
32
|
-
* @return {
|
|
35
|
+
* @param {ProcessorOptions} converterOptions The converter options
|
|
36
|
+
* @return {GetDataFn}
|
|
33
37
|
*/
|
|
34
|
-
const
|
|
38
|
+
const generateGetData = (converterOptions) => (inputPath) => {
|
|
35
39
|
const { data, content } = readFileSync(inputPath);
|
|
36
|
-
const doc = processor.load(content
|
|
40
|
+
const doc = processor.load(content, {
|
|
41
|
+
...converterOptions,
|
|
42
|
+
base_dir: getBaseDir(inputPath, converterOptions.base_dir),
|
|
43
|
+
});
|
|
37
44
|
const attributes = doc.getAttributes();
|
|
38
45
|
const title = doc.getDocumentTitle();
|
|
39
46
|
debug(`Document title ${title}`);
|
|
@@ -46,6 +53,17 @@ const getData = (inputPath) => {
|
|
|
46
53
|
};
|
|
47
54
|
};
|
|
48
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
|
+
|
|
49
67
|
/**
|
|
50
68
|
* Generates Eleventy template renderer for AsciiDoctor
|
|
51
69
|
*
|
|
@@ -75,7 +93,7 @@ function eleventyAsciidoctor(convertOptions = {}) {
|
|
|
75
93
|
const attributes = parseDocumentAttributes(options.attributes ?? {});
|
|
76
94
|
let { outdir } = attributes;
|
|
77
95
|
|
|
78
|
-
base_dir =
|
|
96
|
+
base_dir = getBaseDir(inputPath, base_dir);
|
|
79
97
|
|
|
80
98
|
if (outdir === undefined) {
|
|
81
99
|
const { page } = data ?? {};
|
|
@@ -85,6 +103,15 @@ function eleventyAsciidoctor(convertOptions = {}) {
|
|
|
85
103
|
}
|
|
86
104
|
}
|
|
87
105
|
|
|
106
|
+
const converterOptions = {
|
|
107
|
+
...options,
|
|
108
|
+
attributes: {
|
|
109
|
+
...attributes,
|
|
110
|
+
outdir,
|
|
111
|
+
},
|
|
112
|
+
base_dir,
|
|
113
|
+
};
|
|
114
|
+
|
|
88
115
|
if (content) {
|
|
89
116
|
debug(`Converting:\n ${content}`);
|
|
90
117
|
debug(`base_dir: ${base_dir}`);
|
|
@@ -98,17 +125,14 @@ function eleventyAsciidoctor(convertOptions = {}) {
|
|
|
98
125
|
}
|
|
99
126
|
|
|
100
127
|
return processor.convert(content, {
|
|
101
|
-
...
|
|
102
|
-
attributes: {
|
|
103
|
-
...attributes,
|
|
104
|
-
outdir,
|
|
105
|
-
},
|
|
106
|
-
base_dir,
|
|
128
|
+
...converterOptions,
|
|
107
129
|
extension_registry: registry,
|
|
108
130
|
});
|
|
109
131
|
}
|
|
110
132
|
};
|
|
111
133
|
|
|
134
|
+
const getData = generateGetData(options);
|
|
135
|
+
|
|
112
136
|
return {
|
|
113
137
|
read: false,
|
|
114
138
|
getData,
|
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
|
}
|