mikel-frontmatter 0.32.0 → 0.33.1

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
@@ -34,7 +34,7 @@ const m = mikel.create();
34
34
  m.use(mikelFrontmatter({ ... }));
35
35
  ```
36
36
 
37
- In your template, the `{{#frontmatter}}` helper allows you to define metadata at the beginning of your templates, similar to frontmatter in Markdown files. The parsed data is stored as a variable accessible via `@frontmatter` (or a custom variable name, see below).
37
+ In your template, the `{{#frontmatter}}` helper allows you to define metadata at the beginning of your templates, similar to frontmatter in Markdown files. The parsed data is stored as a state variable accessible via `@frontmatter` (or a custom variable name, see below).
38
38
 
39
39
  Example:
40
40
 
@@ -64,7 +64,7 @@ The `{{#frontmatter}}` helper accepts the following arguments:
64
64
 
65
65
  #### as
66
66
 
67
- Custom variable name to save parsed metadata. If not provided, parsed metadata will be saved in `@frontmatter`. Example:
67
+ Custom state variable name to save parsed metadata. If not provided, parsed metadata will be saved in `@frontmatter`. Example:
68
68
 
69
69
  ```html
70
70
  {{#frontmatter as="meta"}}
package/index.d.ts CHANGED
@@ -33,12 +33,11 @@ declare function mikelFrontmatter(options?: MikelFrontmatterOptions): {
33
33
  helpers: {
34
34
  frontmatter: (params: {
35
35
  args: any[];
36
- opt?: Record<string, any>;
37
36
  options: Record<string, any>;
38
37
  tokens: string[];
39
38
  data: Record<string, any>;
40
- variables: Record<string, any>;
41
- fn: (blockData?: Record<string, any>, blockVars?: Record<string, any>, blockOutput?: string[]) => string;
39
+ state: Record<string, any>;
40
+ fn: (blockData?: Record<string, any>, blockState?: Record<string, any>, blockOutput?: string[]) => string;
42
41
  }) => string;
43
42
  };
44
43
  };
package/index.js CHANGED
@@ -211,22 +211,20 @@ const parseFrontmatterBlock = (content = "", format = "yaml", parser = null) =>
211
211
  // @description plugin to register a #frontmatter helper
212
212
  // @param {Object} options - plugin options
213
213
  // @param {Function} options.parser - custom YAML parser function
214
- const mikelFrontmatter = (options = {}) => {
215
- return {
216
- helpers: {
217
- frontmatter: params => {
218
- const variableName = params.options.as || "frontmatter";
219
- const format = params.options.format || "yaml";
220
- // register the variable (overwrite if it already exists)
221
- Object.assign(params.variables, {
222
- [variableName]: parseFrontmatterBlock(params.fn(params.data) || "", format, options.parser),
223
- });
224
- // don't render anything
225
- return "";
226
- },
214
+ const mikelFrontmatter = (options = {}) => ({
215
+ helpers: {
216
+ frontmatter: params => {
217
+ const variableName = params.options.as || "frontmatter";
218
+ const format = params.options.format || "yaml";
219
+ // register the variable (overwrite if it already exists)
220
+ Object.assign(params.state, {
221
+ [variableName]: parseFrontmatterBlock(params.fn(params.data) || "", format, options.parser),
222
+ });
223
+ // don't render anything
224
+ return "";
227
225
  },
228
- };
229
- };
226
+ },
227
+ });
230
228
 
231
229
  // assign additional metadata to the plugin function
232
230
  mikelFrontmatter.yamlParser = parseYaml;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "mikel-frontmatter",
3
3
  "description": "A mikel plugin to define new data inside templates using a frontmatter-like syntax.",
4
- "version": "0.32.0",
4
+ "version": "0.33.1",
5
5
  "type": "module",
6
6
  "license": "MIT",
7
7
  "author": "Josemi Juanes",