eleventy-plugin-vento 3.0.2 → 3.2.0

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/CHANGELOG.md CHANGED
@@ -1,5 +1,72 @@
1
1
  # eleventy-plugin-vento
2
2
 
3
+ ## 3.2.0
4
+
5
+ ### Minor Changes
6
+
7
+ - f9388e1: Further refine caching between Eleventy and Vento: commit ec02a765 deferred **all** caching to Vento and turned off Eleventy's cache (released in 3.1.0). This release allows Vento to cache only the templates that Eleventy can't cache (permalinks, includes, etc.), and Eleventy caches everything else.
8
+
9
+ A performance oversight has also been resolved by this change. Now, template functions are pre-compiled and saved by Eleventy, only running the template on render without having to go through a re-compile or get a template from the cache.
10
+
11
+ ### Patch Changes
12
+
13
+ - 693e1a2: Refactored the following features internally:
14
+
15
+ - Reverts 2c3548c1 for modularity: The compatibility check has moved back to `modules/utils.js`
16
+ - Revises caching further: Instead of deferring to Vento for everything, permalink templates and templates loaded by Vento (like includes) are cached by Vento. Everything else is cached by Eleventy.
17
+ - Rename some internal variables to help with readability (`_11ty.ctx => _11Ctx`)
18
+ - `DEBUG` key `Eleventy:Vento:Template` renamed to `Eleventy:Vento:Render`
19
+ - Declare engine functions separately and return as an object after everything has been declared.
20
+
21
+ ## 3.1.0
22
+
23
+ ### Minor Changes
24
+
25
+ - 7e6ba68: Separate `shortcodes` and `pairedShortcodes` into seperate object namespaces. Prior to this version, Eleventy shortcodes and paired shortcodes were merged into a single object keyed as `_11ty.functions` which allowed for naming collisions between shortcodes and their paired counterparts.
26
+ - b8f0a03: Adds new dependency on `debug` package, to help out with testing and getting more verbose logs. The following `DEBUG` namespaces are implemented:
27
+
28
+ - `Eleventy:Vento:Setup` - Logs initial setup of the plugin, loading features, pre-page compile setup steps (like changing `page` and `eleventy` objects)
29
+ - `Eleventy:Vento:Cache` - Logs updates to Vento's own internal cache, which is used in tandem with Eleventy's cache.
30
+ - `Eleventy:Vento:Template` - Logs rendered templates and other template related actions
31
+
32
+ Because it is a child of the `Eleventy:` namespace, the following command will include output from this plugin as well:
33
+
34
+ ```sh
35
+ $ DEBUG='Eleventy:*' npx @11ty/eleventy
36
+ ```
37
+
38
+ Alternatively, use a finer grained namespace to see only the output generated by `eleventy-plugin-vento`.
39
+
40
+ ```sh
41
+ $ DEBUG='Eleventy:Vento:*' npx @11ty/eleventy
42
+ ```
43
+
44
+ ```sh
45
+ $ DEBUG='Eleventy:Vento:Template' npx @11ty/eleventy
46
+ ```
47
+
48
+ See [the docs on 11ty.dev](https://www.11ty.dev/docs/debugging/) as well as the [debug package README](https://github.com/debug-js/debug/blob/master/README.md) for more information.
49
+
50
+ - ec02a76: Further caching improvements to e8111234 and e46ce6ea. Eleventy now defers all template caching to Vento.
51
+
52
+ Templates are now compiled directly instead of using Vento's `.runString` method which reduces overhead and enables this plugin to manage the Vento cache in a more direct manner.
53
+
54
+ - 494b184: Permalink compilation optimizations:
55
+
56
+ - Permalinks now short-circuit to raw strings if they don't contain Vento template syntax, avoiding compilation entirely.
57
+ - Permalinks are now assigned (fake) pathnames in Vento's cache. If you change template content but don't change a dynamic permalink in development, Vento will reuse the compiled permalink template. Note that **any** modifications to a template file will **always** cause it to be recompiled (see 19c352fa) — this improvement just optimizes recompiling dynamic permalinks that haven't changed.
58
+
59
+ ### Patch Changes
60
+
61
+ - 4b4b387: Entries for changed files are now deleted from Vento's cache when running the Eleventy Dev server. (fixes #38)
62
+
63
+ ## 3.0.3-next.0
64
+
65
+ ### Patch Changes
66
+
67
+ - e811123: Partially reverts e46ce6ea, refine caching logic. Pre-compile, the plugin checks the Vento cache to see what source needs compiling and if that matches what was already compiled. If not, then the cache is cleared so Vento can recompile.
68
+ - 2f32efb: Clear Vento cache on every template change, to help with #38. Resolution is still WIP.
69
+
3
70
  ## 3.0.2
4
71
 
5
72
  ### Patch Changes
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "eleventy-plugin-vento",
3
- "version": "3.0.2",
3
+ "version": "3.2.0",
4
4
  "description": "Adds support for the Vento templating language to Eleventy.",
5
5
  "type": "module",
6
6
  "engines": {
@@ -32,18 +32,19 @@
32
32
  "CHANGELOG.md"
33
33
  ],
34
34
  "dependencies": {
35
+ "debug": "4.3.7",
35
36
  "ventojs": "1.12.10"
36
37
  },
37
38
  "devDependencies": {
38
39
  "@11ty/eleventy": "3.0.0",
39
40
  "@changesets/cli": "2.27.9",
40
- "eslint": "9.12.0",
41
+ "@eslint/js": "9.13.0",
42
+ "eslint": "9.13.0",
41
43
  "eslint-config-flat-gitignore": "0.3.0",
42
44
  "eslint-config-prettier": "9.1.0",
43
45
  "eslint-plugin-unicorn": "56.0.0",
44
46
  "globals": "15.11.0",
45
- "vitest": "2.1.2",
46
- "zx": "8.1.9"
47
+ "vitest": "2.1.4"
47
48
  },
48
49
  "prettier": {
49
50
  "bracketSameLine": true,
@@ -52,7 +53,7 @@
52
53
  "trailingComma": "es5"
53
54
  },
54
55
  "scripts": {
55
- "test": "vitest --run",
56
+ "test": "vitest",
56
57
  "lint": "eslint '**/*.js'",
57
58
  "ci:version": "changeset version && pnpm install --no-frozen-lockfile",
58
59
  "ci:publish": "changeset publish",
package/readme.md CHANGED
@@ -17,6 +17,7 @@ An [Eleventy](https://11ty.dev/) plugin that adds support for [Vento](https://ve
17
17
  [Vento Plugins](#vento-plugins)<br>
18
18
  [Auto-Trimming Tags](#auto-trimming-tags)<br>
19
19
  [Ignoring Tags](#ignoring-tags)<br>
20
+ [Debugging](#debugging)<br>
20
21
 
21
22
  ## Installing
22
23
 
@@ -28,7 +29,7 @@ npm install eleventy-plugin-vento
28
29
 
29
30
  This plugin is ESM only and cannot be required from CommonJS.
30
31
 
31
- If you're using CommonJS and loading it asynchronously (ie `await import`), you will need at **minimum** Eleventy v3.0.0-alpha.15 which provides internal methods this plugin uses to get Eleventy stuff from the config API.
32
+ If you're using CommonJS and loading it asynchronously (ie `await import`), you will need at **minimum** Eleventy v3.0.0-alpha.15 which provides internal methods this plugin uses to retrieve Eleventy features from the config API.
32
33
 
33
34
  In your Eleventy config:
34
35
 
@@ -101,7 +102,7 @@ Eleventy: See [Filters](https://www.11ty.dev/docs/filters/)
101
102
  > [!NOTE]
102
103
  > Remember, Vento can print any return value from a Javascript expression, as well as [run arbitrary JavaScript](https://vento.js.org/syntax/javascript/) in templates through its `{{> ...}}` operator. In these cases, shortcodes may not be needed depending on your usage.
103
104
 
104
- Single and Paired Shortcodes added via Eleventy's `.addShortcode()`, `addAsyncShortcode()`, `addPairedShortcode()` or `.addAsyncPairedShortcode()` will be automatically loaded into Vento.
105
+ Single and Paired Shortcodes added via Eleventy's `.addShortcode()`, `.addAsyncShortcode()`, `.addPairedShortcode()` or `.addAsyncPairedShortcode()` will be automatically loaded into Vento.
105
106
 
106
107
  When using shortcodes in your templates, write them like any other Vento tag:
107
108
 
@@ -265,3 +266,33 @@ Rather than having to do multiple `{{ /echo }} ... {{ echo }}` statements, the p
265
266
  <p>Page built on: 09-19-2024</p>
266
267
  {{ /if }}
267
268
  ```
269
+
270
+ ## Debugging
271
+
272
+ Like Eleventy, this plugin uses the [`debug`](https://www.npmjs.com/package/debug) package to handle verbose logging. The following `DEBUG` namespaces are implemented:
273
+
274
+ - `Eleventy:Vento:Setup` - Logs initial setup of the plugin, loading features, pre-page compile setup steps (like changing `page` and `eleventy` objects)
275
+ - `Eleventy:Vento:Cache` - Logs updates to Vento's own internal cache, which is used in tandem with Eleventy's cache.
276
+ - `Eleventy:Vento:Render` - Logs when templates are rendered
277
+
278
+ Because it is a child of the `Eleventy:` namespace, the following command will include output from this plugin as well:
279
+
280
+ ```sh
281
+ $ DEBUG='Eleventy:*' npx @11ty/eleventy
282
+ ```
283
+
284
+ Alternatively, use a finer grained namespace to see only the output generated by `eleventy-plugin-vento`.
285
+
286
+ ```sh
287
+ $ DEBUG='Eleventy:Vento:*' npx @11ty/eleventy
288
+ ```
289
+
290
+ ```sh
291
+ $ DEBUG='Eleventy:Vento:Template' npx @11ty/eleventy
292
+ ```
293
+
294
+ ### Relevant Documentation
295
+
296
+ Eleventy: See [Debug Mode](https://www.11ty.dev/docs/debugging/).
297
+
298
+ Debug: See [`debug` on npm](https://www.npmjs.com/package/debug).
package/src/engine.js CHANGED
@@ -3,11 +3,15 @@
3
3
  * a simple API for Eleventy to interface with.
4
4
  *
5
5
  * @typedef {{eleventy?: Record<string, unknown>, page?: Record<string, unknown>}} EleventyContext
6
- * @typedef {Context & Record<string, unknown>} EleventyData
6
+ * @typedef {EleventyContext & Record<string, unknown>} EleventyData
7
7
  * @typedef {(...args: unknown[]) => unknown} EleventyFunction
8
+ * @typedef {Record<string, EleventyFunction>} EleventyFunctionSet
8
9
  * @typedef {import('ventojs/src/environment.js').Environment} VentoEnvironment
9
10
  * @typedef {VentoEnvironment & {
10
- * utils: { _11ty: { ctx: Context, tags: Record<string, EleventyFunction> } }
11
+ * utils: {
12
+ * _11tyFns: { shortcodes: EleventyFunctionSet, pairedShortcodes: EleventyFunctionSet }
13
+ * _11tyCtx: EleventyContext
14
+ * }
11
15
  * }} EleventyVentoEnvironment
12
16
  */
13
17
 
@@ -16,67 +20,107 @@ import ventojs from 'ventojs';
16
20
 
17
21
  // Internal modules
18
22
  import { createVentoTag } from './modules/create-vento-tag.js';
19
- import { CONTEXT_DATA_KEYS } from './modules/utils.js';
23
+ import { CONTEXT_DATA_KEYS, DEBUG } from './modules/utils.js';
20
24
 
21
25
  /** @param {import('ventojs').Options} options */
22
26
  export function createVentoEngine(options) {
23
27
  /** @type {EleventyVentoEnvironment} */
24
28
  const env = ventojs(options);
25
- env.utils._11ty = { ctx: {}, functions: {} };
29
+ env.utils._11tyFns = { shortcodes: {}, pairedShortcodes: {} };
30
+ env.utils._11tyCtx = {};
26
31
 
27
- return {
28
- /** @param {string} path */
29
- getCachedSource(path) {
30
- return env.cache.get(path)?.source;
31
- },
32
-
33
- /** @param {string} path */
34
- emptyCache(path) {
35
- return path ? env.cache.delete(path) : env.cache.clear();
36
- },
37
-
38
- /** @param {import('ventojs/src/environment.js').Plugin[]} plugins */
39
- loadPlugins(plugins) {
40
- for (const plugin of plugins) {
41
- env.use(plugin);
42
- }
43
- },
32
+ /** @param {EleventyData} newContext */
33
+ function setContext(newContext) {
34
+ if (env.utils._11tyCtx?.page?.inputPath === newContext?.page?.inputPath) {
35
+ return;
36
+ }
44
37
 
45
- /** @param {PageData} newContext */
46
- loadContext(newContext) {
47
- // Loop through allowed keys and load those into the context
48
- for (const K of CONTEXT_DATA_KEYS) {
49
- env.utils._11ty.ctx[K] = newContext[K];
50
- }
51
- },
38
+ for (const K of CONTEXT_DATA_KEYS) {
39
+ env.utils._11tyCtx[K] = newContext[K];
40
+ }
52
41
 
53
- /** @param {Record<string, EleventyFunction>} filters */
54
- loadFilters(filters) {
55
- for (const [name, fn] of Object.entries(filters)) {
56
- env.filters[name] = (...args) => fn.apply(env.utils._11ty.ctx, args);
57
- }
58
- },
59
-
60
- /**
61
- * @param {Record<string, EleventyFunction>} shortcodes
62
- * @param {boolean} paired
63
- */
64
- loadShortcodes(shortcodes, paired = false) {
65
- for (const [name, fn] of Object.entries(shortcodes)) {
66
- env.utils._11ty.functions[name] = fn;
67
- env.tags.push(createVentoTag(name, paired));
42
+ DEBUG.setup('Reload context, new context is: %o', env.utils._11tyCtx);
43
+ }
44
+
45
+ /** @param {import('ventojs/src/environment.js').Plugin[]} plugins */
46
+ function loadPlugins(plugins) {
47
+ for (const plugin of plugins) {
48
+ env.use(plugin);
49
+ }
50
+ }
51
+
52
+ /** @param {Record<string, EleventyFunction>} filters */
53
+ function loadFilters(filters) {
54
+ for (const [name, fn] of Object.entries(filters)) {
55
+ env.filters[name] = fn.bind(env.utils._11tyCtx);
56
+ }
57
+ }
58
+
59
+ /** @param {Record<string, EleventyFunction>} shortcodes */
60
+ function loadShortcodes(shortcodes) {
61
+ for (const [name, fn] of Object.entries(shortcodes)) {
62
+ env.utils._11tyFns.shortcodes[name] = fn;
63
+ env.tags.push(createVentoTag({ name, group: 'shortcodes' }));
64
+ }
65
+ }
66
+
67
+ /** @param {Record<string, EleventyFunction>} pairedShortcodes */
68
+ function loadPairedShortcodes(pairedShortcodes) {
69
+ for (const [name, fn] of Object.entries(pairedShortcodes)) {
70
+ env.utils._11tyFns.pairedShortcodes[name] = fn;
71
+ env.tags.push(createVentoTag({ name, group: 'pairedShortcodes' }));
72
+ }
73
+ }
74
+
75
+ /**
76
+ * @param {string} source
77
+ * @param {string} file
78
+ * @param {boolean} [useVentoCache=true]
79
+ */
80
+ function getTemplateFunction(source, file, useVentoCache = true) {
81
+ // Attempt to retrieve template function from cache
82
+ let template = env.cache.get(file);
83
+
84
+ if (template?.source === source) {
85
+ DEBUG.cache('Cache HIT for `%s`, used precompiled template', file);
86
+ } else {
87
+ template = env.compile(source, file);
88
+
89
+ DEBUG.cache(
90
+ `Cache MISS for \`%s\`, compiled new template:\nUse Vento cache: %o\n\n${template}`,
91
+ file,
92
+ useVentoCache
93
+ );
94
+ if (useVentoCache) {
95
+ env.cache.set(file, template);
68
96
  }
69
- },
97
+ }
98
+
99
+ return template;
100
+ }
70
101
 
71
- /** @param {{data: PageData, source: string, path: string}} input */
72
- async process(input) {
73
- // Reload context
74
- this.loadContext(input.data);
102
+ /**
103
+ * @param {import('ventojs/src/environment.js').Template} template
104
+ * @param {EleventyData} data
105
+ * @param {string} from
106
+ */
107
+ async function render(template, data, from) {
108
+ // Load new context
109
+ setContext(data);
75
110
 
76
- // Process the templates
77
- const result = await env.runString(input.source, input.data, input.path);
111
+ // Render template
112
+ DEBUG.render('Rendering `%s`', from);
113
+ const { content } = await template(data);
114
+ return content;
115
+ }
78
116
 
79
- return result.content;
80
- },
117
+ return {
118
+ cache: env.cache,
119
+ loadPlugins,
120
+ loadFilters,
121
+ loadShortcodes,
122
+ loadPairedShortcodes,
123
+ getTemplateFunction,
124
+ render,
81
125
  };
82
126
  }
package/src/index.js CHANGED
@@ -20,19 +20,23 @@
20
20
  * (See [Vento Docs](https://vento.js.org/configuration/#options))
21
21
  */
22
22
 
23
+ // Built-ins
24
+ import path from 'node:path';
25
+
23
26
  // External modules
24
27
  import autotrimPlugin, { defaultTags as autotrimDefaultTags } from 'ventojs/plugins/auto_trim.js';
25
28
 
26
29
  // Local modules
27
30
  import { createVentoEngine } from './engine.js';
28
31
  import { ignoreTagPlugin } from './modules/ignore-tag.js';
29
- import { runCompatibilityCheck } from './modules/utils.js';
32
+ import { DEBUG, runCompatibilityCheck } from './modules/utils.js';
30
33
 
31
34
  /**
32
35
  * @param {import('@11ty/eleventy').UserConfig} eleventyConfig
33
36
  * @param {Partial<VentoPluginOptions>} userOptions
34
37
  */
35
38
  export function VentoPlugin(eleventyConfig, userOptions) {
39
+ DEBUG.setup('Initializing eleventy-plugin-vento');
36
40
  runCompatibilityCheck(eleventyConfig);
37
41
 
38
42
  /** @type {VentoPluginOptions} */
@@ -52,10 +56,17 @@ export function VentoPlugin(eleventyConfig, userOptions) {
52
56
  ...userOptions,
53
57
  };
54
58
 
59
+ DEBUG.setup('Merged default and user config: %O', options);
60
+
55
61
  // Get list of filters, shortcodes and paired shortcodes
56
62
  const filters = eleventyConfig.getFilters();
63
+ DEBUG.setup('Reading filters from Eleventy: %o', filters);
64
+
57
65
  const shortcodes = eleventyConfig.getShortcodes();
66
+ DEBUG.setup('Reading shortcodes from Eleventy: %o', shortcodes);
67
+
58
68
  const pairedShortcodes = eleventyConfig.getPairedShortcodes();
69
+ DEBUG.setup('Reading paired shortcodes from Eleventy: %o', pairedShortcodes);
59
70
 
60
71
  // Add autotrim plugin if enabled
61
72
  if (options.autotrim) {
@@ -78,61 +89,89 @@ export function VentoPlugin(eleventyConfig, userOptions) {
78
89
  }
79
90
  }
80
91
 
92
+ DEBUG.setup('Enabled autotrim for tags: %o', tagSet);
93
+
81
94
  options.plugins.push(autotrimPlugin({ tags: [...tagSet] }));
82
95
  }
83
96
 
84
97
  // Add ignore tag plugin if enabled
85
98
  if (options.ignoreTag) {
99
+ DEBUG.setup('Enabling `{{! ... }}` tag syntax');
86
100
  options.plugins.push(ignoreTagPlugin);
87
101
  }
88
102
 
89
103
  // Create the vento engine instance
104
+ DEBUG.setup('Initializing Vento environment');
90
105
  const engine = createVentoEngine(options.ventoOptions);
91
106
 
92
107
  // Load plugins
108
+ DEBUG.setup('Loading plugins: %o', options.plugins);
93
109
  engine.loadPlugins(options.plugins);
94
110
 
95
111
  // Add filters, single and paired shortcodes if enabled
96
112
  if (options.filters) {
113
+ DEBUG.setup('Loading filters: %o', filters);
97
114
  engine.loadFilters(filters);
98
115
  }
99
116
  if (options.shortcodes) {
100
- engine.loadShortcodes(shortcodes, false);
117
+ DEBUG.setup('Loading shortcodes: %o', shortcodes);
118
+ engine.loadShortcodes(shortcodes);
101
119
  }
102
120
  if (options.pairedShortcodes) {
103
- engine.loadShortcodes(pairedShortcodes, true);
121
+ DEBUG.setup('Loading paired shortcodes: %o', pairedShortcodes);
122
+ engine.loadPairedShortcodes(pairedShortcodes);
104
123
  }
105
124
 
125
+ // Handle emptying the cache when files are updated
126
+ DEBUG.setup('Registering Vento cache handler on eleventy.beforeWatch event');
127
+ eleventyConfig.on('eleventy.beforeWatch', async (updatedFiles) => {
128
+ for (let file of updatedFiles) {
129
+ file = path.normalize(file);
130
+ DEBUG.cache('Delete cache entry for %s', file);
131
+ engine.cache.delete(file);
132
+ }
133
+ });
134
+
106
135
  // Add vto as a template format
136
+ DEBUG.setup('Registering .vto as a template format');
107
137
  eleventyConfig.addTemplateFormats('vto');
108
138
 
109
139
  // Add extension handling
140
+ DEBUG.setup('Registering .vto extension with eleventy');
110
141
  eleventyConfig.addExtension('vto', {
111
142
  outputFileExtension: 'html',
112
143
  read: true,
113
144
 
114
- // Main compile function
115
- async compile(inputContent, inputPath) {
116
- return async (data) => await engine.process({ data, source: inputContent, path: inputPath });
145
+ compile(inputContent, inputPath) {
146
+ // Normalize input path
147
+ inputPath = path.normalize(inputPath);
148
+
149
+ // Retrieve the template function
150
+ const template = engine.getTemplateFunction(inputContent, inputPath, false);
151
+
152
+ // Return a render function
153
+ return async (data) => await engine.render(template, data, inputPath);
117
154
  },
118
155
 
119
- // Custom permalink compilation
120
156
  compileOptions: {
121
- cache: true,
122
- getCacheKey(inputContent, inputPath) {
123
- if (engine.getCachedSource(inputPath) !== inputContent) {
124
- engine.emptyCache(inputPath);
157
+ // Custom permalink compilation
158
+ permalink(permalinkContent, inputPath) {
159
+ // Short circuit if input isn't a string and doesn't look like a vento template
160
+ if (typeof permalinkContent === 'string' && /\{\{\s+.+\s+\}\}/.test(permalinkContent)) {
161
+ // Normalize input path
162
+ inputPath = 'Permalink::' + path.normalize(inputPath);
163
+
164
+ // Retrieve the template function
165
+ const template = engine.getTemplateFunction(permalinkContent, inputPath);
166
+
167
+ // Return a render function
168
+ return async (data) => await engine.render(template, data, inputPath);
125
169
  }
126
170
 
127
- return engine.getCachedSource(inputPath);
128
- },
129
- permalink(linkContents) {
130
- if (typeof linkContents !== 'string') {
131
- return linkContents;
132
- }
133
-
134
- return async (data) => engine.process({ data, source: linkContents });
171
+ return permalinkContent;
135
172
  },
136
173
  },
137
174
  });
175
+
176
+ DEBUG.setup('eleventy-plugin-vento initialized');
138
177
  }
@@ -1,19 +1,20 @@
1
1
  /**
2
2
  * @file Helper function that creates vento tags from eleventy functions
3
3
  *
4
- * @param {string} name
5
- * @param {boolean} paired
4
+ * @param {{name: string, group: 'shortcodes' | 'pairedShortcodes' }} options
6
5
  */
7
6
 
8
- export function createVentoTag(name, paired) {
7
+ export function createVentoTag(options) {
8
+ const IS_PAIRED = options.group === 'pairedShortcodes';
9
+
9
10
  /** @type {import("ventojs/src/environment.js").Tag} */
10
11
  const tag = (env, code, output, tokens) => {
11
- if (!code.startsWith(name)) return;
12
+ if (!code.startsWith(options.name)) return;
12
13
 
13
- // Declare helper object path strings
14
- const fn = `__env.utils._11ty.functions.${name}`;
15
- const ctx = '__env.utils._11ty.ctx';
16
- let args = [code.replace(name, '').trim()];
14
+ // Declare helper variables for repeated strings in template
15
+ const fn = `__env.utils._11tyFns.${options.group}.${options.name}`;
16
+ const ctx = '__env.utils._11tyCtx';
17
+ const args = [code.replace(options.name, '').trim()];
17
18
 
18
19
  const varname = output.startsWith('__shortcode_content')
19
20
  ? `${output}_precomp`
@@ -22,35 +23,38 @@ export function createVentoTag(name, paired) {
22
23
  // Create an array to hold compiled template code
23
24
  const compiled = [];
24
25
 
25
- if (paired) {
26
+ if (IS_PAIRED) {
26
27
  args.unshift(env.compileFilters(tokens, varname, env.options.autoescape));
27
28
  compiled.push(
28
29
  '{',
29
30
  `let ${varname} = "";`,
30
- ...env.compileTokens(tokens, varname, [`/${name}`])
31
+ ...env.compileTokens(tokens, varname, [`/${options.name}`])
31
32
  );
32
- if (tokens.length > 0 && (tokens[0][0] !== 'tag' || tokens[0][1] !== `/${name}`)) {
33
- throw new Error(`Missing closing tag for ${name} tag: ${code}`);
33
+ if (tokens.length > 0 && (tokens[0][0] !== 'tag' || tokens[0][1] !== `/${options.name}`)) {
34
+ throw new Error(`Vento: Missing closing tag for ${options.name} tag: ${code}`);
34
35
  }
35
36
  tokens.shift();
36
37
  }
37
38
 
38
- // Compile arguments into a string
39
- args = args.some(Boolean) ? `, ${args.filter(Boolean).join(', ')}` : '';
39
+ args.unshift(ctx);
40
40
 
41
41
  compiled.push(
42
42
  '{',
43
- `const __shortcode_result = await ${fn}.call(${ctx + args});`,
43
+ `const __shortcode_result = await ${fn}.call(${args.filter(Boolean).join(', ')});`,
44
44
  `${output} += ${env.compileFilters(tokens, '__shortcode_result', env.options.autoescape)}`,
45
45
  '}'
46
46
  );
47
47
 
48
- if (paired) compiled.push('}');
48
+ if (IS_PAIRED) {
49
+ compiled.push('}');
50
+ }
49
51
 
50
- // console.log(compiled);
52
+ const compiledTag = compiled.join('\n');
51
53
 
52
- return compiled.join('\n');
54
+ return compiledTag;
53
55
  };
54
56
 
55
- return Object.defineProperty(tag, 'name', { value: paired ? `${name}PairedTag` : `${name}Tag` });
57
+ return Object.defineProperty(tag, 'name', {
58
+ value: options.name + IS_PAIRED ? `PairedTag` : `Tag`,
59
+ });
56
60
  }
@@ -1,3 +1,12 @@
1
+ // Set up debugger global
2
+ import createDebugger from 'debug';
3
+ const debugBaseNamespace = 'Eleventy:Vento';
4
+ export const DEBUG = {
5
+ setup: createDebugger(`${debugBaseNamespace}:Setup`),
6
+ cache: createDebugger(`${debugBaseNamespace}:Cache`),
7
+ render: createDebugger(`${debugBaseNamespace}:Render`),
8
+ };
9
+
1
10
  // Project-wide constants
2
11
  export const REQUIRED_API_METHODS = [
3
12
  ['getShortcodes', 'v3.0.0-alpha.15'],
@@ -8,17 +17,17 @@ export const REQUIRED_API_METHODS = [
8
17
 
9
18
  export const CONTEXT_DATA_KEYS = ['page', 'eleventy'];
10
19
 
11
- // Project-wide helper functions
12
- export function logError(message) {
13
- console.error(`[eleventy-plugin-vento] ${message}`);
14
- }
15
-
16
- /** @param {import("@11ty/eleventy").UserConfig} configApi */
17
- export function runCompatibilityCheck(configApi) {
20
+ // Helper functions
21
+ export function runCompatibilityCheck(config) {
22
+ DEBUG.setup('Run compatibility check');
18
23
  for (const [method, version] of REQUIRED_API_METHODS) {
19
- if (!configApi?.[method]) {
20
- logError(
21
- `Eleventy plugin compatibility error: '${method}' not available. Use Eleventy ${version} or later.`
24
+ if (!config?.[method]) {
25
+ console.error(
26
+ '[eleventy-plugin-vento] Plugin compatibility error:',
27
+ `\`${method}\``,
28
+ 'not found. Please use Eleventy',
29
+ version,
30
+ 'or later.'
22
31
  );
23
32
  }
24
33
  }