@static-pages/core 2.1.0 → 3.0.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/README.md CHANGED
@@ -32,10 +32,10 @@ This project targets small and medium sized projects. The rendering process trie
32
32
  __Readers__ provides an iterable list of page data. __Controllers__ can manipulate and extend each data object. __Writers__ render the final output for you.
33
33
 
34
34
  ```js
35
- const staticPages = require("@static-pages/core").default;
36
- const markdownReader = require("@static-pages/markdown-reader").default;
37
- const yamlReader = require("@static-pages/yaml-reader").default;
38
- const twigWriter = require("@static-pages/twig-writer").default;
35
+ import staticPages from '@static-pages/core';
36
+ import markdownReader from '@static-pages/markdown-reader';
37
+ import yamlReader from '@static-pages/yaml-reader';
38
+ import twigWriter from '@static-pages/twig-writer';
39
39
 
40
40
  staticPages([{
41
41
  from: markdownReader({
@@ -84,22 +84,7 @@ type Data = Record<string, unknown>;
84
84
  type Data = { [k: string]: unknown };
85
85
  ```
86
86
 
87
- ## Custom options for the controller
88
- You can pass additional configuration options to your controller under the `variables` property.
89
- These variables are accessible through the `this` context variable of the controller.
90
-
91
- ```js
92
- require("@static-pages/core").default([{
93
- from: ...,
94
- to: ...,
95
- controller: function(data) {
96
- this.myProp; // <-- 123
97
- },
98
- variables: {
99
- myProp: 123,
100
- },
101
- }]);
102
- ```
87
+ > When `Options` is not passed as an array, it is wrapped into an array.
103
88
 
104
89
  ## Missing a feature?
105
90
  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/cjs/index.d.ts CHANGED
@@ -4,7 +4,6 @@ export declare type Route = {
4
4
  from: Iterable<Data> | AsyncIterable<Data>;
5
5
  to: (data: Data) => void | Promise<void>;
6
6
  controller?: Controller;
7
- variables?: Record<string, unknown>;
8
7
  };
9
8
  export declare const staticPages: (routes: Route | Route[]) => Promise<void>;
10
9
  export default staticPages;
package/cjs/index.js CHANGED
@@ -10,7 +10,7 @@ const staticPages = async (routes) => {
10
10
  for (const route of Array.isArray(routes) ? routes : [routes]) {
11
11
  if (typeof route !== 'object' || !route)
12
12
  throw new Error(`Route type mismatch, expected 'object', got '${getType(route)}'.`);
13
- const { from, to, controller, variables } = route;
13
+ const { from, to, controller } = route;
14
14
  if (!isIterable(from) && !isAsyncIterable(from))
15
15
  throw new Error('Route \'from\' is not an \'iterable\' or an \'asyncIterable\'.');
16
16
  if (typeof to !== 'function')
@@ -19,7 +19,7 @@ const staticPages = async (routes) => {
19
19
  throw new Error(`Route 'controller' type mismatch, expected 'function', got '${getType(controller)}'.`);
20
20
  const isController = typeof controller === 'function';
21
21
  for await (const data of from) {
22
- const results = isController ? await controller.call(variables, data) : data;
22
+ const results = isController ? await controller(data) : data;
23
23
  if (typeof results === 'object' && results) {
24
24
  if (Array.isArray(results)) {
25
25
  for (const result of results) {
package/esm/index.d.ts CHANGED
@@ -4,7 +4,6 @@ export declare type Route = {
4
4
  from: Iterable<Data> | AsyncIterable<Data>;
5
5
  to: (data: Data) => void | Promise<void>;
6
6
  controller?: Controller;
7
- variables?: Record<string, unknown>;
8
7
  };
9
8
  export declare const staticPages: (routes: Route | Route[]) => Promise<void>;
10
9
  export default staticPages;
package/esm/index.js CHANGED
@@ -7,7 +7,7 @@ export const staticPages = async (routes) => {
7
7
  for (const route of Array.isArray(routes) ? routes : [routes]) {
8
8
  if (typeof route !== 'object' || !route)
9
9
  throw new Error(`Route type mismatch, expected 'object', got '${getType(route)}'.`);
10
- const { from, to, controller, variables } = route;
10
+ const { from, to, controller } = route;
11
11
  if (!isIterable(from) && !isAsyncIterable(from))
12
12
  throw new Error('Route \'from\' is not an \'iterable\' or an \'asyncIterable\'.');
13
13
  if (typeof to !== 'function')
@@ -16,7 +16,7 @@ export const staticPages = async (routes) => {
16
16
  throw new Error(`Route 'controller' type mismatch, expected 'function', got '${getType(controller)}'.`);
17
17
  const isController = typeof controller === 'function';
18
18
  for await (const data of from) {
19
- const results = isController ? await controller.call(variables, data) : data;
19
+ const results = isController ? await controller(data) : data;
20
20
  if (typeof results === 'object' && results) {
21
21
  if (Array.isArray(results)) {
22
22
  for (const result of results) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@static-pages/core",
3
- "version": "2.1.0",
3
+ "version": "3.0.0",
4
4
  "description": "General purpose static pages renderer.",
5
5
  "type": "module",
6
6
  "main": "./cjs/index.js",