eleventy-plugin-asciidoc 1.1.0 → 1.2.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
@@ -1,13 +1,16 @@
1
1
  const eleventyAsciidoc = require("./lib/eleventy-asciidoc.js");
2
2
 
3
+ /** @typedef {import('./lib/eleventy-asciidoc.js').ProcessorOptions} ProcessorOptions} */
4
+
3
5
  module.exports = {
4
6
  /**
5
7
  * Plugin config function
6
8
  *
7
- * @param {Object} eleventy The eleventy configuration object
9
+ * @param {object} eleventyConfig The eleventy configuration object
10
+ * @param {ProcessorOptions} converterOptions Options for Asciidoctor.converter()
8
11
  */
9
- configFunction(eleventyConfig, userOptions) {
12
+ configFunction(eleventyConfig, converterOptions) {
10
13
  eleventyConfig.addTemplateFormats("adoc");
11
- eleventyConfig.addExtension("adoc", eleventyAsciidoc(userOptions));
14
+ eleventyConfig.addExtension("adoc", eleventyAsciidoc(converterOptions));
12
15
  },
13
16
  };
package/README.md CHANGED
@@ -1,9 +1,18 @@
1
1
  # eleventy-plugin-asciidoc
2
2
 
3
- Eleventy plugin to add support for AsciiDoc. The plugin uses [Asciidoctor.js](https://docs.asciidoctor.org/asciidoctor.js) under the hood.
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`).
4
+
5
+ The plugin uses [Asciidoctor.js](https://docs.asciidoctor.org/asciidoctor.js) under the hood.
4
6
 
5
7
  **Requires Eleventy `1.0.0` or newer.**
6
8
 
9
+ ## Features
10
+
11
+ - Supports the default [YAML front matter](https://www.11ty.dev/docs/data-frontmatter/).
12
+ - Supports [AsciiDoc document title](https://docs.asciidoctor.org/asciidoc/latest/document/title/#title-syntax)
13
+ - Other attributes in the AsciiDoc file are made available in `page.asciidocAttributes`.
14
+ - Example `:author: Jane Doe` in the `.adoc` file will be available in `page.asciidocAttrbutes.author`
15
+
7
16
  ## Usage
8
17
 
9
18
  ### Install
@@ -33,9 +42,8 @@ const eleventyAsciidoc = require("eleventy-plugin-asciidoc");
33
42
 
34
43
  module.exports = function (eleventyConfig) {
35
44
  eleventyConfig.addPlugin(eleventyAsciidoc, {
36
- /* Converter options */
37
- showtitle: true,
38
- safe: "unsafe",
45
+ showtitle: true /* Default value: true */,
46
+ safe: "unsafe" /* Default value: undefined */,
39
47
  });
40
48
  };
41
49
  ```
@@ -1,22 +1,57 @@
1
1
  // @ts-check
2
2
 
3
3
  const asciidoctor = require("asciidoctor").default();
4
- const debug = require("debug")("eleventy-asciidoc");
5
-
6
- const nunjucks = require("nunjucks");
4
+ const debug = require("debug")("eleventy-plugin-asciidoc");
7
5
  const fs = require("fs");
8
6
  const matter = require("gray-matter");
7
+ const nunjucks = require("nunjucks");
8
+
9
+ /** @typedef {import('asciidoctor').Asciidoctor.ProcessorOptions} ProcessorOptions */
10
+ /** @typedef {import('gray-matter').GrayMatterFile} GrayMatterFile */
9
11
 
10
- function eleventyAsciidoctor(options = {}) {
11
- debug("Options: ", options);
12
- const readFileSync = (inputPath) => {
13
- return matter(fs.readFileSync(inputPath, "utf8"));
12
+ /**
13
+ * Reads a file synchronously.
14
+ *
15
+ * @param {string} inputPath The input path
16
+ * @return {GrayMatterFile} { description_of_the_return_value }
17
+ */
18
+ const readFileSync = (inputPath) => {
19
+ return matter(fs.readFileSync(inputPath, "utf8"));
20
+ };
21
+
22
+ /**
23
+ * Gets front-matter data from the file synchronously
24
+ *
25
+ * @param {string} inputPath The input path
26
+ * @return {{ [key: string]: any }} The data.
27
+ */
28
+ const getData = (inputPath) => {
29
+ const { data, content } = readFileSync(inputPath);
30
+ const doc = asciidoctor.load(content);
31
+ const attributes = doc.getAttributes();
32
+ const title = doc.getDocumentTitle();
33
+ debug(`Document title ${title}`);
34
+ debug(`Document attributes: ${attributes}`);
35
+
36
+ return {
37
+ title,
38
+ asciidocAttributes: attributes,
39
+ ...data,
14
40
  };
41
+ };
15
42
 
16
- const getData = (inputPath) => {
17
- const { data } = readFileSync(inputPath);
43
+ /**
44
+ * Generates Eleventy template renderer for AsciiDoctor
45
+ *
46
+ * @param {ProcessorOptions=} convertOptions Options for Asciidoctor.converter()
47
+ * @return {Object} Eleventy data processor object
48
+ */
49
+ function eleventyAsciidoctor(convertOptions = {}) {
50
+ debug("Converter options: ", convertOptions);
18
51
 
19
- return data;
52
+ const options = {
53
+ showtitle: true,
54
+ ...convertOptions,
20
55
  };
21
56
 
22
57
  const compile = (str) => (data) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "eleventy-plugin-asciidoc",
3
- "version": "1.1.0",
3
+ "version": "1.2.0",
4
4
  "description": "Adds support for AsciiDoc to Eleventy",
5
5
  "main": ".eleventy.js",
6
6
  "repository": {
@@ -9,7 +9,7 @@
9
9
  },
10
10
  "scripts": {
11
11
  "lint": "eslint lib/**.js tests/**.js",
12
- "test": "nyc ava --timeout=1m -v --color",
12
+ "test": "nyc ava -v --color",
13
13
  "prepare": "husky install"
14
14
  },
15
15
  "keywords": [