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

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
@@ -48,11 +48,12 @@ Import only the specific helpers you need without using the plugin:
48
48
 
49
49
  **ES Modules:**
50
50
  ```javascript
51
- import { bricks, mdAutoRawTags } from "@anydigital/11ty-bricks";
51
+ import { bricks, mdAutoRawTags, siteData } from "@anydigital/11ty-bricks";
52
52
 
53
53
  export default function(eleventyConfig) {
54
54
  bricks(eleventyConfig);
55
55
  mdAutoRawTags(eleventyConfig);
56
+ siteData(eleventyConfig);
56
57
 
57
58
  // Your other configuration...
58
59
  }
@@ -60,11 +61,12 @@ export default function(eleventyConfig) {
60
61
 
61
62
  **CommonJS:**
62
63
  ```javascript
63
- const { bricks, mdAutoRawTags } = require("@anydigital/11ty-bricks");
64
+ const { bricks, mdAutoRawTags, siteData } = require("@anydigital/11ty-bricks");
64
65
 
65
66
  module.exports = function(eleventyConfig) {
66
67
  bricks(eleventyConfig);
67
68
  mdAutoRawTags(eleventyConfig);
69
+ siteData(eleventyConfig);
68
70
 
69
71
  // Your other configuration...
70
72
  };
@@ -82,13 +84,15 @@ When using the plugin (Option 1), you can configure which helpers to enable:
82
84
  | `fragments` | boolean | `false` | Enable the fragment shortcode for including content from fragments |
83
85
  | `setAttrFilter` | boolean | `false` | Enable the setAttr filter for overriding object attributes |
84
86
  | `byAttrFilter` | boolean | `false` | Enable the byAttr filter for filtering collections by attribute values |
87
+ | `siteData` | boolean | `false` | Enable site.year and site.isProd global data |
85
88
 
86
89
  **Example:**
87
90
  ```javascript
88
91
  eleventyConfig.addPlugin(eleventyBricks, {
89
92
  bricks: true,
90
93
  mdAutoRawTags: true,
91
- byAttrFilter: true
94
+ byAttrFilter: true,
95
+ siteData: true
92
96
  });
93
97
  ```
94
98
 
@@ -282,13 +286,13 @@ Fragments allow you to organize reusable content snippets in a dedicated directo
282
286
 
283
287
  **Usage:**
284
288
 
285
- 1. Enable `fragment` in your Eleventy config:
289
+ 1. Enable `fragments` in your Eleventy config:
286
290
 
287
291
  ```javascript
288
- import { fragment } from "@anydigital/11ty-bricks";
292
+ import { fragments } from "@anydigital/11ty-bricks";
289
293
 
290
294
  export default function(eleventyConfig) {
291
- fragment(eleventyConfig);
295
+ fragments(eleventyConfig);
292
296
  // Or use as plugin:
293
297
  // eleventyConfig.addPlugin(eleventyBricks, { fragments: true });
294
298
  }
@@ -496,6 +500,80 @@ Template usage:
496
500
  {% set recentBlogPosts = collections.all | byAttr('category', 'blog') | reverse | limit(5) %}
497
501
  ```
498
502
 
503
+ ### siteData
504
+
505
+ Adds global site data to your Eleventy project, providing commonly needed values that can be accessed in all templates.
506
+
507
+ **Why use this?**
508
+
509
+ 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.
510
+
511
+ **Usage:**
512
+
513
+ 1. Enable `siteData` in your Eleventy config:
514
+
515
+ ```javascript
516
+ import { siteData } from "@anydigital/11ty-bricks";
517
+
518
+ export default function(eleventyConfig) {
519
+ siteData(eleventyConfig);
520
+ // Or use as plugin:
521
+ // eleventyConfig.addPlugin(eleventyBricks, { siteData: true });
522
+ }
523
+ ```
524
+
525
+ 2. Use the global data in your templates:
526
+
527
+ **Current Year:**
528
+ ```njk
529
+ <footer>
530
+ <p>&copy; {{ site.year }} Your Company Name. All rights reserved.</p>
531
+ </footer>
532
+ ```
533
+
534
+ **Environment Check:**
535
+ ```njk
536
+ {% if site.isProd %}
537
+ <!-- Production-only features -->
538
+ <script async src="https://www.googletagmanager.com/gtag/js?id=GA_TRACKING_ID"></script>
539
+ {% else %}
540
+ <!-- Development-only features -->
541
+ <div class="dev-toolbar">Development Mode</div>
542
+ {% endif %}
543
+ ```
544
+
545
+ **Available Data:**
546
+
547
+ - `site.year`: The current year as a number (e.g., `2026`)
548
+ - `site.isProd`: Boolean indicating if running in production mode (`true` for `eleventy build`, `false` for `eleventy serve`)
549
+
550
+ **Features:**
551
+
552
+ - Automatically updates the year value
553
+ - Detects production vs development mode based on `ELEVENTY_RUN_MODE` environment variable
554
+ - Available globally in all templates without manual setup
555
+ - No configuration required
556
+
557
+ **Examples:**
558
+
559
+ ```njk
560
+ {# Copyright notice #}
561
+ <p>Copyright &copy; {{ site.year }} My Site</p>
562
+
563
+ {# Conditional loading of analytics #}
564
+ {% if site.isProd %}
565
+ <script src="/analytics.js"></script>
566
+ {% endif %}
567
+
568
+ {# Different behavior in dev vs prod #}
569
+ {% if site.isProd %}
570
+ <link rel="stylesheet" href="/css/styles.min.css">
571
+ {% else %}
572
+ <link rel="stylesheet" href="/css/styles.css">
573
+ <script src="/live-reload.js"></script>
574
+ {% endif %}
575
+ ```
576
+
499
577
  ### Additional Exports
