@anyblades/buildawesome-kit 1.3.0-alpha → 1.3.0-alpha.3

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
@@ -39,15 +39,15 @@ Then `addPlugin` to your 11ty config:
39
39
  ```js
40
40
  import eleventyBladesPlugin from "@anyblades/eleventy-blades";
41
41
 
42
- export default function (eleventyConfig) {
43
- eleventyConfig.addPlugin(eleventyBladesPlugin);
42
+ export default function ($config) {
43
+ $config.addPlugin(eleventyBladesPlugin);
44
44
  }
45
45
  ```
46
46
 
47
47
  You can toggle features/filters like this:
48
48
 
49
49
  ```js
50
- eleventyConfig.addPlugin(eleventyBladesPlugin, {
50
+ $config.addPlugin(eleventyBladesPlugin, {
51
51
  mdAutoRawTags: false,
52
52
  filters: { attr_set: false },
53
53
  });
@@ -93,7 +93,7 @@ cd _includes/
93
93
  ln -s ../node_modules/@anyblades/blades/_includes/blades
94
94
 
95
95
  # Run Eleventy:
96
- eleventy --config=node_modules/@anyblades/eleventy-blades-base/eleventy.config.js
96
+ eleventy --config=node_modules/@anyblades/eleventy-blades-base/buildawesome.config.js
97
97
  ```
98
98
 
99
99
  Live examples:
@@ -106,7 +106,7 @@ Live examples:
106
106
  If you don't want to type `--config=...` every time, symlink it once:
107
107
 
108
108
  ```sh
109
- ln -s node_modules/@anyblades/eleventy-blades-base/eleventy.config.js
109
+ ln -s node_modules/@anyblades/eleventy-blades-base/buildawesome.config.js
110
110
  eleventy
111
111
  ```
112
112
 
@@ -114,7 +114,7 @@ Or save it in your `package.json` scripts:
114
114
 
115
115
  ```json
116
116
  "scripts": {
117
- "build": "eleventy --config=node_modules/@anyblades/eleventy-blades-base/eleventy.config.js"
117
+ "build": "eleventy --config=node_modules/@anyblades/eleventy-blades-base/buildawesome.config.js"
118
118
  }
119
119
  ```
120
120
 
@@ -125,15 +125,15 @@ Alternatively, import it as a base config in your 11ty config:
125
125
  ```js
126
126
  import baseConfig from "@anyblades/eleventy-blades-base";
127
127
 
128
- export default async function (eleventyConfig) {
129
- await baseConfig(eleventyConfig);
128
+ export default async function ($config) {
129
+ await baseConfig($config);
130
130
  }
131
131
  ```
132
132
 
133
133
  You can toggle features/filters like this:
134
134
 
