mikel-press 0.27.1 → 0.29.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.
Files changed (3) hide show
  1. package/README.md +14 -0
  2. package/index.js +18 -1
  3. package/package.json +1 -1
package/README.md CHANGED
@@ -162,6 +162,20 @@ This plugin loads additional files (aka assets) and includes them in the build f
162
162
 
163
163
  This plugin processes and parses the frontmatter in each file. The parsed frontmatter content will be available in `page.attributes` field.
164
164
 
165
+ ### `press.TransformPlugin(options)`
166
+
167
+ A generic transform plugin that will execute the provided `options.transform` function with the `context` and the current `node` object. Example:
168
+
169
+ ```javascript
170
+ press.TransformPlugin({
171
+ transform: node => {
172
+ if (node.label === press.LABEL_PAGE && node.content && path.extname(node.source) === ".md") {
173
+ node.content = `{{#markdown}}\n\n${node.content}\n\n{{/markdown}}\n`;
174
+ }
175
+ },
176
+ });
177
+ ```
178
+
165
179
  ### `press.ContentPagePlugin()`
166
180
 
167
181
  This plugin processes each page using the mikel templating.
package/index.js CHANGED
@@ -39,6 +39,7 @@ press.createContext = (config = {}) => {
39
39
  ...plugins,
40
40
  ],
41
41
  nodes: [],
42
+ actions: {},
42
43
  });
43
44
  getPlugins(context, "init").forEach(plugin => {
44
45
  return plugin.init(context);
@@ -59,7 +60,15 @@ press.createContext = (config = {}) => {
59
60
 
60
61
  // @description build the provided context
61
62
  press.buildContext = (context, nodesToBuild = null) => {
62
- const nodes = Array.isArray(nodesToBuild) ? nodesToBuild : context.nodes;
63
+ const nodes = (Array.isArray(nodesToBuild) ? nodesToBuild : context.nodes).slice();
64
+ const createNode = (nodeLabel, nodeObject = {}) => {
65
+ nodes.push({ label: nodeLabel, content: "", ...nodeObject });
66
+ };
67
+ // 0. assign actions to context
68
+ Object.assign(context.actions, {
69
+ createPage: pageObject => createNode(press.LABEL_PAGE, pageObject),
70
+ createAsset: assetObject => createNode(press.LABEL_ASSET, assetObject),
71
+ });
63
72
  // 1. transform nodes
64
73
  getPlugins(context, "transform").forEach(plugin => {
65
74
  // special hook to initialize the transform plugin
@@ -247,6 +256,14 @@ press.LayoutsPlugin = (options = {}) => {
247
256
  });
248
257
  };
249
258
 
259
+ // @description generic transform plugin
260
+ press.TransformPlugin = (options = {}) => {
261
+ const transformFn = typeof options?.transform === "function" ? options.transform : options;
262
+ return {
263
+ transform: (context, node) => transformFn(node, context),
264
+ };
265
+ };
266
+
250
267
  // @description frontmatter plugin
251
268
  press.FrontmatterPlugin = () => {
252
269
  return {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "mikel-press",
3
3
  "description": "A tiny and fast static site generator based on mikel templating",
4
- "version": "0.27.1",
4
+ "version": "0.29.0",
5
5
  "type": "module",
6
6
  "license": "MIT",
7
7
  "author": {