@static-pages/core 3.0.1 → 3.0.2

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 (2) hide show
  1. package/README.md +16 -10
  2. package/package.json +1 -1
package/README.md CHANGED
@@ -46,11 +46,11 @@ staticPages([{
46
46
  viewsDir: "path/to/views/folder",
47
47
  outDir: "path/to/output/folder",
48
48
  }),
49
- controller: function(data) {
49
+ controller(data) {
50
50
  data.timestamp = new Date().toJSON(); // adds a "timestamp" variable
51
51
  return data; // returning the data is required if you want to send it to the renderer
52
52
  }
53
- },{
53
+ }, {
54
54
  from: yamlReader({ // assume we have the home page data in yaml format.
55
55
  pattern: "home/*.yaml" // <-- reads home/en.yaml, home/de.yaml, home/fr.yaml etc.
56
56
  }),
@@ -59,27 +59,33 @@ staticPages([{
59
59
  viewsDir: "path/to/views/folder",
60
60
  outDir: "path/to/output/folder",
61
61
  }),
62
- controller: function(data) {
62
+ controller(data) {
63
63
  data.commitHash = yourGetCommitHashFn();
64
64
  return data;
65
65
  }
66
- }]).catch(console.error);
66
+ }])
67
+ .catch(error => {
68
+ console.error('Error:', error);
69
+ console.error(error.stack);
70
+ });
67
71
  ```
68
72
 
69
- ## `staticPages(options: Options)`
70
- The `staticPages()` function expects one parameter which must be an array.
71
- Each item should contain `from`, `to` and optionally a `controller` property matching the definition below.
73
+ ## `staticPages(routes: Route | Route[])`
74
+ The function expects the `routes` parameter to be an array. It is wrapped into an array automatically when other type is provided.
75
+ Each item in this array should be an object containing a `from`, `to` and optionally a `controller` property matching the definition below.
72
76
 
73
77
  ```ts
74
78
  type Data = Record<string, unknown>;
75
- type Options = {
79
+ type Route = {
76
80
  from: Iterable<Data> | AsyncIterable<Data>;
77
81
  to: (data: Data) => void | Promise<void>;
78
82
  controller?: (data: Data) => undefined | Data | Data[] | Promise<undefined | Data | Data[]>;
79
- }[];
83
+ };
80
84
  ```
81
85
 
82
- > Additionally, when `Options` is not passed as an array, it is wrapped into an array.
86
+ > Tip: Controllers may return an array of `Data` objects. Each data object will be rendered as a separate page.
87
+
88
+ > Tip: Controllers may return `undefined` to prevent the rendering of the current data object.
83
89
 
84
90
  ## Missing a feature?
85
91
  Create an issue describing your needs. If it fits the scope of the project I will implement it or you can implement it your own and submit a pull request.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@static-pages/core",
3
- "version": "3.0.1",
3
+ "version": "3.0.2",
4
4
  "description": "General purpose static pages renderer.",
5
5
  "type": "module",
6
6
  "main": "./cjs/index.js",