500
578
 
501
579
  The plugin also exports the following for advanced usage:
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@anydigital/11ty-bricks",
3
- "version": "1.0.0-alpha.8",
3
+ "version": "1.0.0-alpha.9",
4
4
  "description": "A collection of helpful utilities and filters for Eleventy (11ty)",
5
5
  "type": "module",
6
6
  "main": "./src/index.js",
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', 'fragments', 'setAttrFilter', 'byAttrFilter'].forEach(name => {
13
+ ['bricks', 'mdAutoRawTags', 'mdAutoNl2br', 'fragments', '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
@@ -3,6 +3,7 @@ import { mdAutoRawTags, mdAutoNl2br, transformAutoRaw, transformNl2br } from "./
3
3
  import { fragments } from "./fragments.js";
4
4
  import { setAttrFilter } from "./setAttrFilter.js";
5
5
  import { byAttrFilter } from "./byAttrFilter.js";
6
+ import { siteData } from "./siteData.js";
6
7
 
7
8
  /**
8
9
  * 11ty Bricks Plugin
@@ -18,14 +19,15 @@ import { byAttrFilter } from "./byAttrFilter.js";
18
19
  * @param {boolean} options.fragments - Enable fragment shortcode (default: false)
19
20
  * @param {boolean} options.setAttrFilter - Enable setAttr filter (default: false)
20
21
  * @param {boolean} options.byAttrFilter - Enable byAttr filter (default: false)
22
+ * @param {boolean} options.siteData - Enable site.year global data (default: false)
21
23
  */
22
24
  export default function eleventyBricksPlugin(eleventyConfig, options = {}) {
23
- const plugins = { bricks, mdAutoRawTags, mdAutoNl2br, fragments, setAttrFilter, byAttrFilter };
25
+ const plugins = { bricks, mdAutoRawTags, mdAutoNl2br, fragments, setAttrFilter, byAttrFilter, siteData };
24
26
  Object.entries(options).forEach(([key, enabled]) => enabled && plugins[key]?.(eleventyConfig));
25
27
  }
26
28
 
27
29
  // Export individual helpers for granular usage
28
- export { bricks, mdAutoRawTags, mdAutoNl2br, fragments, setAttrFilter, byAttrFilter };
30
+ export { bricks, mdAutoRawTags, mdAutoNl2br, fragments, setAttrFilter, byAttrFilter, siteData };
29
31
 
30
32
  // Export transform functions for advanced usage
31
33
  export { transformAutoRaw, transformNl2br };
@@ -0,0 +1,12 @@
1
+ /**
2
+ * Add site.year and site.isProd global data
3
+ * - site.isProd: Boolean indicating if running in production mode (build) vs development (serve)
4
+ * - site.year: Sets the current year to be available in all templates as {{ site.year }}
5
+ *
6
+ * @param {Object} eleventyConfig - The Eleventy configuration object
7
+ */
8
+ export function siteData(eleventyConfig) {
9
+ eleventyConfig.addGlobalData("site.isProd", () => process.env.ELEVENTY_RUN_MODE === "build");
10
+ eleventyConfig.addGlobalData("site.year", () => new Date().getFullYear());
11
+ }
12
+