@static-pages/core 3.0.1 → 3.0.4
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 +16 -10
- package/cjs/package.json +1 -3
- package/package.json +14 -11
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
|
|
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
|
|
62
|
+
controller(data) {
|
|
63
63
|
data.commitHash = yourGetCommitHashFn();
|
|
64
64
|
return data;
|
|
65
65
|
}
|
|
66
|
-
}])
|
|
66
|
+
}])
|
|
67
|
+
.catch(error => {
|
|
68
|
+
console.error('Error:', error);
|
|
69
|
+
console.error(error.stack);
|
|
70
|
+
});
|
|
67
71
|
```
|
|
68
72
|
|
|
69
|
-
## `staticPages(
|
|
70
|
-
The
|
|
71
|
-
Each item should
|
|
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
|
|
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
|
-
>
|
|
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/cjs/package.json
CHANGED
package/package.json
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@static-pages/core",
|
|
3
|
-
"version": "3.0.
|
|
3
|
+
"version": "3.0.4",
|
|
4
4
|
"description": "General purpose static pages renderer.",
|
|
5
5
|
"type": "module",
|
|
6
|
-
"main": "
|
|
7
|
-
"module": "
|
|
8
|
-
"
|
|
6
|
+
"main": "cjs/index.js",
|
|
7
|
+
"module": "esm/index.js",
|
|
8
|
+
"types": "esm/index.d.ts",
|
|
9
9
|
"exports": {
|
|
10
10
|
".": {
|
|
11
11
|
"require": "./cjs/index.js",
|
|
@@ -13,15 +13,15 @@
|
|
|
13
13
|
}
|
|
14
14
|
},
|
|
15
15
|
"scripts": {
|
|
16
|
-
"prepack": "npm run
|
|
16
|
+
"prepack": "npm run test",
|
|
17
17
|
"build": "npm run build:esm && npm run build:cjs",
|
|
18
18
|
"build:esm": "tsc",
|
|
19
|
-
"build:cjs": "tsc --outDir cjs --module commonjs",
|
|
20
19
|
"watch:esm": "tsc --watch",
|
|
21
|
-
"
|
|
22
|
-
"
|
|
23
|
-
"
|
|
24
|
-
"
|
|
20
|
+
"build:cjs": "tsc --project tsconfig.cjs.json && echo { \"type\": \"commonjs\" }>cjs/package.json",
|
|
21
|
+
"watch:cjs": "npm run build:cjs && tsc --project tsconfig.cjs.json --watch",
|
|
22
|
+
"test": "eslint src && npm run build && cross-env NODE_OPTIONS=--experimental-vm-modules jest",
|
|
23
|
+
"coverage": "cross-env NODE_OPTIONS=--experimental-vm-modules jest --coverage && cat ./coverage/lcov.info | coveralls",
|
|
24
|
+
"clean": "rimraf esm cjs coverage"
|
|
25
25
|
},
|
|
26
26
|
"repository": {
|
|
27
27
|
"type": "git",
|
|
@@ -45,12 +45,15 @@
|
|
|
45
45
|
},
|
|
46
46
|
"homepage": "https://staticpagesjs.github.io/",
|
|
47
47
|
"devDependencies": {
|
|
48
|
+
"@types/jest": "^28.1.6",
|
|
48
49
|
"@types/node": "^14.18.9",
|
|
49
50
|
"@typescript-eslint/eslint-plugin": "^5.3.0",
|
|
50
51
|
"@typescript-eslint/parser": "^5.3.0",
|
|
51
52
|
"coveralls": "^3.1.1",
|
|
53
|
+
"cross-env": "^7.0.3",
|
|
52
54
|
"eslint": "^8.1.0",
|
|
53
|
-
"jest": "^
|
|
55
|
+
"eslint-plugin-jest": "^26.6.0",
|
|
56
|
+
"jest": "^28.1.3",
|
|
54
57
|
"rimraf": "^3.0.2",
|
|
55
58
|
"typescript": "^4.4.4"
|
|
56
59
|
}
|