eleventy-plugin-asciidoc 3.1.0 → 3.1.1

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 CHANGED
@@ -1,6 +1,8 @@
1
1
  # eleventy-plugin-asciidoc
2
2
 
3
- Eleventy plugin to add support for [AsciiDoc](https://asciidoc.org/). You don't need to use to shortcodes. You can directly use AsciiDoc files (`.adoc`), just like Markdown (`.md`).
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()`. These are the [available options](https://docs.asciidoctor.org/asciidoctor.js/latest/processor/convert-options/).
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. This can be changed using above [options](#customize-with-options).
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).
60
+
61
+ #### `attributes.outdir`
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).
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 quick way to style the content is to use the CSS file from Asciidoctor.js. The CSS file is [available on cdnjs](https://cdnjs.com/libraries/asciidoctor.js).
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
 
@@ -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();
@@ -71,11 +72,23 @@ function eleventyAsciidoctor(convertOptions = {}) {
71
72
  const { content } = readFileSync(inputPath);
72
73
 
73
74
  let { base_dir, configure_extension_registry } = options;
75
+ const attributes = parseDocumentAttributes(options.attributes ?? {});
76
+ let { outdir } = attributes;
77
+
74
78
  base_dir = base_dir === undefined ? path.dirname(inputPath) : base_dir;
75
79
 
80
+ if (outdir === undefined) {
81
+ const { page } = data ?? {};
82
+ const { outputPath } = page ?? {};
83
+ if (outputPath !== undefined) {
84
+ outdir = path.dirname(outputPath);
85
+ }
86
+ }
87
+
76
88
  if (content) {
77
89
  debug(`Converting:\n ${content}`);
78
90
  debug(`base_dir: ${base_dir}`);
91
+ debug(`attributes:\n ${JSON.stringify(attributes)}`);
79
92
 
80
93
  let registry;
81
94
  if (typeof configure_extension_registry === "function") {
@@ -86,6 +99,10 @@ function eleventyAsciidoctor(convertOptions = {}) {
86
99
 
87
100
  return processor.convert(content, {
88
101
  ...options,
102
+ attributes: {
103
+ ...attributes,
104
+ outdir,
105
+ },
89
106
  base_dir,
90
107
  extension_registry: registry,
91
108
  });
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.0",
3
+ "version": "3.1.1",
4
4
  "description": "Adds support for AsciiDoc to Eleventy",
5
5
  "main": ".eleventy.js",
6
6
  "repository": {