eleventy-plugin-asciidoc 1.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 +13 -0
- package/.gitattributes +1 -0
- package/LICENSE +21 -0
- package/README.md +41 -0
- package/lib/eleventy-asciidoc.js +47 -0
- package/package.json +55 -0
package/.eleventy.js
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
const eleventyAsciidoc = require("./lib/eleventy-asciidoc.js");
|
|
2
|
+
|
|
3
|
+
module.exports = {
|
|
4
|
+
/**
|
|
5
|
+
* Plugin config function
|
|
6
|
+
*
|
|
7
|
+
* @param {Object} eleventy The eleventy configuration object
|
|
8
|
+
*/
|
|
9
|
+
configFunction(eleventyConfig, userOptions) {
|
|
10
|
+
eleventyConfig.addTemplateFormats("adoc");
|
|
11
|
+
eleventyConfig.addExtension("adoc", eleventyAsciidoc(userOptions));
|
|
12
|
+
},
|
|
13
|
+
};
|
package/.gitattributes
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
*.js text eol=lf
|
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) Saneef Ansari
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
# eleventy-plugin-asciidoc
|
|
2
|
+
|
|
3
|
+
Eleventy plugin to add support for AsciiDoc. The plugin uses [Asciidoctor.js](https://docs.asciidoctor.org/asciidoctor.js) under the hood.
|
|
4
|
+
|
|
5
|
+
**Requires Eleventy `1.0.0` or newer.**
|
|
6
|
+
|
|
7
|
+
## Usage
|
|
8
|
+
|
|
9
|
+
### Install
|
|
10
|
+
|
|
11
|
+
```sh
|
|
12
|
+
npm install eleventy-plugin-asciidoc
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
### Add to Configuration File
|
|
16
|
+
|
|
17
|
+
Usually `.eleventy.js`:
|
|
18
|
+
|
|
19
|
+
```js
|
|
20
|
+
const eleventyAsciidoc = require("eleventy-plugin-asciidoc");
|
|
21
|
+
|
|
22
|
+
module.exports = function (eleventyConfig) {
|
|
23
|
+
eleventyConfig.addPlugin(eleventyAsciidoc);
|
|
24
|
+
};
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
#### Customize with Options
|
|
28
|
+
|
|
29
|
+
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/).
|
|
30
|
+
|
|
31
|
+
```js
|
|
32
|
+
const eleventyAsciidoc = require("eleventy-plugin-asciidoc");
|
|
33
|
+
|
|
34
|
+
module.exports = function (eleventyConfig) {
|
|
35
|
+
eleventyConfig.addPlugin(eleventyAsciidoc, {
|
|
36
|
+
/* Converter options */
|
|
37
|
+
showtitle: true,
|
|
38
|
+
safe: "unsafe",
|
|
39
|
+
});
|
|
40
|
+
};
|
|
41
|
+
```
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
// @ts-check
|
|
2
|
+
|
|
3
|
+
const asciidoctor = require("asciidoctor").default();
|
|
4
|
+
const debug = require("debug")("eleventy-asciidoc");
|
|
5
|
+
|
|
6
|
+
const nunjucks = require("nunjucks");
|
|
7
|
+
const fs = require("fs");
|
|
8
|
+
const matter = require("gray-matter");
|
|
9
|
+
|
|
10
|
+
function eleventyAsciidoctor(options = {}) {
|
|
11
|
+
debug("Options: ", options);
|
|
12
|
+
const readFileSync = (inputPath) => {
|
|
13
|
+
return matter(fs.readFileSync(inputPath, "utf8"));
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
const getData = (inputPath) => {
|
|
17
|
+
const { data } = readFileSync(inputPath);
|
|
18
|
+
|
|
19
|
+
return data;
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
const compile = (str) => (data) => {
|
|
23
|
+
if (str) {
|
|
24
|
+
// Since `read: false` is set 11ty doesn't read file contents
|
|
25
|
+
// so if str has a value, it's a permalink (which can be a string or a function)
|
|
26
|
+
return typeof str === "function"
|
|
27
|
+
? str(data)
|
|
28
|
+
: nunjucks.renderString(str, data);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
debug(`Reading ${data.page.inputPath}`);
|
|
32
|
+
const { content } = readFileSync(data.page.inputPath);
|
|
33
|
+
|
|
34
|
+
if (content) {
|
|
35
|
+
debug(`Converting:\n ${content}`);
|
|
36
|
+
return asciidoctor.convert(content, options);
|
|
37
|
+
}
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
return {
|
|
41
|
+
read: false,
|
|
42
|
+
getData,
|
|
43
|
+
compile,
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
module.exports = eleventyAsciidoctor;
|
package/package.json
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "eleventy-plugin-asciidoc",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "Adds support for AsciiDoc to Eleventy",
|
|
5
|
+
"main": ".eleventy.js",
|
|
6
|
+
"repository": {
|
|
7
|
+
"type": "git",
|
|
8
|
+
"url": "git+https://github.com:saneef/eleventy-plugin-asciidoctor.git"
|
|
9
|
+
},
|
|
10
|
+
"scripts": {
|
|
11
|
+
"lint": "eslint lib/**.js tests/**.js",
|
|
12
|
+
"test": "nyc ava --timeout=1m -v --color",
|
|
13
|
+
"prepare": "husky install"
|
|
14
|
+
},
|
|
15
|
+
"keywords": [
|
|
16
|
+
"responsive-images",
|
|
17
|
+
"images",
|
|
18
|
+
"eleventy",
|
|
19
|
+
"11ty",
|
|
20
|
+
"eleventy-plugin"
|
|
21
|
+
],
|
|
22
|
+
"author": "Saneef Ansari <hello@saneef.com> (https://saneef.com/)",
|
|
23
|
+
"license": "MIT",
|
|
24
|
+
"dependencies": {
|
|
25
|
+
"asciidoctor": "^2.2.5",
|
|
26
|
+
"debug": "^4.3.2",
|
|
27
|
+
"gray-matter": "^4.0.3",
|
|
28
|
+
"nunjucks": "^3.2.3"
|
|
29
|
+
},
|
|
30
|
+
"devDependencies": {
|
|
31
|
+
"ava": "^3.15.0",
|
|
32
|
+
"eslint": "^8.0.1",
|
|
33
|
+
"eslint-config-prettier": "^8.3.0",
|
|
34
|
+
"eslint-config-xo-space": "^0.30.0",
|
|
35
|
+
"eslint-plugin-prettier": "^4.0.0",
|
|
36
|
+
"husky": "^7.0.2",
|
|
37
|
+
"lint-staged": "^11.2.3",
|
|
38
|
+
"nyc": "^15.1.0",
|
|
39
|
+
"prettier": "^2.4.1",
|
|
40
|
+
"rimraf": "^3.0.2"
|
|
41
|
+
},
|
|
42
|
+
"lint-staged": {
|
|
43
|
+
"*.js": "eslint --cache --fix",
|
|
44
|
+
"*.{js,md,json}": "prettier --write"
|
|
45
|
+
},
|
|
46
|
+
"ava": {
|
|
47
|
+
"files": [
|
|
48
|
+
"tests/**/*",
|
|
49
|
+
"!tests/utils.js"
|
|
50
|
+
],
|
|
51
|
+
"ignoredByWatcher": [
|
|
52
|
+
"tests/output/**"
|
|
53
|
+
]
|
|
54
|
+
}
|
|
55
|
+
}
|