@anydigital/eleventy-bricks 1.0.0-alpha.13

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 ADDED
@@ -0,0 +1,712 @@
1
+ # eleventy-bricks
2
+
3
+ A collection of helpful utilities and filters for Eleventy (11ty).
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ npm install @anydigital/eleventy-bricks
9
+ ```
10
+
11
+ ## Usage
12
+
13
+ You can use this library in two ways:
14
+
15
+ ### Option 1: As a Plugin
16
+
17
+ Import and use the entire plugin. You can configure which helpers to enable using the options parameter:
18
+
19
+ **ES Modules:**
20
+ ```javascript
21
+ import eleventyBricks from "@anydigital/eleventy-bricks";
22
+
23
+ export default function(eleventyConfig) {
24
+ eleventyConfig.addPlugin(eleventyBricks, {
25
+ mdAutoRawTags: true // Enable mdAutoRawTags preprocessor (default: false)
26
+ });
27
+
28
+ // Your other configuration...
29
+ }
30
+ ```
31
+
32
+ **CommonJS:**
33
+ ```javascript
34
+ const eleventyBricks = require("@anydigital/eleventy-bricks");
35
+
36
+ module.exports = function(eleventyConfig) {
37
+ eleventyConfig.addPlugin(eleventyBricks, {
38
+ mdAutoRawTags: true // Enable mdAutoRawTags preprocessor (default: false)
39
+ });
40
+
41
+ // Your other configuration...
42
+ };
43
+ ```
44
+
45
+ > **Note:** The CommonJS wrapper uses dynamic imports internally and returns async functions. Eleventy's `addPlugin()` method handles this automatically.
46
+
47
+ ### Option 2: Import Individual Helpers (Recommended)
48
+
49
+ Import only the specific helpers you need without using the plugin:
50
+
51
+ **ES Modules:**
52
+ ```javascript
53
+ import { bricks, mdAutoRawTags, mdAutoNl2br, fragments, setAttrFilter, byAttrFilter, siteData } from "@anydigital/eleventy-bricks";
54
+
55
+ export default function(eleventyConfig) {
56
+ bricks(eleventyConfig);
57
+ mdAutoRawTags(eleventyConfig);
58
+ mdAutoNl2br(eleventyConfig);
59
+ fragments(eleventyConfig);
60
+ setAttrFilter(eleventyConfig);
61
+ byAttrFilter(eleventyConfig);
62
+ siteData(eleventyConfig);
63
+
64
+ // Your other configuration...
65
+ }
66
+ ```
67
+
68
+ **CommonJS:**
69
+ ```javascript
70
+ const { bricks, mdAutoRawTags, mdAutoNl2br, fragments, setAttrFilter, byAttrFilter, siteData } = require("@anydigital/eleventy-bricks");
71
+
72
+ module.exports = async function(eleventyConfig) {
73
+ await bricks(eleventyConfig);
74
+ await mdAutoRawTags(eleventyConfig);
75
+ await mdAutoNl2br(eleventyConfig);
76
+ await fragments(eleventyConfig);
77
+ await setAttrFilter(eleventyConfig);
78
+ await byAttrFilter(eleventyConfig);
79
+ await siteData(eleventyConfig);
80
+
81
+ // Your other configuration...
82
+ };
83
+ ```
84
+
85
+ > **Note:** When using CommonJS with individual helpers, the config function must be `async` and each helper must be `await`ed, as the CommonJS wrapper uses dynamic imports internally.
86
+
87
+ ## Configuration Options
88
+
89
+ When using the plugin (Option 1), you can configure which helpers to enable:
90
+
91
+ | Option | Type | Default | Description |
92
+ |--------|------|---------|-------------|
93
+ | `bricks` | boolean | `false` | Enable the bricks system for dependency management |
94
+ | `mdAutoRawTags` | boolean | `false` | Enable the mdAutoRawTags preprocessor for Markdown files |
95
+ | `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
+ | `setAttrFilter` | boolean | `false` | Enable the setAttr filter for overriding object attributes |
98
+ | `byAttrFilter` | boolean | `false` | Enable the byAttr filter for filtering collections by attribute values |
99
+ | `siteData` | boolean | `false` | Enable site.year and site.isProd global data |
100
+
101
+ **Example:**
102
+ ```javascript
103
+ eleventyConfig.addPlugin(eleventyBricks, {
104
+ bricks: true,
105
+ mdAutoRawTags: true,
106
+ byAttrFilter: true,
107
+ siteData: true
108
+ });
109
+ ```
110
+
111
+ ## Available 11ty Helpers
112
+
113
+ ### bricks
114
+
115
+ 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.
116
+
117
+ **Why use this?**
118
+
119
+ 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:
120
+ - Collects dependencies from all bricks used on a page
121
+ - Categorizes them (external CSS, external JS, inline styles, inline scripts)
122
+ - Injects them in the correct location in your HTML output
123
+
124
+ **How it works:**
125
+
126
+ 1. Use the `bricksDependencies` shortcode in your base template to mark where dependencies should be injected
127
+ 2. Use the `brick` shortcode to register and render brick components that declare their dependencies
128
+ 3. The system automatically collects all dependencies and injects them when the page is built
129
+
130
+ **Usage:**
131
+
132
+ 1. Enable `bricks` in your Eleventy config:
133
+
134
+ ```javascript
135
+ import { bricks } from "@anydigital/eleventy-bricks";
136
+
137
+ export default function(eleventyConfig) {
138
+ bricks(eleventyConfig);
139
+ // Or use as plugin:
140
+ // eleventyConfig.addPlugin(eleventyBricks, { bricks: true });
141
+ }
142
+ ```
143
+
144
+ 2. Add the `bricksDependencies` shortcode in your base template (typically in the `<head>` section):
145
+
146
+ ```njk
147
+ <head>
148
+ <meta charset="UTF-8">
149
+ <title>My Site</title>
150
+ {% bricksDependencies [
151
+ ... (global dependencies can be set here) ...
152
+ ] %}
153
+ <!-- Other head content -->
154
+ </head>
155
+ ```
156
+
157
+ 3. Create brick components that declare their dependencies:
158
+
159
+ ```javascript
160
+ // myBrick.js
161
+ export default {
162
+ dependencies: [
163
+ 'https://cdn.example.com/library.css',
164
+ 'https://cdn.example.com/library.js'
165
+ ],
166
+ style: `
167
+ .my-component { color: blue; }
168
+ `,
169
+ script: `
170
+ console.log('Component initialized');
171
+ `,
172
+ render: function() {
173
+ return '<div class="my-component">Hello World</div>';
174
+ }
175
+ };
176
+ ```
177
+
178
+ 4. Use the `brick` shortcode in your templates:
179
+
180
+ ```njk
181
+ {% set myBrick = require('./myBrick.js') %}
182
+ {% brick myBrick %}
183
+ ```
184
+
185
+ **Brick Component Structure:**
186
+
187
+ A brick component is a JavaScript object with the following optional properties:
188
+
189
+ - `dependencies`: Array of URLs to external CSS or JavaScript files (e.g., `['https://cdn.example.com/style.css', 'https://cdn.example.com/script.js']`)
190
+ - `style`: String containing inline CSS
191
+ - `script`: String containing inline JavaScript
192
+ - `render`: Function that returns the HTML markup for the component
193
+
194
+ **Output:**
195
+
196
+ The system will automatically inject all dependencies in the order they were registered:
197
+
198
+ ```html
199
+ <head>
200
+ <meta charset="UTF-8">
201
+ <title>My Site</title>
202
+ <link rel="stylesheet" href="https://cdn.example.com/library.css">
203
+ <style>.my-component { color: blue; }</style>
204
+ <script src="https://cdn.example.com/library.js"></script>
205
+ <script>console.log('Component initialized');</script>
206
+ <!-- Other head content -->
207
+ </head>
208
+ ```
209
+
210
+ **Features:**
211
+
212
+ - Automatic dependency collection per page
213
+ - Categorizes dependencies (CSS vs JS, external vs inline)
214
+ - Deduplicates dependencies (using Sets internally)
215
+ - Works with both external URLs and inline code
216
+ - Clears registry before each build to prevent stale data
217
+
218
+ ### mdAutoRawTags
219
+
220
+ Prevents Nunjucks syntax from being processed in Markdown files by automatically wrapping `{{`, `}}`, `{%`, and `%}` with `{% raw %}` tags.
221
+
222
+ **Why use this?**
223
+
224
+ 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.
225
+
226
+ **Usage:**
227
+
228
+ 1. Enable `mdAutoRawTags` in your Eleventy config:
229
+
230
+ ```javascript
231
+ import { mdAutoRawTags } from "@anydigital/eleventy-bricks";
232
+
233
+ export default function(eleventyConfig) {
234
+ mdAutoRawTags(eleventyConfig);
235
+ // Or use as plugin:
236
+ // eleventyConfig.addPlugin(eleventyBricks, { mdAutoRawTags: true });
237
+ }
238
+ ```
239
+
240
+ **Example:**
241
+
242
+ Before `mdAutoRawTags`, writing this in Markdown:
243
+ ```markdown
244
+ Use {{ variable }} to output variables.
245
+ ```
246
+
247
+ Would try to process `{{ variable }}` as a template variable. With `mdAutoRawTags`, it displays exactly as written.
248
+
249
+ ### mdAutoNl2br
250
+
251
+ 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.
252
+
253
+ **Why use this?**
254
+
255
+ 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.
256
+
257
+ **Usage:**
258
+
259
+ 1. Enable `mdAutoNl2br` in your Eleventy config:
260
+
261
+ ```javascript
262
+ import { mdAutoNl2br } from "@anydigital/eleventy-bricks";
263
+
264
+ export default function(eleventyConfig) {
265
+ mdAutoNl2br(eleventyConfig);
266
+ // Or use as plugin:
267
+ // eleventyConfig.addPlugin(eleventyBricks, { mdAutoNl2br: true });
268
+ }
269
+ ```
270
+
271
+ **Example:**
272
+
273
+ In your Markdown file:
274
+ ```markdown
275
+ | Column 1 | Column 2 |
276
+ |----------|----------|
277
+ | Line 1\nLine 2\nLine 3 | Another cell\nWith multiple lines |
278
+ ```
279
+
280
+ Will render as:
281
+ ```html
282
+ <td>Line 1<br>Line 2<br>Line 3</td>
283
+ <td>Another cell<br>With multiple lines</td>
284
+ ```
285
+
286
+ **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
+
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
+ ### setAttr
363
+
364
+ 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.
365
+
366
+ **Why use this?**
367
+
368
+ 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.
369
+
370
+ **Usage:**
371
+
372
+ 1. Enable `setAttr` in your Eleventy config:
373
+
374
+ ```javascript
375
+ import { setAttrFilter } from "@anydigital/eleventy-bricks";
376
+
377
+ export default function(eleventyConfig) {
378
+ setAttrFilter(eleventyConfig);
379
+ // Or use as plugin:
380
+ // eleventyConfig.addPlugin(eleventyBricks, { setAttrFilter: true });
381
+ }
382
+ ```
383
+
384
+ 2. Use the filter in your templates:
385
+
386
+ ```njk
387
+ {# Create a modified version of a page object #}
388
+ {% set modifiedPage = page | setAttr('title', 'New Title') %}
389
+
390
+ <h1>{{ modifiedPage.title }}</h1>
391
+ <p>Original title: {{ page.title }}</p>
392
+ ```
393
+
394
+ **Parameters:**
395
+
396
+ - `obj`: The object to modify
397
+ - `key`: The attribute name to set (string)
398
+ - `value`: The value to set for the attribute (any type)
399
+
400
+ **Returns:**
401
+
402
+ A new object with the specified attribute set to the given value. The original object is not modified.
403
+
404
+ **Features:**
405
+
406
+ - Non-mutating: Creates a new object, leaving the original unchanged
407
+ - Works with any object type
408
+ - Supports any attribute name and value type
409
+ - Can be chained with other filters
410
+
411
+ **Examples:**
412
+
413
+ ```njk
414
+ {# Override a single attribute #}
415
+ {% set updatedPost = post | setAttr('featured', true) %}
416
+
417
+ {# Chain multiple setAttr filters #}
418
+ {% set modifiedPost = post
419
+ | setAttr('category', 'blog')
420
+ | setAttr('priority', 1)
421
+ %}
422
+
423
+ {# Use in loops #}
424
+ {% for item in collection %}
425
+ {% set enhancedItem = item | setAttr('processed', true) %}
426
+ {# ... use enhancedItem ... #}
427
+ {% endfor %}
428
+ ```
429
+
430
+ ### byAttr
431
+
432
+ 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.
433
+
434
+ **Why use this?**
435
+
436
+ 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).
437
+
438
+ **Usage:**
439
+
440
+ 1. Enable `byAttr` in your Eleventy config:
441
+
442
+ ```javascript
443
+ import { byAttrFilter } from "@anydigital/eleventy-bricks";
444
+
445
+ export default function(eleventyConfig) {
446
+ byAttrFilter(eleventyConfig);
447
+ // Or use as plugin:
448
+ // eleventyConfig.addPlugin(eleventyBricks, { byAttrFilter: true });
449
+ }
450
+ ```
451
+
452
+ 2. Use the filter in your templates:
453
+
454
+ **Filter by exact attribute match:**
455
+ ```njk
456
+ {# Get all posts with category 'blog' #}
457
+ {% set blogPosts = collections.all | byAttr('category', 'blog') %}
458
+
459
+ {% for post in blogPosts %}
460
+ <h2>{{ post.data.title }}</h2>
461
+ {% endfor %}
462
+ ```
463
+
464
+ **Filter by array attribute (tags):**
465
+ ```njk
466
+ {# Get all posts that include 'javascript' tag #}
467
+ {% set jsPosts = collections.all | byAttr('tags', 'javascript') %}
468
+
469
+ {% for post in jsPosts %}
470
+ <h2>{{ post.data.title }}</h2>
471
+ {% endfor %}
472
+ ```
473
+
474
+ **Parameters:**
475
+
476
+ - `collection`: The collection to filter (array of items)
477
+ - `attrName`: The attribute name to check (string)
478
+ - `targetValue`: The value to match against (any type)
479
+
480
+ **Features:**
481
+
482
+ - Works with any attribute in front matter
483
+ - Handles both `item.data.attrName` and `item.attrName` patterns
484
+ - Special handling for array attributes (uses `includes()` check)
485
+ - Returns empty array if collection is invalid
486
+ - Filters out items without the specified attribute
487
+
488
+ **Examples:**
489
+
490
+ Front matter:
491
+ ```yaml
492
+ ---
493
+ title: My Post
494
+ category: blog
495
+ tags: [javascript, tutorial, beginner]
496
+ priority: 1
497
+ ---
498
+ ```
499
+
500
+ Template usage:
501
+ ```njk
502
+ {# Filter by category #}
503
+ {% set blogPosts = collections.all | byAttr('category', 'blog') %}
504
+
505
+ {# Filter by tag (array) #}
506
+ {% set jsTutorials = collections.all | byAttr('tags', 'javascript') %}
507
+
508
+ {# Filter by numeric value #}
509
+ {% set highPriority = collections.all | byAttr('priority', 1) %}
510
+
511
+ {# Chain filters #}
512
+ {% set recentBlogPosts = collections.all | byAttr('category', 'blog') | reverse | limit(5) %}
513
+ ```
514
+
515
+ ### siteData
516
+
517
+ Adds global site data to your Eleventy project, providing commonly needed values that can be accessed in all templates.
518
+
519
+ **Why use this?**
520
+
521
+ 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.
522
+
523
+ **Usage:**
524
+
525
+ 1. Enable `siteData` in your Eleventy config:
526
+
527
+ ```javascript
528
+ import { siteData } from "@anydigital/eleventy-bricks";
529
+
530
+ export default function(eleventyConfig) {
531
+ siteData(eleventyConfig);
532
+ // Or use as plugin:
533
+ // eleventyConfig.addPlugin(eleventyBricks, { siteData: true });
534
+ }
535
+ ```
536
+
537
+ 2. Use the global data in your templates:
538
+
539
+ **Current Year:**
540
+ ```njk
541
+ <footer>
542
+ <p>&copy; {{ site.year }} Your Company Name. All rights reserved.</p>
543
+ </footer>
544
+ ```
545
+
546
+ **Environment Check:**
547
+ ```njk
548
+ {% if site.isProd %}
549
+ <!-- Production-only features -->
550
+ <script async src="https://www.googletagmanager.com/gtag/js?id=GA_TRACKING_ID"></script>
551
+ {% else %}
552
+ <!-- Development-only features -->
553
+ <div class="dev-toolbar">Development Mode</div>
554
+ {% endif %}
555
+ ```
556
+
557
+ **Available Data:**
558
+
559
+ - `site.year`: The current year as a number (e.g., `2026`)
560
+ - `site.isProd`: Boolean indicating if running in production mode (`true` for `eleventy build`, `false` for `eleventy serve`)
561
+
562
+ **Features:**
563
+
564
+ - Automatically updates the year value
565
+ - Detects production vs development mode based on `ELEVENTY_RUN_MODE` environment variable
566
+ - Available globally in all templates without manual setup
567
+ - No configuration required
568
+
569
+ **Examples:**
570
+
571
+ ```njk
572
+ {# Copyright notice #}
573
+ <p>Copyright &copy; {{ site.year }} My Site</p>
574
+
575
+ {# Conditional loading of analytics #}
576
+ {% if site.isProd %}
577
+ <script src="/analytics.js"></script>
578
+ {% endif %}
579
+
580
+ {# Different behavior in dev vs prod #}
581
+ {% if site.isProd %}
582
+ <link rel="stylesheet" href="/css/styles.min.css">
583
+ {% else %}
584
+ <link rel="stylesheet" href="/css/styles.css">
585
+ <script src="/live-reload.js"></script>
586
+ {% endif %}
587
+ ```
588
+
589
+ ### Additional Exports
590
+
591
+ The plugin also exports the following for advanced usage:
592
+
593
+ - `transformAutoRaw(content)`: The transform function used by `mdAutoRawTags` preprocessor. Can be used programmatically to wrap Nunjucks syntax with raw tags.
594
+ - `transformNl2br(content)`: The transform function used by `mdAutoNl2br` preprocessor. Can be used programmatically to convert `\n` sequences to `<br>` tags.
595
+
596
+ ## Starter Configuration Files
597
+
598
+ The package includes pre-configured starter files in `node_modules/@anydigital/eleventy-bricks/src/starter/` that you can symlink to your project for quick setup:
599
+
600
+ ### Available Starter Files
601
+
602
+ #### eleventy.config.js
603
+
604
+ A fully-configured Eleventy config file with:
605
+ - All eleventy-bricks plugins enabled
606
+ - Eleventy Navigation plugin
607
+ - Markdown-it with anchors
608
+ - YAML data support
609
+ - CLI input directory support
610
+ - Symlink support for development
611
+
612
+ **Required dependencies:**
613
+ ```bash
614
+ npm install @11ty/eleventy-navigation markdown-it markdown-it-anchor js-yaml minimist
615
+ ```
616
+
617
+ **Symlink to your project:**
618
+ ```bash
619
+ ln -s node_modules/@anydigital/eleventy-bricks/src/starter/eleventy.config.js eleventy.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/eleventy-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/eleventy-bricks/src/starter/eleventy.config.js .
645
+ mkdir -p admin
646
+ cp node_modules/@anydigital/eleventy-bricks/src/starter/admin/index.html admin/
647
+ ```
648
+
649
+ ## CLI Helper Commands
650
+
651
+ After installing this package, the `download-files` command becomes available:
652
+
653
+ ### download-files
654
+
655
+ A CLI command that downloads external files to your project based on URLs specified in your `package.json`.
656
+
657
+ **Usage:**
658
+
659
+ 1. Add a `_downloadFiles` field to your project's `package.json` with URL-to-path mappings:
660
+
661
+ ```json
662
+ {
663
+ "_downloadFiles": {
664
+ "https://example.com/library.js": "src/vendor/library.js",
665
+ "https://cdn.example.com/styles.css": "public/css/external.css"
666
+ }
667
+ }
668
+ ```
669
+
670
+ 2. Run the download command:
671
+
672
+ ```bash
673
+ npx download-files
674
+ ```
675
+
676
+ **Options:**
677
+
678
+ - `-o, --output <dir>`: Specify an output directory where all files will be downloaded (relative paths in `_downloadFiles` will be resolved relative to this directory)
679
+
680
+ ```bash
681
+ # Download all files to a specific directory
682
+ npx download-files --output public
683
+ ```
684
+
685
+ **Features:**
686
+
687
+ - Downloads multiple files from external URLs
688
+ - Automatically creates directories if they don't exist
689
+ - Overwrites existing files
690
+ - Continues downloading remaining files even if some fail
691
+ - Provides clear progress and error messages
692
+ - Returns appropriate exit codes for CI/CD integration
693
+
694
+ **Use Cases:**
695
+
696
+ - Download third-party libraries and assets
697
+ - Fetch external resources during build processes
698
+ - Keep vendored files up to date
699
+ - Automate dependency downloads that aren't available via npm
700
+
701
+ ## Requirements
702
+
703
+ - Node.js >= 18.0.0
704
+ - Eleventy >= 2.0.0 (supports both 2.x and 3.x)
705
+
706
+ ## License
707
+
708
+ MIT
709
+
710
+ ## Contributing
711
+
712
+ Contributions are welcome! Please feel free to submit a Pull Request.