135
135
  ```js
136
- await baseConfig(eleventyConfig, {
136
+ await baseConfig($config, {
137
137
  plugins: {
138
138
  "@anyblades/eleventy-blades": {
139
139
  mdAutoRawTags: false,
@@ -145,8 +145,8 @@ await baseConfig(eleventyConfig, {
145
145
 
146
146
  Live examples:
147
147
 
148
- - https://github.com/johnheenan/minform/blob/main/eleventy.config.js
149
- - https://github.com/hostfurl/minformhf/blob/main/eleventy.config.js
148
+ - https://github.com/johnheenan/minform/blob/main/buildawesome.config.js
149
+ - https://github.com/hostfurl/minformhf/blob/main/buildawesome.config.js
150
150
 
151
151
  <!--section:gh-only-->
152
152
 
@@ -19,44 +19,45 @@ import path from "node:path";
19
19
 
20
20
  /**
21
21
  * Eleventy Configuration
22
- * @param {Object} eleventyConfig - The Eleventy configuration object
22
+ * @param {Object} $config - The Eleventy configuration object
23
23
  * @returns {Object} The Eleventy configuration object
24
24
  */
25
- export default async function (eleventyConfig, pluginOptions = {}) {
25
+ export default async function ($config, pluginOptions = {}) {
26
26
  /* Dirs */
27
- const inputDir = eleventyConfig.directories.input;
28
- const outputDir = eleventyConfig.directories.output;
29
- const cwdIsDotEleventy = path.basename(process.cwd()) === ".11ty";
30
- if (cwdIsDotEleventy) {
27
+ const inputDir = $config.directories.input;
28
+ const outputDir = $config.directories.output;
29
+ const _cwd = path.basename(process.cwd());
30
+ const cwdDotDir = _cwd.startsWith(".") ? _cwd : undefined;
31
+ if (cwdDotDir) {
31
32
  // Per https://www.11ty.dev/docs/config/#directory-for-includes
32
33
  // Order matters, put this at the top of your configuration file.
33
34
  // This is relative to your input directory!
34
- eleventyConfig.setIncludesDirectory("./.11ty/_includes/");
35
+ $config.setIncludesDirectory(`${cwdDotDir}/_includes/`);
35
36
  }
36
37
 
37
38
  /* Plugins */
38
- eleventyConfig.addBundle("css", { bundleHtmlContentFromSelector: "style" }); // per https://www.11ty.dev/docs/plugins/bundle/#bundling-html-node-content
39
- eleventyConfig.addTransform("inject-css-bundle", function (content) {
39
+ $config.addBundle("css", { bundleHtmlContentFromSelector: "style" }); // per https://www.11ty.dev/docs/plugins/bundle/#bundling-html-node-content
40
+ $config.addTransform("inject-css-bundle", function (content) {
40
41
  const isHtml = typeof this.page.outputPath === "string" && this.page.outputPath.endsWith(".html");
41
- const css = isHtml && eleventyConfig.getFilter("getBundle").call(this, "css");
42
+ const css = isHtml && $config.getFilter("getBundle").call(this, "css");
42
43
  return css ? content.replace("</head>", `<style>${css}</style></head>`) : content;
43
44
  });
44
- eleventyConfig.addPlugin(RenderPlugin);
45
- eleventyConfig.addPlugin(eleventyNavigationPlugin);
46
- eleventyConfig.addPlugin(
45
+ $config.addPlugin(RenderPlugin);
46
+ $config.addPlugin(eleventyNavigationPlugin);
47
+ $config.addPlugin(
47
48
  kitPlugin,
48
49
  pluginOptions.plugins?.["@anyblades/buildawesome-kit-plugin"] ?? { mdAutoRawTags: true },
49
50
  );
50
- eleventyConfig.addPlugin(pluginTOC, {
51
+ $config.addPlugin(pluginTOC, {
51
52
  ignoredElements: [".header-anchor", "sub"],
52
53
  ul: true,
53
54
  wrapper: (toc) => `${toc}`,
54
55
  });
55
56
  // Feed plugin
56
- eleventyConfig.addCollection("feed", (collectionApi) =>
57
+ $config.addCollection("feed", (collectionApi) =>
57
58
  collectionApi.getAll().filter((item) => item.data.date || item.data.revised),
58
59
  );
59
- eleventyConfig.addPlugin(feedPlugin, {
60
+ $config.addPlugin(feedPlugin, {
60
61
  // per https://www.11ty.dev/docs/plugins/rss/#virtual-template
61
62
  type: "atom", // or "rss", "json"
62
63
  outputPath: "/feed.xml",
@@ -93,23 +94,23 @@ export default async function (eleventyConfig, pluginOptions = {}) {
93
94
  .catch(() => {
94
95
  /* optional – skip if not installed */
95
96
  });
96
- eleventyConfig.setLibrary("md", md);
97
+ $config.setLibrary("md", md);
97
98
  //```<!--section:code,markdownify-->```js
98
- eleventyConfig.addFilter("markdownify", (content) => md.render(String(content ?? "")));
99
+ $config.addFilter("markdownify", (content) => md.render(String(content ?? "")));
99
100
  //```<!--section:code-->```js
100
101
 
101
102
  /* Data */
102
- eleventyConfig.addDataExtension("yml,yaml", (contents) => YAML.parse(contents));
103
- eleventyConfig.addGlobalData("layout", "default");
103
+ $config.addDataExtension("yml,yaml", (contents) => YAML.parse(contents));
104
+ $config.addGlobalData("layout", "default");
104
105
  // Sitemap
105
- eleventyConfig.addTemplate("sitemap.xml.njk", "", {
106
+ $config.addTemplate("sitemap.xml.njk", "", {
106
107
  permalink: "/sitemap.xml",
107
108
  layout: "blades/sitemap.xml.njk",
108
109
  eleventyExcludeFromCollections: true,
109
110
  });
110
111
 
111
112
  /* Build */
112
- eleventyConfig.addPassthroughCopy(
113
+ $config.addPassthroughCopy(
113
114
  {
114
115
  // From current working directory
115
116
  _public: "./",
@@ -123,19 +124,19 @@ export default async function (eleventyConfig, pluginOptions = {}) {
123
124
 
124
125
  /* Internal */
125
126
  // Jekyll templates compatibility
126
- eleventyConfig.addFilter("relative_url", (content) => content); // dummy
127
- eleventyConfig.setLiquidOptions({
127
+ $config.addFilter("relative_url", (content) => content); // dummy
128
+ $config.setLiquidOptions({
128
129
  dynamicPartials: false, // allows unquoted Jekyll-style includes
129
130
  root: [
130
- eleventyConfig.directories.includes,
131
+ $config.directories.includes,
131
132
  fs.realpathSync(path.resolve("./node_modules/@anyblades/blades/_includes")), // for symlinks to work after https://github.com/harttle/liquidjs/pull/870
132
133
  ],
133
134
  });
134
135
  // Dev tools
135
- eleventyConfig.setChokidarConfig({ followSymlinks: true }); // follow symlinks in Chokidar used by 11ty to watch files
136
- if (cwdIsDotEleventy) {
137
- eleventyConfig.watchIgnores.add(`../.11ty/${outputDir}`); // !!! avoid circular watching
138
- eleventyConfig.watchIgnores.add("../.11ty/node_modules/"); // avoid performance issues
136
+ $config.setChokidarConfig({ followSymlinks: true }); // follow symlinks in Chokidar used by 11ty to watch files
137
+ if (cwdDotDir) {
138
+ $config.watchIgnores.add(`../${cwdDotDir}/${outputDir}`); // !!! avoid circular watching
139
+ $config.watchIgnores.add(`../${cwdDotDir}/node_modules/`); // avoid performance issues
139
140
  }
140
141
  }
141
142
  //```
