eleventy-plugin-asciidoc 5.0.1 → 5.1.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/README.md CHANGED
@@ -35,7 +35,7 @@ module.exports = function (eleventyConfig) {
35
35
  };
36
36
  ```
37
37
 
38
- ### Front Matter
38
+ ## Front Matter
39
39
 
40
40
  You can use either [Eleventy style front matter](https://www.11ty.dev/docs/data-frontmatter/#front-matter-formats) or AsciiDoc document attributes to write front matter.
41
41
 
@@ -68,7 +68,7 @@ Hello everyone!
68
68
  > [!WARNING]
69
69
  > Asciidoctor.js converts all attribute names to lower case letters. Example `:eleventy-aTitle:` will be made available as `atitle` in front matter data (also as `eleventy-atitle` in document attributes).
70
70
 
71
- #### Data Cascade
71
+ ### Data Cascade
72
72
 
73
73
  Data specified using AsciiDoc style front matter override YAML (or front matter in other Eleventy supported formats).
74
74
 
@@ -87,9 +87,36 @@ In the above case, front matter data will have `{ layout: layout-b.njk }`.
87
87
 
88
88
  In the case of `title`, [the AsciiDoc document title](https://docs.asciidoctor.org/asciidoc/latest/document/title/) (including `title` and `doctitle` attributes) takes precedence over front matter.
89
89
 
90
- ### Customize with Options
90
+ ## Options
91
+
92
+ You can pass options as the second argument in `addPlugin()`.
93
+
94
+ ### Options for this plugin
95
+
96
+ #### `eleventyAttributesPrefix`
97
+
98
+ Default value is `eleventy-`.
99
+
100
+ This config can be used to change the prefix string for [AsciiDoc style front matter](#front-matter).
101
+
102
+ #### `resolveDocumentTitle`
103
+
104
+ Default value is `false`.
105
+
106
+ If enabled, the title will be resolved from the heading of the first section in the document. Otherwise, the title will be the Level 0 heading.
107
+
108
+ ```adoc
109
+ == A second level heading
110
+
111
+ This text is written in AsciiDoc format.
112
+ ```
113
+
114
+ With `resolveDocumentTitle: true`, the above document will have a title (in page data). `A second level heading`.
115
+
116
+ ### Options for Asciidoctor.js
117
+
118
+ All properties other than [the ones specific to the plugin](#options-for-this-plugin) will be passed to Asciidoctor.js.
91
119
 
92
- You can pass options to `convert()` of Asciidoctor.js as second argument in `addPlugin()`.
93
120
  These are the [available options](https://docs.asciidoctor.org/asciidoctor.js/latest/processor/convert-options/).
94
121
 
95
122
  ```js
@@ -144,12 +171,6 @@ module.exports = function (eleventyConfig) {
144
171
 
145
172
  Refer to [Asciidoctor.js documentation](https://docs.asciidoctor.org/asciidoctor.js/latest/extend/extensions/) to know more about extensions.
146
173
 
147
- #### `eleventyAttributesPrefix`
148
-
149
- Default value is `eleventy-`.
150
-
151
- This config can be used to change the prefix string for [AsciiDoc style front matter](#front-matter).
152
-
153
174
  ### CSS Styles
154
175
 
155
176
  The plugin does not include any CSS styles. It is up to you to style the content.
@@ -18,6 +18,7 @@ const processor = asciidoctor();
18
18
  /**
19
19
  * @typedef {Object} ExtraProcessorOptions
20
20
  * @property {string=} eleventyAttributesPrefix
21
+ * @property {Boolean} [resolveDocumentTitle=false]
21
22
  * @typedef {import('@asciidoctor/core').ProcessorOptions & ExtraProcessorOptions} EleventyAsciidocOptions
22
23
  */
23
24
 
@@ -31,6 +32,21 @@ const readFileSync = (inputPath) => {
31
32
  return matter(fs.readFileSync(inputPath, "utf8"));
32
33
  };
33
34
 
35
+ /**
36
+ * Gets the title from ascii document document.
37
+ *
38
+ * @param {object} document The document
39
+ * @param {boolean} [resolve=false] The resolve
40
+ * @return {string | undefined} The title of the document.
41
+ */
42
+ function getTitleFromAsciiDocDocument(document, resolve = false) {
43
+ if (resolve) {
44
+ return document.getDocumentTitle();
45
+ }
46
+
47
+ return document.getHeader()?.title;
48
+ }
49
+
34
50
  /** @typedef {(inputPath: string) => Object.<string, any>} GetDataFn
35
51
  * Gets front-matter data from the file synchronously
36
52
  */
@@ -44,14 +60,19 @@ const readFileSync = (inputPath) => {
44
60
 
45
61
  const generateGetDataFromInputPath = (converterOptions) => (inputPath) => {
46
62
  const { content } = readFileSync(inputPath);
47
- const { eleventyAttributesPrefix = "eleventy-" } = converterOptions;
63
+ const {
64
+ eleventyAttributesPrefix = "eleventy-",
65
+ resolveDocumentTitle = false,
66
+ ...restOfConverterOptions
67
+ } = converterOptions;
48
68
 
49
69
  const doc = processor.load(content, {
50
- ...converterOptions,
51
- base_dir: getBaseDir(inputPath, converterOptions.base_dir),
70
+ ...restOfConverterOptions,
71
+ base_dir: getBaseDir(inputPath, restOfConverterOptions.base_dir),
52
72
  });
53
73
 
54
- const title = doc.getDocumentTitle();
74
+ const title = getTitleFromAsciiDocDocument(doc, resolveDocumentTitle);
75
+
55
76
  const attributes = doc.getAttributes();
56
77
 
57
78
  let eleventyAttributes = pickByKeyPrefix(
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "eleventy-plugin-asciidoc",
3
- "version": "5.0.1",
3
+ "version": "5.1.0",
4
4
  "description": "Adds support for AsciiDoc to Eleventy",
5
5
  "main": "index.js",
6
6
  "funding": "https://github.com/sponsors/saneef/",