@anydigital/eleventy-bricks 1.0.0-alpha.13 → 1.0.0-alpha.14
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
|
@@ -50,13 +50,12 @@ Import only the specific helpers you need without using the plugin:
|
|
|
50
50
|
|
|
51
51
|
**ES Modules:**
|
|
52
52
|
```javascript
|
|
53
|
-
import { bricks, mdAutoRawTags, mdAutoNl2br,
|
|
53
|
+
import { bricks, mdAutoRawTags, mdAutoNl2br, setAttrFilter, byAttrFilter, siteData } from "@anydigital/eleventy-bricks";
|
|
54
54
|
|
|
55
55
|
export default function(eleventyConfig) {
|
|
56
56
|
bricks(eleventyConfig);
|
|
57
57
|
mdAutoRawTags(eleventyConfig);
|
|
58
58
|
mdAutoNl2br(eleventyConfig);
|
|
59
|
-
fragments(eleventyConfig);
|
|
60
59
|
setAttrFilter(eleventyConfig);
|
|
61
60
|
byAttrFilter(eleventyConfig);
|
|
62
61
|
siteData(eleventyConfig);
|
|
@@ -67,13 +66,12 @@ export default function(eleventyConfig) {
|
|
|
67
66
|
|
|
68
67
|
**CommonJS:**
|
|
69
68
|
```javascript
|
|
70
|
-
const { bricks, mdAutoRawTags, mdAutoNl2br,
|
|
69
|
+
const { bricks, mdAutoRawTags, mdAutoNl2br, setAttrFilter, byAttrFilter, siteData } = require("@anydigital/eleventy-bricks");
|
|
71
70
|
|
|
72
71
|
module.exports = async function(eleventyConfig) {
|
|
73
72
|
await bricks(eleventyConfig);
|
|
74
73
|
await mdAutoRawTags(eleventyConfig);
|
|
75
74
|
await mdAutoNl2br(eleventyConfig);
|
|
76
|
-
await fragments(eleventyConfig);
|
|
77
75
|
await setAttrFilter(eleventyConfig);
|
|
78
76
|
await byAttrFilter(eleventyConfig);
|
|
79
77
|
await siteData(eleventyConfig);
|
|
@@ -93,7 +91,6 @@ When using the plugin (Option 1), you can configure which helpers to enable:
|
|
|
93
91
|
| `bricks` | boolean | `false` | Enable the bricks system for dependency management |
|
|
94
92
|
| `mdAutoRawTags` | boolean | `false` | Enable the mdAutoRawTags preprocessor for Markdown files |
|
|
95
93
|
| `mdAutoNl2br` | boolean | `false` | Enable the mdAutoNl2br preprocessor to convert \n to `<br>` tags |
|
|
96
|
-
| `fragments` | boolean | `false` | Enable the fragment shortcode for including content from fragments |
|
|
97
94
|
| `setAttrFilter` | boolean | `false` | Enable the setAttr filter for overriding object attributes |
|
|
98
95
|
| `byAttrFilter` | boolean | `false` | Enable the byAttr filter for filtering collections by attribute values |
|
|
99
96
|
| `siteData` | boolean | `false` | Enable site.year and site.isProd global data |
|
|
@@ -285,80 +282,6 @@ Will render as:
|
|
|
285
282
|
|
|
286
283
|
**Note:** This processes literal `\n` sequences (backslash followed by 'n'), not actual newline characters. Type `\n` in your source files where you want line breaks.
|
|
287
284
|
|
|
288
|
-
### fragment
|
|
289
|
-
|
|
290
|
-
A shortcode that includes content from fragment files stored in the `_fragments` directory. The content will be processed by the template engine.
|
|
291
|
-
|
|
292
|
-
**Why use this?**
|
|
293
|
-
|
|
294
|
-
Fragments allow you to organize reusable content snippets in a dedicated directory and include them in your templates. This is useful for:
|
|
295
|
-
- Reusable content blocks
|
|
296
|
-
- Shared template sections
|
|
297
|
-
- Component-like content organization
|
|
298
|
-
|
|
299
|
-
**Usage:**
|
|
300
|
-
|
|
301
|
-
1. Enable `fragments` in your Eleventy config:
|
|
302
|
-
|
|
303
|
-
```javascript
|
|
304
|
-
import { fragments } from "@anydigital/eleventy-bricks";
|
|
305
|
-
|
|
306
|
-
export default function(eleventyConfig) {
|
|
307
|
-
fragments(eleventyConfig);
|
|
308
|
-
// Or use as plugin:
|
|
309
|
-
// eleventyConfig.addPlugin(eleventyBricks, { fragments: true });
|
|
310
|
-
}
|
|
311
|
-
```
|
|
312
|
-
|
|
313
|
-
2. Create fragment files in the `_fragments` directory (relative to your input directory):
|
|
314
|
-
|
|
315
|
-
```
|
|
316
|
-
your-project/
|
|
317
|
-
_fragments/
|
|
318
|
-
header.njk
|
|
319
|
-
footer.njk
|
|
320
|
-
callout.md
|
|
321
|
-
```
|
|
322
|
-
|
|
323
|
-
3. Use the `fragment` shortcode in your templates:
|
|
324
|
-
|
|
325
|
-
```njk
|
|
326
|
-
{% fragment "header.njk" %}
|
|
327
|
-
|
|
328
|
-
<main>
|
|
329
|
-
<!-- Your content -->
|
|
330
|
-
</main>
|
|
331
|
-
|
|
332
|
-
{% fragment "footer.njk" %}
|
|
333
|
-
```
|
|
334
|
-
|
|
335
|
-
**Parameters:**
|
|
336
|
-
|
|
337
|
-
- `path`: The path to the fragment file relative to the `_fragments` directory
|
|
338
|
-
|
|
339
|
-
**Features:**
|
|
340
|
-
|
|
341
|
-
- Reads files from `_fragments` directory in your input directory
|
|
342
|
-
- Content is processed by the template engine
|
|
343
|
-
- Supports any template language that Eleventy supports
|
|
344
|
-
- Shows helpful error comment if fragment is not found
|
|
345
|
-
|
|
346
|
-
**Example:**
|
|
347
|
-
|
|
348
|
-
Create `_fragments/callout.njk`:
|
|
349
|
-
```njk
|
|
350
|
-
<div class="callout callout-{{ type | default('info') }}">
|
|
351
|
-
{{ content }}
|
|
352
|
-
</div>
|
|
353
|
-
```
|
|
354
|
-
|
|
355
|
-
Use it in your template:
|
|
356
|
-
```njk
|
|
357
|
-
{% set type = "warning" %}
|
|
358
|
-
{% set content = "This is important!" %}
|
|
359
|
-
{% fragment "callout.njk" %}
|
|
360
|
-
```
|
|
361
|
-
|
|
362
285
|
### setAttr
|
|
363
286
|
|
|
364
287
|
A filter that creates a new object with an overridden attribute value. This is useful for modifying data objects in templates without mutating the original.
|
|
@@ -595,7 +518,7 @@ The plugin also exports the following for advanced usage:
|
|
|
595
518
|
|
|
596
519
|
## Starter Configuration Files
|
|
597
520
|
|
|
598
|
-
The package includes pre-configured starter files in `node_modules/@anydigital/eleventy-bricks/src
|
|
521
|
+
The package includes pre-configured starter files in `node_modules/@anydigital/eleventy-bricks/src/` that you can symlink to your project for quick setup:
|
|
599
522
|
|
|
600
523
|
### Available Starter Files
|
|
601
524
|
|
|
@@ -616,7 +539,7 @@ npm install @11ty/eleventy-navigation markdown-it markdown-it-anchor js-yaml min
|
|
|
616
539
|
|
|
617
540
|
**Symlink to your project:**
|
|
618
541
|
```bash
|
|
619
|
-
ln -s node_modules/@anydigital/eleventy-bricks/src/
|
|
542
|
+
ln -s node_modules/@anydigital/eleventy-bricks/src/eleventy.config.js eleventy.config.js
|
|
620
543
|
```
|
|
621
544
|
|
|
622
545
|
#### admin/index.html
|
|
@@ -626,7 +549,7 @@ A ready-to-use Sveltia CMS admin interface for content management.
|
|
|
626
549
|
**Symlink to your project:**
|
|
627
550
|
```bash
|
|
628
551
|
mkdir -p admin
|
|
629
|
-
ln -s ../node_modules/@anydigital/eleventy-bricks/src/
|
|
552
|
+
ln -s ../node_modules/@anydigital/eleventy-bricks/src/admin/index.html admin/index.html
|
|
630
553
|
```
|
|
631
554
|
|
|
632
555
|
### Benefits of Symlinking
|
|
@@ -641,9 +564,9 @@ ln -s ../node_modules/@anydigital/eleventy-bricks/src/starter/admin/index.html a
|
|
|
641
564
|
If you prefer to customize the configurations extensively, you can copy the files instead:
|
|
642
565
|
|
|
643
566
|
```bash
|
|
644
|
-
cp node_modules/@anydigital/eleventy-bricks/src/
|
|
567
|
+
cp node_modules/@anydigital/eleventy-bricks/src/eleventy.config.js .
|
|
645
568
|
mkdir -p admin
|
|
646
|
-
cp node_modules/@anydigital/eleventy-bricks/src/
|
|
569
|
+
cp node_modules/@anydigital/eleventy-bricks/src/admin/index.html admin/
|
|
647
570
|
```
|
|
648
571
|
|
|
649
572
|
## CLI Helper Commands
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@anydigital/eleventy-bricks",
|
|
3
|
-
"version": "1.0.0-alpha.
|
|
3
|
+
"version": "1.0.0-alpha.14",
|
|
4
4
|
"description": "A collection of helpful utilities and filters for Eleventy (11ty)",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./src/index.js",
|
|
@@ -46,6 +46,6 @@
|
|
|
46
46
|
"node": ">=18.0.0"
|
|
47
47
|
},
|
|
48
48
|
"_downloadFiles": {
|
|
49
|
-
"https://raw.githubusercontent.com/danurbanowicz/eleventy-sveltia-cms-starter/refs/heads/master/admin/index.html": "src/
|
|
49
|
+
"https://raw.githubusercontent.com/danurbanowicz/eleventy-sveltia-cms-starter/refs/heads/master/admin/index.html": "src/admin/index.html"
|
|
50
50
|
}
|
|
51
51
|
}
|
package/src/index.cjs
CHANGED
|
@@ -10,7 +10,7 @@ module.exports = async function eleventyBricksPlugin(eleventyConfig, options) {
|
|
|
10
10
|
};
|
|
11
11
|
|
|
12
12
|
// Export individual helpers for granular usage
|
|
13
|
-
['bricks', 'mdAutoRawTags', 'mdAutoNl2br', '
|
|
13
|
+
['bricks', 'mdAutoRawTags', 'mdAutoNl2br', 'setAttrFilter', 'byAttrFilter', 'siteData'].forEach(name => {
|
|
14
14
|
module.exports[name] = async (eleventyConfig) => {
|
|
15
15
|
const module = await import('./index.js');
|
|
16
16
|
return module[name](eleventyConfig);
|
package/src/index.js
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { bricks } from "./bricks.js";
|
|
2
2
|
import { mdAutoRawTags, mdAutoNl2br, transformAutoRaw, transformNl2br } from "./markdown.js";
|
|
3
|
-
import { fragments } from "./fragments.js";
|
|
4
3
|
import { setAttrFilter } from "./setAttrFilter.js";
|
|
5
4
|
import { byAttrFilter } from "./byAttrFilter.js";
|
|
6
5
|
import { siteData } from "./siteData.js";
|
|
@@ -16,18 +15,17 @@ import { siteData } from "./siteData.js";
|
|
|
16
15
|
* @param {boolean} options.bricks - Enable bricks system with dependencies injection (default: false)
|
|
17
16
|
* @param {boolean} options.mdAutoRawTags - Enable mdAutoRawTags preprocessor (default: false)
|
|
18
17
|
* @param {boolean} options.mdAutoNl2br - Enable mdAutoNl2br for \n to <br> conversion (default: false)
|
|
19
|
-
* @param {boolean} options.fragments - Enable fragment shortcode (default: false)
|
|
20
18
|
* @param {boolean} options.setAttrFilter - Enable setAttr filter (default: false)
|
|
21
19
|
* @param {boolean} options.byAttrFilter - Enable byAttr filter (default: false)
|
|
22
20
|
* @param {boolean} options.siteData - Enable site.year and site.isProd global data (default: false)
|
|
23
21
|
*/
|
|
24
22
|
export default function eleventyBricksPlugin(eleventyConfig, options = {}) {
|
|
25
|
-
const plugins = { bricks, mdAutoRawTags, mdAutoNl2br,
|
|
23
|
+
const plugins = { bricks, mdAutoRawTags, mdAutoNl2br, setAttrFilter, byAttrFilter, siteData };
|
|
26
24
|
Object.entries(options).forEach(([key, enabled]) => enabled && plugins[key]?.(eleventyConfig));
|
|
27
25
|
}
|
|
28
26
|
|
|
29
27
|
// Export individual helpers for granular usage
|
|
30
|
-
export { bricks, mdAutoRawTags, mdAutoNl2br,
|
|
28
|
+
export { bricks, mdAutoRawTags, mdAutoNl2br, setAttrFilter, byAttrFilter, siteData };
|
|
31
29
|
|
|
32
30
|
// Export transform functions for advanced usage
|
|
33
31
|
export { transformAutoRaw, transformNl2br };
|
package/src/fragments.js
DELETED
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
import { readFileSync } from "fs";
|
|
2
|
-
import { join } from "path";
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* fragment shortcode - Include content from fragments
|
|
6
|
-
*
|
|
7
|
-
* This shortcode reads a file from the _fragments directory and includes
|
|
8
|
-
* its content. The content will be processed by the template engine.
|
|
9
|
-
*
|
|
10
|
-
* @param {Object} eleventyConfig - The Eleventy configuration object
|
|
11
|
-
*/
|
|
12
|
-
export function fragments(eleventyConfig) {
|
|
13
|
-
eleventyConfig.addShortcode("fragment", function(path) {
|
|
14
|
-
// Get the input directory from Eleventy's context
|
|
15
|
-
const inputDir = this.page?.inputPath
|
|
16
|
-
? join(process.cwd(), eleventyConfig.dir?.input || ".")
|
|
17
|
-
: process.cwd();
|
|
18
|
-
|
|
19
|
-
// Construct the full path to the fragment file
|
|
20
|
-
const fragmentPath = join(inputDir, "_fragments", path);
|
|
21
|
-
|
|
22
|
-
try {
|
|
23
|
-
// Read the fragment file
|
|
24
|
-
const content = readFileSync(fragmentPath, "utf8");
|
|
25
|
-
|
|
26
|
-
// Return content to be processed by the template engine
|
|
27
|
-
return content;
|
|
28
|
-
} catch (error) {
|
|
29
|
-
console.error(`Error reading fragment at ${fragmentPath}:`, error.message);
|
|
30
|
-
return `<!-- Fragment not found: ${path} -->`;
|
|
31
|
-
}
|
|
32
|
-
});
|
|
33
|
-
}
|
|
34
|
-
|
|
File without changes
|