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