@rmdes/indiekit-preset-eleventy 1.0.0-beta.25
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 +17 -0
- package/assets/icon.svg +4 -0
- package/index.js +22 -0
- package/lib/post-template.js +81 -0
- package/lib/post-types.js +25 -0
- package/package.json +45 -0
package/README.md
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
# @indiekit/preset-eleventy
|
|
2
|
+
|
|
3
|
+
[Eleventy](https://www.11ty.dev) publication preset for Indiekit.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
`npm install @indiekit/preset-eleventy`
|
|
8
|
+
|
|
9
|
+
## Usage
|
|
10
|
+
|
|
11
|
+
Add `@indiekit/preset-eleventy` to your list of plug-ins:
|
|
12
|
+
|
|
13
|
+
```json
|
|
14
|
+
{
|
|
15
|
+
"plugins": ["@indiekit/preset-eleventy"]
|
|
16
|
+
}
|
|
17
|
+
```
|
package/assets/icon.svg
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 96 96">
|
|
2
|
+
<path fill="#222" d="M0 0h96v96H0z"/>
|
|
3
|
+
<path fill="#FFF" d="M42.7 27c1 0 1.3.8 1.3 2v35.5c0 1.6-.4 2.5-1.4 2.5h-4.1c-1 0-1.4-1-1.4-2.5V34.8h-.2l-.8.2-.5.2h-.2c-1 .1-1.4-.7-1.4-1.9v-2.5c0-1 .4-1.8 1.2-2l7-1.7.5-.1Zm11.9-1c1 0 1.4.8 1.4 2.1v10.4h3c1 0 1.5 1 1.5 2V42c0 1.2-.5 2-1.5 2h-3v13.7c0 .9 0 1.6.2 2.2v.3l.4 1.2.6.4.7.1h1.9c1 0 1.5.7 1.5 1.7v1.6c0 1-.6 1.8-1.6 1.8H57c-.8 0-1.5 0-2-.2-.7 0-1.4-.3-2-.7a5 5 0 0 1-1.7-1.7c-.4-.7-.7-1.6-1-2.8-.2-1.1-.4-2.5-.4-4V44h-1.4c-1 0-1.5-.7-1.5-1.8v-1.6c0-1.2.5-2.1 1.5-2.1H50l.4-10.4c.1-1.3.5-2.1 1.5-2.1h2.7Zm22.2 13c.9 0 1.2.7 1.2 1.8v.7l-4.8 25.2a26 26 0 0 1-1.3 5c-.5 1.2-1 2-1.7 2.5s-1.5.8-2.6.8h-.3c-1.6 0-2.8-.5-3.5-1.5-.2-.3-.3-.8-.3-1.4v-.2c0-1.8.3-2.8 1.3-2.8l1.2.4 1 .2s.2-.1.4-.6c.3-.6.4-1.5.4-2.6l-.5-2.9L62 41.4l-.1-.7c0-1 .3-1.7 1.1-1.7h3.2c.5 0 .8.2 1.1.5.3.3.5.7.6 1.4l2.8 15.3L73 41c0-.6.2-1 .4-1.3v-.1c.4-.4.8-.6 1.2-.6h2.2ZM28.7 27c1 0 1.3.8 1.3 2v35.5c0 1.6-.4 2.5-1.4 2.5h-4.1c-1 0-1.4-1-1.4-2.5V34.8h-.2l-.8.2-.5.2h-.2c-1 .1-1.4-.7-1.4-1.9v-2.5c0-1 .4-1.8 1.2-2l7-1.7.5-.1Z"/>
|
|
4
|
+
</svg>
|
package/index.js
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { getPostTemplate } from "./lib/post-template.js";
|
|
2
|
+
import { getPostTypes } from "./lib/post-types.js";
|
|
3
|
+
|
|
4
|
+
export default class EleventyPreset {
|
|
5
|
+
name = "Eleventy preset";
|
|
6
|
+
|
|
7
|
+
get info() {
|
|
8
|
+
return {
|
|
9
|
+
name: "Eleventy",
|
|
10
|
+
};
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
postTemplate(properties) {
|
|
14
|
+
return getPostTemplate(properties);
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
init(Indiekit) {
|
|
18
|
+
this.postTypes = getPostTypes(Indiekit.postTypes);
|
|
19
|
+
|
|
20
|
+
Indiekit.addPreset(this);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import camelcaseKeys from "camelcase-keys";
|
|
2
|
+
import YAML from "yaml";
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Get content
|
|
6
|
+
* @access private
|
|
7
|
+
* @param {object} properties - JF2 properties
|
|
8
|
+
* @returns {string} Content
|
|
9
|
+
*/
|
|
10
|
+
const getContent = (properties) => {
|
|
11
|
+
if (properties.content) {
|
|
12
|
+
const content =
|
|
13
|
+
properties.content.text || properties.content.html || properties.content;
|
|
14
|
+
return `\n${content}\n`;
|
|
15
|
+
} else {
|
|
16
|
+
return "";
|
|
17
|
+
}
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Get front matter
|
|
22
|
+
* @access private
|
|
23
|
+
* @param {object} properties - JF2 properties
|
|
24
|
+
* @returns {string} Front matter in chosen format
|
|
25
|
+
*/
|
|
26
|
+
const getFrontMatter = (properties) => {
|
|
27
|
+
/**
|
|
28
|
+
* Eleventy uses camelCase for YAML property keys, i.e. `fileSlug`
|
|
29
|
+
* @see {@link https://www.11ty.dev/docs/data-eleventy-supplied/}
|
|
30
|
+
*/
|
|
31
|
+
properties = camelcaseKeys(properties, { deep: true });
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Replace Microformat properties with Eleventy equivalents
|
|
35
|
+
* @see {@link https://www.11ty.dev/docs/data-frontmatter/}
|
|
36
|
+
* @see {@link https://www.11ty.dev/docs/dates/}
|
|
37
|
+
*/
|
|
38
|
+
properties = {
|
|
39
|
+
date: properties.published,
|
|
40
|
+
...(properties.name && { title: properties.name }),
|
|
41
|
+
...properties,
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Draft posts
|
|
46
|
+
* @see {@link https://www.11ty.dev/docs/quicktips/draft-posts/}
|
|
47
|
+
*/
|
|
48
|
+
if (properties.postStatus === "draft") {
|
|
49
|
+
properties.draft = true;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
delete properties.content; // Shown below front matter
|
|
53
|
+
delete properties.name; // Use `title`
|
|
54
|
+
delete properties.postStatus; // Use `draft`
|
|
55
|
+
delete properties.published; // Use `date`
|
|
56
|
+
delete properties.slug; // use `page.fileSlug`
|
|
57
|
+
delete properties.type; // Not required
|
|
58
|
+
|
|
59
|
+
// Convert url to Eleventy permalink so generated URL matches Indiekit's stored URL
|
|
60
|
+
// Add trailing slash to generate /path/index.html instead of /path.html
|
|
61
|
+
if (properties.url) {
|
|
62
|
+
const url = properties.url;
|
|
63
|
+
properties.permalink = url.endsWith("/") ? url : `${url}/`;
|
|
64
|
+
}
|
|
65
|
+
delete properties.url;
|
|
66
|
+
|
|
67
|
+
const frontMatter = YAML.stringify(properties, { lineWidth: 0 });
|
|
68
|
+
return `---\n${frontMatter}---\n`;
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* Get post template
|
|
73
|
+
* @param {object} properties - JF2 properties
|
|
74
|
+
* @returns {string} Rendered template
|
|
75
|
+
*/
|
|
76
|
+
export const getPostTemplate = (properties) => {
|
|
77
|
+
const content = getContent(properties);
|
|
78
|
+
const frontMatter = getFrontMatter(properties);
|
|
79
|
+
|
|
80
|
+
return frontMatter + content;
|
|
81
|
+
};
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import plur from "plur";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Get paths and URLs for configured post types
|
|
5
|
+
* @param {object} postTypes - Post type configuration
|
|
6
|
+
* @returns {object} Updated post type configuration
|
|
7
|
+
*/
|
|
8
|
+
export const getPostTypes = (postTypes) => {
|
|
9
|
+
for (const type of postTypes.keys()) {
|
|
10
|
+
const collection = plur(type);
|
|
11
|
+
|
|
12
|
+
postTypes.set(type, {
|
|
13
|
+
...postTypes.get(type),
|
|
14
|
+
post: {
|
|
15
|
+
path: `${collection}/{yyyy}-{MM}-{dd}-{slug}.md`,
|
|
16
|
+
url: `${collection}/{yyyy}/{MM}/{dd}/{slug}`,
|
|
17
|
+
},
|
|
18
|
+
media: {
|
|
19
|
+
path: `media/${collection}/{yyyy}/{MM}/{dd}/{filename}`,
|
|
20
|
+
},
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
return postTypes;
|
|
25
|
+
};
|
package/package.json
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@rmdes/indiekit-preset-eleventy",
|
|
3
|
+
"version": "1.0.0-beta.25",
|
|
4
|
+
"description": "Eleventy publication preset for Indiekit (fork with permalink fix)",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"indiekit",
|
|
7
|
+
"indiekit-plugin",
|
|
8
|
+
"indieweb",
|
|
9
|
+
"micropub",
|
|
10
|
+
"eleventy",
|
|
11
|
+
"11ty"
|
|
12
|
+
],
|
|
13
|
+
"homepage": "https://getindiekit.com",
|
|
14
|
+
"author": {
|
|
15
|
+
"name": "Paul Robert Lloyd",
|
|
16
|
+
"url": "https://paulrobertlloyd.com"
|
|
17
|
+
},
|
|
18
|
+
"license": "MIT",
|
|
19
|
+
"engines": {
|
|
20
|
+
"node": ">=20"
|
|
21
|
+
},
|
|
22
|
+
"type": "module",
|
|
23
|
+
"main": "index.js",
|
|
24
|
+
"files": [
|
|
25
|
+
"assets",
|
|
26
|
+
"lib",
|
|
27
|
+
"index.js"
|
|
28
|
+
],
|
|
29
|
+
"bugs": {
|
|
30
|
+
"url": "https://github.com/rmdes/indiekit/issues"
|
|
31
|
+
},
|
|
32
|
+
"repository": {
|
|
33
|
+
"type": "git",
|
|
34
|
+
"url": "https://github.com/rmdes/indiekit.git",
|
|
35
|
+
"directory": "packages/preset-eleventy"
|
|
36
|
+
},
|
|
37
|
+
"dependencies": {
|
|
38
|
+
"camelcase-keys": "^10.0.0",
|
|
39
|
+
"plur": "^6.0.0",
|
|
40
|
+
"yaml": "^2.6.0"
|
|
41
|
+
},
|
|
42
|
+
"publishConfig": {
|
|
43
|
+
"access": "public"
|
|
44
|
+
}
|
|
45
|
+
}
|