@anydigital/11ty-bricks 1.0.0-alpha → 1.0.0-alpha.11

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
@@ -21,8 +21,8 @@ Import and use the entire plugin. You can configure which helpers to enable usin
21
21
  import eleventyBricks from "@anydigital/11ty-bricks";
22
22
 
23
23
  export default function(eleventyConfig) {
24
- eleventyBricks(eleventyConfig, {
25
- autoRaw: true // Enable autoRaw preprocessor (default: false)
24
+ eleventyConfig.addPlugin(eleventyBricks, {
25
+ mdAutoRawTags: true // Enable mdAutoRawTags preprocessor (default: false)
26
26
  });
27
27
 
28
28
  // Your other configuration...
@@ -34,8 +34,8 @@ export default function(eleventyConfig) {
34
34
  const eleventyBricks = require("@anydigital/11ty-bricks");
35
35
 
36
36
  module.exports = function(eleventyConfig) {
37
- eleventyBricks(eleventyConfig, {
38
- autoRaw: true // Enable autoRaw preprocessor (default: false)
37
+ eleventyConfig.addPlugin(eleventyBricks, {
38
+ mdAutoRawTags: true // Enable mdAutoRawTags preprocessor (default: false)
39
39
  });
40
40
 
41
41
  // Your other configuration...
@@ -48,10 +48,16 @@ Import only the specific helpers you need without using the plugin:
48
48
 
49
49
  **ES Modules:**
50
50
  ```javascript
51
- import { autoRaw } from "@anydigital/11ty-bricks";
51
+ import { bricks, mdAutoRawTags, mdAutoNl2br, fragments, setAttrFilter, byAttrFilter, siteData } from "@anydigital/11ty-bricks";
52
52
 
53
53
  export default function(eleventyConfig) {
54
- autoRaw(eleventyConfig);
54
+ bricks(eleventyConfig);
55
+ mdAutoRawTags(eleventyConfig);
56
+ mdAutoNl2br(eleventyConfig);
57
+ fragments(eleventyConfig);
58
+ setAttrFilter(eleventyConfig);
59
+ byAttrFilter(eleventyConfig);
60
+ siteData(eleventyConfig);
55
61
 
56
62
  // Your other configuration...
57
63
  }
@@ -59,10 +65,16 @@ export default function(eleventyConfig) {
59
65
 
60
66
  **CommonJS:**
61
67
  ```javascript
62
- const { autoRaw } = require("@anydigital/11ty-bricks");
68
+ const { bricks, mdAutoRawTags, mdAutoNl2br, fragments, setAttrFilter, byAttrFilter, siteData } = require("@anydigital/11ty-bricks");
63
69
 
64
70
  module.exports = function(eleventyConfig) {
65
- autoRaw(eleventyConfig);
71
+ bricks(eleventyConfig);
72
+ mdAutoRawTags(eleventyConfig);
73
+ mdAutoNl2br(eleventyConfig);
74
+ fragments(eleventyConfig);
75
+ setAttrFilter(eleventyConfig);
76
+ byAttrFilter(eleventyConfig);
77
+ siteData(eleventyConfig);
66
78
 
67
79
  // Your other configuration...
68
80
  };
@@ -74,33 +86,618 @@ When using the plugin (Option 1), you can configure which helpers to enable:
74
86
 
75
87
  | Option | Type | Default | Description |
76
88
  |--------|------|---------|-------------|
77
- | `autoRaw` | boolean | `false` | Enable the autoRaw preprocessor for Markdown files |
89
+ | `bricks` | boolean | `false` | Enable the bricks system for dependency management |
90
+ | `mdAutoRawTags` | boolean | `false` | Enable the mdAutoRawTags preprocessor for Markdown files |
91
+ | `mdAutoNl2br` | boolean | `false` | Enable the mdAutoNl2br preprocessor to convert \n to `<br>` tags |
92
+ | `fragments` | boolean | `false` | Enable the fragment shortcode for including content from fragments |
93
+ | `setAttrFilter` | boolean | `false` | Enable the setAttr filter for overriding object attributes |
94
+ | `byAttrFilter` | boolean | `false` | Enable the byAttr filter for filtering collections by attribute values |
95
+ | `siteData` | boolean | `false` | Enable site.year and site.isProd global data |
78
96
 
79
97
  **Example:**
80
98
  ```javascript
81
- eleventyBricks(eleventyConfig, {
82
- autoRaw: true
99
+ eleventyConfig.addPlugin(eleventyBricks, {
100
+ bricks: true,
101
+ mdAutoRawTags: true,
102
+ byAttrFilter: true,
103
+ siteData: true
83
104
  });
84
105
  ```
85
106
 
86
- ## Available Helpers
107
+ ## Available 11ty Helpers
87
108
 
88
- ### autoRaw
109
+ ### bricks
110
+
111
+ A dependency management system for Eleventy that automatically collects and injects CSS and JavaScript dependencies (both external and inline) per page. This allows brick components to declare their dependencies, and the system will inject them in the correct location in your HTML.
112
+
113
+ **Why use this?**
114
+
115
+ When building reusable components (bricks) in Eleventy, you often need to include CSS and JavaScript dependencies. Instead of manually adding these to every page, `bricks` automatically:
116
+ - Collects dependencies from all bricks used on a page
117
+ - Categorizes them (external CSS, external JS, inline styles, inline scripts)
118
+ - Injects them in the correct location in your HTML output
119
+
120
+ **How it works:**
121
+
122
+ 1. Use the `bricksDependencies` shortcode in your base template to mark where dependencies should be injected
123
+ 2. Use the `brick` shortcode to register and render brick components that declare their dependencies
124
+ 3. The system automatically collects all dependencies and injects them when the page is built
125
+
126
+ **Usage:**
127
+
128
+ 1. Enable `bricks` in your Eleventy config:
129
+
130
+ ```javascript
131
+ import { bricks } from "@anydigital/11ty-bricks";
132
+
133
+ export default function(eleventyConfig) {
134
+ bricks(eleventyConfig);
135
+ // Or use as plugin:
136
+ // eleventyConfig.addPlugin(eleventyBricks, { bricks: true });
137
+ }
138
+ ```
139
+
140
+ 2. Add the `bricksDependencies` shortcode in your base template (typically in the `<head>` section):
141
+
142
+ ```njk
143
+ <head>
144
+ <meta charset="UTF-8">
145
+ <title>My Site</title>
146
+ {% bricksDependencies [
147
+ ... (global dependencies can be set here) ...
148
+ ] %}
149
+ <!-- Other head content -->
150
+ </head>
151
+ ```
152
+
153
+ 3. Create brick components that declare their dependencies:
154
+
155
+ ```javascript
156
+ // myBrick.js
157
+ export default {
158
+ dependencies: [
159
+ 'https://cdn.example.com/library.css',
160
+ 'https://cdn.example.com/library.js'
161
+ ],
162
+ style: `
163
+ .my-component { color: blue; }
164
+ `,
165
+ script: `
166
+ console.log('Component initialized');
167
+ `,
168
+ render: function() {
169
+ return '<div class="my-component">Hello World</div>';
170
+ }
171
+ };
172
+ ```
173
+
174
+ 4. Use the `brick` shortcode in your templates:
175
+
176
+ ```njk
177
+ {% set myBrick = require('./myBrick.js') %}
178
+ {% brick myBrick %}
179
+ ```
180
+
181
+ **Brick Component Structure:**
182
+
183
+ A brick component is a JavaScript object with the following optional properties:
184
+
185
+ - `dependencies`: Array of URLs to external CSS or JavaScript files (e.g., `['https://cdn.example.com/style.css', 'https://cdn.example.com/script.js']`)
186
+ - `style`: String containing inline CSS
187
+ - `script`: String containing inline JavaScript
188
+ - `render`: Function that returns the HTML markup for the component
189
+
190
+ **Output:**
191
+
192
+ The system will automatically inject all dependencies in the order they were registered:
193
+
194
+ ```html
195
+ <head>
196
+ <meta charset="UTF-8">
197
+ <title>My Site</title>
198
+ <link rel="stylesheet" href="https://cdn.example.com/library.css">
199
+ <style>.my-component { color: blue; }</style>
200
+ <script src="https://cdn.example.com/library.js"></script>
201
+ <script>console.log('Component initialized');</script>
202
+ <!-- Other head content -->
203
+ </head>
204
+ ```
205
+
206
+ **Features:**
207
+
208
+ - Automatic dependency collection per page
209
+ - Categorizes dependencies (CSS vs JS, external vs inline)
210
+ - Deduplicates dependencies (using Sets internally)
211
+ - Works with both external URLs and inline code
212
+ - Clears registry before each build to prevent stale data
213
+
214
+ ### mdAutoRawTags
89
215
 
90
216
  Prevents Nunjucks syntax from being processed in Markdown files by automatically wrapping `{{`, `}}`, `{%`, and `%}` with `{% raw %}` tags.
91
217
 
92
218
  **Why use this?**
93
219
 
94
- When writing documentation or tutorials about templating in Markdown files, you often want to show Nunjucks/Liquid syntax as literal text. This helper automatically escapes these special characters so they display as-is instead of being processed by the template engine.
220
+ When writing documentation or tutorials about templating in Markdown files, you often want to show Nunjucks/Liquid syntax as literal text. This preprocessor automatically escapes these special characters so they display as-is instead of being processed by the template engine.
221
+
222
+ **Usage:**
223
+
224
+ 1. Enable `mdAutoRawTags` in your Eleventy config:
225
+
226
+ ```javascript
227
+ import { mdAutoRawTags } from "@anydigital/11ty-bricks";
228
+
229
+ export default function(eleventyConfig) {
230
+ mdAutoRawTags(eleventyConfig);
231
+ // Or use as plugin:
232
+ // eleventyConfig.addPlugin(eleventyBricks, { mdAutoRawTags: true });
233
+ }
234
+ ```
95
235
 
96
236
  **Example:**
97
237
 
98
- Before `autoRaw`, writing this in Markdown:
238
+ Before `mdAutoRawTags`, writing this in Markdown:
99
239
  ```markdown
100
240
  Use {{ variable }} to output variables.
101
241
  ```
102
242
 
103
- Would try to process `{{ variable }}` as a template variable. With `autoRaw`, it displays exactly as written.
243
+ Would try to process `{{ variable }}` as a template variable. With `mdAutoRawTags`, it displays exactly as written.
244
+
245
+ ### mdAutoNl2br
246
+
247
+ Automatically converts `\n` sequences to `<br>` tags in Markdown content. This is particularly useful for adding line breaks inside Markdown tables where standard newlines don't work.
248
+
249
+ **Why use this?**
250
+
251
+ Markdown tables don't support multi-line content in cells. By using `\n` in your content, this preprocessor will convert it to `<br>` tags, allowing you to display line breaks within table cells and other content.
252
+
253
+ **Usage:**
254
+
255
+ 1. Enable `mdAutoNl2br` in your Eleventy config:
256
+
257
+ ```javascript
258
+ import { mdAutoNl2br } from "@anydigital/11ty-bricks";
259
+
260
+ export default function(eleventyConfig) {
261
+ mdAutoNl2br(eleventyConfig);
262
+ // Or use as plugin:
263
+ // eleventyConfig.addPlugin(eleventyBricks, { mdAutoNl2br: true });
264
+ }
265
+ ```
266
+
267
+ **Example:**
268
+
269
+ In your Markdown file:
270
+ ```markdown
271
+ | Column 1 | Column 2 |
272
+ |----------|----------|
273
+ | Line 1\nLine 2\nLine 3 | Another cell\nWith multiple lines |
274
+ ```
275
+
276
+ Will render as:
277
+ ```html
278
+ <td>Line 1<br>Line 2<br>Line 3</td>
279
+ <td>Another cell<br>With multiple lines</td>
280
+ ```
281
+
282
+ **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.
283
+
284
+ ### fragment
285
+
286
+ A shortcode that includes content from fragment files stored in the `_fragments` directory. The content will be processed by the template engine.
287
+
288
+ **Why use this?**
289
+
290
+ Fragments allow you to organize reusable content snippets in a dedicated directory and include them in your templates. This is useful for:
291
+ - Reusable content blocks
292
+ - Shared template sections
293
+ - Component-like content organization
294
+
295
+ **Usage:**
296
+
297
+ 1. Enable `fragments` in your Eleventy config:
298
+
299
+ ```javascript
300
+ import { fragments } from "@anydigital/11ty-bricks";
301
+
302
+ export default function(eleventyConfig) {
303
+ fragments(eleventyConfig);
304
+ // Or use as plugin:
305
+ // eleventyConfig.addPlugin(eleventyBricks, { fragments: true });
306
+ }
307
+ ```
308
+
309
+ 2. Create fragment files in the `_fragments` directory (relative to your input directory):
310
+
311
+ ```
312
+ your-project/
313
+ _fragments/
314
+ header.njk
315
+ footer.njk
316
+ callout.md
317
+ ```
318
+
319
+ 3. Use the `fragment` shortcode in your templates:
320
+
321
+ ```njk
322
+ {% fragment "header.njk" %}
323
+
324
+ <main>
325
+ <!-- Your content -->
326
+ </main>
327
+
328
+ {% fragment "footer.njk" %}
329
+ ```
330
+
331
+ **Parameters:**
332
+
333
+ - `path`: The path to the fragment file relative to the `_fragments` directory
334
+
335
+ **Features:**
336
+
337
+ - Reads files from `_fragments` directory in your input directory
338
+ - Content is processed by the template engine
339
+ - Supports any template language that Eleventy supports
340
+ - Shows helpful error comment if fragment is not found
341
+
342
+ **Example:**
343
+
344
+ Create `_fragments/callout.njk`:
345
+ ```njk
346
+ <div class="callout callout-{{ type | default('info') }}">
347
+ {{ content }}
348
+ </div>
349
+ ```
350
+
351
+ Use it in your template:
352
+ ```njk
353
+ {% set type = "warning" %}
354
+ {% set content = "This is important!" %}
355
+ {% fragment "callout.njk" %}
356
+ ```
357
+
358
+ ### setAttr
359
+
360
+ 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.
361
+
362
+ **Why use this?**
363
+
364
+ When working with Eleventy data, you sometimes need to modify an object's properties for a specific use case. The `setAttr` filter provides a clean way to create a modified copy of an object without affecting the original.
365
+
366
+ **Usage:**
367
+
368
+ 1. Enable `setAttr` in your Eleventy config:
369
+
370
+ ```javascript
371
+ import { setAttrFilter } from "@anydigital/11ty-bricks";
372
+
373
+ export default function(eleventyConfig) {
374
+ setAttrFilter(eleventyConfig);
375
+ // Or use as plugin:
376
+ // eleventyConfig.addPlugin(eleventyBricks, { setAttrFilter: true });
377
+ }
378
+ ```
379
+
380
+ 2. Use the filter in your templates:
381
+
382
+ ```njk
383
+ {# Create a modified version of a page object #}
384
+ {% set modifiedPage = page | setAttr('title', 'New Title') %}
385
+
386
+ <h1>{{ modifiedPage.title }}</h1>
387
+ <p>Original title: {{ page.title }}</p>
388
+ ```
389
+
390
+ **Parameters:**
391
+
392
+ - `obj`: The object to modify
393
+ - `key`: The attribute name to set (string)
394
+ - `value`: The value to set for the attribute (any type)
395
+
396
+ **Returns:**
397
+
398
+ A new object with the specified attribute set to the given value. The original object is not modified.
399
+
400
+ **Features:**
401
+
402
+ - Non-mutating: Creates a new object, leaving the original unchanged
403
+ - Works with any object type
404
+ - Supports any attribute name and value type
405
+ - Can be chained with other filters
406
+
407
+ **Examples:**
408
+
409
+ ```njk
410
+ {# Override a single attribute #}
411
+ {% set updatedPost = post | setAttr('featured', true) %}
412
+
413
+ {# Chain multiple setAttr filters #}
414
+ {% set modifiedPost = post
415
+ | setAttr('category', 'blog')
416
+ | setAttr('priority', 1)
417
+ %}
418
+
419
+ {# Use in loops #}
420
+ {% for item in collection %}
421
+ {% set enhancedItem = item | setAttr('processed', true) %}
422
+ {# ... use enhancedItem ... #}
423
+ {% endfor %}
424
+ ```
425
+
426
+ ### byAttr
427
+
428
+ A filter that filters collection items by attribute value. It checks if an item's attribute matches a target value. If the attribute is an array, it checks if the array includes the target value.
429
+
430
+ **Why use this?**
431
+
432
+ When working with Eleventy collections, you often need to filter items based on front matter data. The `byAttr` filter provides a flexible way to filter by any attribute, with special handling for array attributes (like tags).
433
+
434
+ **Usage:**
435
+
436
+ 1. Enable `byAttr` in your Eleventy config:
437
+
438
+ ```javascript
439
+ import { byAttrFilter } from "@anydigital/11ty-bricks";
440
+
441
+ export default function(eleventyConfig) {
442
+ byAttrFilter(eleventyConfig);
443
+ // Or use as plugin:
444
+ // eleventyConfig.addPlugin(eleventyBricks, { byAttrFilter: true });
445
+ }
446
+ ```
447
+
448
+ 2. Use the filter in your templates:
449
+
450
+ **Filter by exact attribute match:**
451
+ ```njk
452
+ {# Get all posts with category 'blog' #}
453
+ {% set blogPosts = collections.all | byAttr('category', 'blog') %}
454
+
455
+ {% for post in blogPosts %}
456
+ <h2>{{ post.data.title }}</h2>
457
+ {% endfor %}
458
+ ```
459
+
460
+ **Filter by array attribute (tags):**
461
+ ```njk
462
+ {# Get all posts that include 'javascript' tag #}
463
+ {% set jsPosts = collections.all | byAttr('tags', 'javascript') %}
464
+
465
+ {% for post in jsPosts %}
466
+ <h2>{{ post.data.title }}</h2>
467
+ {% endfor %}
468
+ ```
469
+
470
+ **Parameters:**
471
+
472
+ - `collection`: The collection to filter (array of items)
473
+ - `attrName`: The attribute name to check (string)
474
+ - `targetValue`: The value to match against (any type)
475
+
476
+ **Features:**
477
+
478
+ - Works with any attribute in front matter
479
+ - Handles both `item.data.attrName` and `item.attrName` patterns
480
+ - Special handling for array attributes (uses `includes()` check)
481
+ - Returns empty array if collection is invalid
482
+ - Filters out items without the specified attribute
483
+
484
+ **Examples:**
485
+
486
+ Front matter:
487
+ ```yaml
488
+ ---
489
+ title: My Post
490
+ category: blog
491
+ tags: [javascript, tutorial, beginner]
492
+ priority: 1
493
+ ---
494
+ ```
495
+
496
+ Template usage:
497
+ ```njk
498
+ {# Filter by category #}
499
+ {% set blogPosts = collections.all | byAttr('category', 'blog') %}
500
+
501
+ {# Filter by tag (array) #}
502
+ {% set jsTutorials = collections.all | byAttr('tags', 'javascript') %}
503
+
504
+ {# Filter by numeric value #}
505
+ {% set highPriority = collections.all | byAttr('priority', 1) %}
506
+
507
+ {# Chain filters #}
508
+ {% set recentBlogPosts = collections.all | byAttr('category', 'blog') | reverse | limit(5) %}
509
+ ```
510
+
511
+ ### siteData
512
+
513
+ Adds global site data to your Eleventy project, providing commonly needed values that can be accessed in all templates.
514
+
515
+ **Why use this?**
516
+
517
+ Many websites need access to the current year (for copyright notices) and environment information (to conditionally enable features based on production vs development). This helper provides these as global `site` data without manually setting them up.
518
+
519
+ **Usage:**
520
+
521
+ 1. Enable `siteData` in your Eleventy config:
522
+
523
+ ```javascript
524
+ import { siteData } from "@anydigital/11ty-bricks";
525
+
526
+ export default function(eleventyConfig) {
527
+ siteData(eleventyConfig);
528
+ // Or use as plugin:
529
+ // eleventyConfig.addPlugin(eleventyBricks, { siteData: true });
530
+ }
531
+ ```
532
+
533
+ 2. Use the global data in your templates:
534
+
535
+ **Current Year:**
536
+ ```njk
537
+ <footer>
538
+ <p>&copy; {{ site.year }} Your Company Name. All rights reserved.</p>
539
+ </footer>
540
+ ```
541
+
542
+ **Environment Check:**
543
+ ```njk
544
+ {% if site.isProd %}
545
+ <!-- Production-only features -->
546
+ <script async src="https://www.googletagmanager.com/gtag/js?id=GA_TRACKING_ID"></script>
547
+ {% else %}
548
+ <!-- Development-only features -->
549
+ <div class="dev-toolbar">Development Mode</div>
550
+ {% endif %}
551
+ ```
552
+
553
+ **Available Data:**
554
+
555
+ - `site.year`: The current year as a number (e.g., `2026`)
556
+ - `site.isProd`: Boolean indicating if running in production mode (`true` for `eleventy build`, `false` for `eleventy serve`)
557
+
558
+ **Features:**
559
+
560
+ - Automatically updates the year value
561
+ - Detects production vs development mode based on `ELEVENTY_RUN_MODE` environment variable
562
+ - Available globally in all templates without manual setup
563
+ - No configuration required
564
+
565
+ **Examples:**
566
+
567
+ ```njk
568
+ {# Copyright notice #}
569
+ <p>Copyright &copy; {{ site.year }} My Site</p>
570
+
571
+ {# Conditional loading of analytics #}
572
+ {% if site.isProd %}
573
+ <script src="/analytics.js"></script>
574
+ {% endif %}
575
+
576
+ {# Different behavior in dev vs prod #}
577
+ {% if site.isProd %}
578
+ <link rel="stylesheet" href="/css/styles.min.css">
579
+ {% else %}
580
+ <link rel="stylesheet" href="/css/styles.css">
581
+ <script src="/live-reload.js"></script>
582
+ {% endif %}
583
+ ```
584
+
585
+ ### Additional Exports
586
+
587
+ The plugin also exports the following for advanced usage:
588
+
589
+ - `transformAutoRaw(content)`: The transform function used by `mdAutoRawTags` preprocessor. Can be used programmatically to wrap Nunjucks syntax with raw tags.
590
+ - `transformNl2br(content)`: The transform function used by `mdAutoNl2br` preprocessor. Can be used programmatically to convert `\n` sequences to `<br>` tags.
591
+
592
+ ## Starter Configuration Files
593
+
594
+ The package includes pre-configured starter files in `node_modules/@anydigital/11ty-bricks/src/starter/` that you can symlink to your project for quick setup:
595
+
596
+ ### Available Starter Files
597
+
598
+ #### eleventy.config.js
599
+
600
+ A fully-configured Eleventy config file with:
601
+ - All 11ty-bricks plugins enabled
602
+ - Eleventy Navigation plugin
603
+ - Markdown-it with anchors
604
+ - YAML data support
605
+ - CLI input directory support
606
+ - Symlink support for development
607
+
608
+ **Symlink to your project:**
609
+ ```bash
610
+ ln -s node_modules/@anydigital/11ty-bricks/src/starter/eleventy.config.js eleventy.config.js
611
+ ```
612
+
613
+ #### tailwind.config.js
614
+
615
+ A pre-configured Tailwind CSS config optimized for Eleventy projects with proper content paths.
616
+
617
+ **Symlink to your project:**
618
+ ```bash
619
+ ln -s node_modules/@anydigital/11ty-bricks/src/starter/tailwind.config.js tailwind.config.js
620
+ ```
621
+
622
+ #### admin/index.html
623
+
624
+ A ready-to-use Sveltia CMS admin interface for content management.
625
+
626
+ **Symlink to your project:**
627
+ ```bash
628
+ mkdir -p admin
629
+ ln -s ../node_modules/@anydigital/11ty-bricks/src/starter/admin/index.html admin/index.html
630
+ ```
631
+
632
+ ### Benefits of Symlinking
633
+
634
+ - **Always up-to-date**: Configuration automatically updates when you upgrade the package
635
+ - **Less maintenance**: No need to manually sync configuration changes
636
+ - **Quick setup**: Get started immediately with best-practice configurations
637
+ - **Easy customization**: Override specific settings by creating your own config that imports from the symlinked version
638
+
639
+ ### Alternative: Copy Files
640
+
641
+ If you prefer to customize the configurations extensively, you can copy the files instead:
642
+
643
+ ```bash
644
+ cp node_modules/@anydigital/11ty-bricks/src/starter/eleventy.config.js .
645
+ cp node_modules/@anydigital/11ty-bricks/src/starter/tailwind.config.js .
646
+ mkdir -p admin
647
+ cp node_modules/@anydigital/11ty-bricks/src/starter/admin/index.html admin/
648
+ ```
649
+
650
+ ## CLI Helper Commands
651
+
652
+ After installing this package, the `download-files` command becomes available:
653
+
654
+ ### download-files
655
+
656
+ A CLI command that downloads external files to your project based on URLs specified in your `package.json`.
657
+
658
+ **Usage:**
659
+
660
+ 1. Add a `_downloadFiles` field to your project's `package.json` with URL-to-path mappings:
661
+
662
+ ```json
663
+ {
664
+ "_downloadFiles": {
665
+ "https://example.com/library.js": "src/vendor/library.js",
666
+ "https://cdn.example.com/styles.css": "public/css/external.css"
667
+ }
668
+ }
669
+ ```
670
+
671
+ 2. Run the download command:
672
+
673
+ ```bash
674
+ npx download-files
675
+ ```
676
+
677
+ **Options:**
678
+
679
+ - `-o, --output <dir>`: Specify an output directory where all files will be downloaded (relative paths in `_downloadFiles` will be resolved relative to this directory)
680
+
681
+ ```bash
682
+ # Download all files to a specific directory
683
+ npx download-files --output public
684
+ ```
685
+
686
+ **Features:**
687
+
688
+ - Downloads multiple files from external URLs
689
+ - Automatically creates directories if they don't exist
690
+ - Overwrites existing files
691
+ - Continues downloading remaining files even if some fail
692
+ - Provides clear progress and error messages
693
+ - Returns appropriate exit codes for CI/CD integration
694
+
695
+ **Use Cases:**
696
+
697
+ - Download third-party libraries and assets
698
+ - Fetch external resources during build processes
699
+ - Keep vendored files up to date
700
+ - Automate dependency downloads that aren't available via npm
104
701
 
105
702
  ## Requirements
106
703
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@anydigital/11ty-bricks",
3
- "version": "1.0.0-alpha",
3
+ "version": "1.0.0-alpha.11",
4
4
  "description": "A collection of helpful utilities and filters for Eleventy (11ty)",
5
5
  "type": "module",
6
6
  "main": "./src/index.js",
@@ -10,10 +10,14 @@
10
10
  "require": "./src/index.cjs"
11
11
  }
12
12
  },
13
+ "bin": {
14
+ "download-files": "src/cli/download-files.js"
15
+ },
13
16
  "files": [
14
17
  "src"
15
18
  ],
16
19
  "scripts": {
20
+ "build": "npx download-files",
17
21
  "test": "node --test src/**/*.test.js"
18
22
  },
19
23
  "keywords": [
@@ -40,5 +44,8 @@
40
44
  },
41
45
  "engines": {
42
46
  "node": ">=18.0.0"
47
+ },
48
+ "_downloadFiles": {
49
+ "https://raw.githubusercontent.com/danurbanowicz/eleventy-sveltia-cms-starter/refs/heads/master/admin/index.html": "src/starter/admin/index.html"
43
50
  }
44
51
  }