package/package.json CHANGED
@@ -1,13 +1,13 @@
1
1
  {
2
2
  "name": "@anyblades/buildawesome-kit",
3
- "version": "1.3.0-alpha",
3
+ "version": "1.3.0-alpha.3",
4
4
  "type": "module",
5
- "main": "./eleventy.config.js",
5
+ "main": "./buildawesome.config.js",
6
6
  "dependencies": {
7
7
  "@11ty/eleventy-navigation": "^1.0.5",
8
8
  "@11ty/eleventy-plugin-rss": "^3.0.0",
9
9
  "@anyblades/blades": "^2.4.6",
10
- "@anyblades/buildawesome-kit-plugin": "^1.3.0-0",
10
+ "@anyblades/buildawesome-kit-plugin": "^1.3.0-alpha.2",
11
11
  "@uncenter/eleventy-plugin-toc": "^2.1.1",
12
12
  "markdown-it": "^14.1.0",
13
13
  "markdown-it-anchor": "^9.2.0",
@@ -32,7 +32,7 @@
32
32
  ],
33
33
  "=== METADATA": "===",
34
34
  "author": "Anton Staroverov",
35
- "description": "A ready-to-go `eleventy.config.js` for popular 11ty plugins, bundled with npm scripts in one reusable, zero-maintenance package.",
35
+ "description": "A ready-to-go `buildawesome.config.js` for popular 11ty plugins, bundled with npm scripts in one reusable, zero-maintenance package.",
36
36
  "homepage": "https://build.blades.ninja/",
37
37
  "keywords": [
38
38
  "11ty",
@@ -60,8 +60,8 @@ export function replaceLinksInHtml(content, transformer) {
60
60
  );
61
61
  }
62
62
 
63
- export default function (eleventyConfig) {
64
- eleventyConfig.addTransform("autoLinkFavicons", function (content) {
63
+ export default function ($config) {
64
+ $config.addTransform("autoLinkFavicons", function (content) {
65
65
  if (this.page.outputPath && this.page.outputPath.endsWith(".html")) {
66
66
  return replaceLinksInHtml(content, transformLink);
67
67
  }
@@ -12,8 +12,8 @@ export function transformNl2br(content) {
12
12
  return content.replace(/\\n\\n/g, "<br>").replace(/\\n/g, "<br>");
13
13
  }
14
14
 
15
- export default function mdAutoNl2br(eleventyConfig) {
16
- eleventyConfig.amendLibrary("md", (mdLib) => {
15
+ export default function mdAutoNl2br($config) {
16
+ $config.amendLibrary("md", (mdLib) => {
17
17
  mdLib.renderer.rules.text = (tokens, idx) => {
18
18
  return transformNl2br(tokens[idx].content);
19
19
  };
@@ -9,8 +9,8 @@ export function transformAutoRaw(content) {
9
9
  return content.replace(/({{|}}|{%|%})/g, "{% raw %}$1{% endraw %}");
10
10
  }
11
11
 
12
- export default function mdAutoRawTags(eleventyConfig) {
13
- eleventyConfig.addPreprocessor("mdAutoRawTags", "md", (data, content) => {
12
+ export default function mdAutoRawTags($config) {
13
+ $config.addPreprocessor("mdAutoRawTags", "md", (data, content) => {
14
14
  return transformAutoRaw(content);
15
15
  });
16
16
  }
@@ -16,8 +16,8 @@ export function transformUncommentAttrs(content) {
16
16
  return content;
17
17
  }
18
18
 
19
- export default function mdAutoUncommentAttrs(eleventyConfig) {
20
- eleventyConfig.amendLibrary("md", (mdLib) => {
19
+ export default function mdAutoUncommentAttrs($config) {
20
+ $config.amendLibrary("md", (mdLib) => {
21
21
  mdLib.core.ruler.before("normalize", "uncomment_attrs", (state) => {
22
22
  state.src = transformUncommentAttrs(state.src);
23
23
  });
@@ -31,8 +31,8 @@ export const siteData = (data) => {
31
31
  };
32
32
  };
33
33
 
34
- export default function (eleventyConfig) {
35
- eleventyConfig.addGlobalData("eleventyComputed", {
34
+ export default function ($config) {
35
+ $config.addGlobalData("eleventyComputed", {
36
36
  site: (data) => ({
37
37
  ...siteData(data),
38
38
  prod: process.env.ELEVENTY_RUN_MODE === "build",
@@ -6,13 +6,13 @@
6
6
  import { readFileSync } from "fs";
7
7
  import YAML from "js-yaml";
8
8
 
9
- export default function (eleventyConfig) {
9
+ export default function ($config) {
10
10
  // Virtual pages
11
- const pages = YAML.load(readFileSync(eleventyConfig.directories.input + "/pages.yaml", "utf8"));
11
+ const pages = YAML.load(readFileSync($config.directories.input + "/pages.yaml", "utf8"));
12
12
  for (const [index, data] of pages.entries()) {
13
13
  const virtualSlug = data.permalink ? data.permalink + "index" : index;
14
14
  // console.log(data, virtualSlug);
15
- eleventyConfig.addTemplate("." + virtualSlug + ".md", "", data);
15
+ $config.addTemplate("." + virtualSlug + ".md", "", data);
16
16
  }
17
17
  }
18
18
  //```
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@anyblades/buildawesome-kit-plugin",
3
- "version": "1.3.0-alpha",
3
+ "version": "1.3.0-alpha.2",
4
4
  "type": "module",
5
5
  "main": "./plugin.js",
6
6
  "exports": {
package/plugin/plugin.js CHANGED
@@ -8,7 +8,7 @@ export const discoverModules = (dir) =>
8
8
  .map((f) => [f.replace(/\.js$/, ""), true]),
9
9
  );
10
10
 
11
- export default async function (eleventyConfig, userOptions) {
11
+ export default async function ($config, userOptions) {
12
12
  //```<!--section:code,def-options-->```js
13
13
  const defaultOptions = { mdAutoRawTags: false };
14
14
  //```<!--section:code-->```js
@@ -31,7 +31,7 @@ export default async function (eleventyConfig, userOptions) {
31
31
  try {
32
32
  if (filterName == "fetch") await import("@11ty/eleventy-fetch");
33
33
  const filterFunc = (await import("./filters/" + filterName + ".js")).default;
34
- eleventyConfig.addFilter(filterName, filterFunc);
34
+ $config.addFilter(filterName, filterFunc);
35
35
  } catch (error) {
36
36
  console.log("^ N/A ^");
37
37
  }
@@ -44,7 +44,7 @@ export default async function (eleventyConfig, userOptions) {
44
44
  console.log("Loading feature: " + featureName + "...");
45
45
  try {
46
46
  const featureConfig = (await import("./features/" + featureName + ".js")).default;
47
- featureConfig(eleventyConfig);
47
+ featureConfig($config);
48
48
  } catch (error) {
49
49
  console.log("^ N/A ^");
50
50
  }