eleventy-plugin-asciidoc 3.1.1 → 4.0.0

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/.eleventy.js CHANGED
@@ -26,7 +26,10 @@ module.exports = {
26
26
  );
27
27
  }
28
28
 
29
- eleventyConfig.addTemplateFormats("adoc");
30
- eleventyConfig.addExtension("adoc", eleventyAsciidoc(converterOptions));
29
+ eleventyConfig.addTemplateFormats(["adoc", "asciidoc", "ad"]);
30
+ eleventyConfig.addExtension(
31
+ ["adoc", "asciidoc", "ad"],
32
+ eleventyAsciidoc(converterOptions),
33
+ );
31
34
  },
32
35
  };
package/README.md CHANGED
@@ -6,14 +6,14 @@ You can directly use AsciiDoc files (`.adoc`), just like Markdown (`.md`).
6
6
 
7
7
  The plugin uses [Asciidoctor.js](https://docs.asciidoctor.org/asciidoctor.js) under the hood.
8
8
 
9
- **Requires Eleventy 1.0.0-beta.10, 1.0.0-canary.50 or newer.**
9
+ **Requires Eleventy 2.0.0-canary.19 or newer.**
10
10
 
11
11
  ## Features
12
12
 
13
13
  - Supports the default [YAML front matter](https://www.11ty.dev/docs/data-frontmatter/).
14
14
  - Supports [AsciiDoc document title](https://docs.asciidoctor.org/asciidoc/latest/document/title/#title-syntax)
15
15
  - Other attributes in the AsciiDoc files are made available in templates through `asciidocAttributes`.
16
- - Example `:author: Jane Doe` in the `.adoc` file will be available as `asciidocAttrbutes.author`
16
+ - Example `:author: Jane Doe` in the `.adoc` file will be available as `asciidocAttributes.author`
17
17
 
18
18
  ## Usage
19
19
 
@@ -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
 
@@ -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} { description_of_the_return_value }
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 {string} inputPath The input path
32
- * @return {{ [key: string]: any }} The data.
35
+ * @param {ProcessorOptions} converterOptions The converter options
36
+ * @return {GetDataFn}
33
37
  */
34
- const getData = (inputPath) => {
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 = base_dir === undefined ? path.dirname(inputPath) : 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
- ...options,
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.1",
3
+ "version": "4.0.0",
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.2",
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": "^5.3.1",
36
- "eslint": "^8.45.0",
37
- "eslint-config-prettier": "^8.9.0",
38
- "eslint-config-xo-space": "^0.34.0",
39
- "eslint-plugin-prettier": "^5.0.0",
40
- "husky": "^8.0.3",
41
- "lint-staged": "^13.2.3",
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.0.0",
44
- "rimraf": "^5.0.1"
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
- "ignoredByWatcher": [
57
- "tests/output/**"
58
- ]
56
+ "watchMode": {
57
+ "ignoreChanges": [
58
+ "tests/output/**"
59
+ ]
60
+ }
59
61
  }
60
62
  }