@static-pages/core 7.0.0-alpha.6 → 7.0.0-beta.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 +5 -18
- package/package.json +18 -12
- package/esm/index.d.ts +0 -13
- /package/{cjs → types}/index.d.ts +0 -0
package/README.md
CHANGED
|
@@ -17,7 +17,7 @@ Yes! Because I browsed the whole jamstack scene, but could not find one which
|
|
|
17
17
|
|
|
18
18
|
And because I wrote a ton of custom static generators before; I tought I can improve the concepts to a point where its (hopefully) useful for others.
|
|
19
19
|
|
|
20
|
-
This project is structured as a toolkit, published under the [@static-pages](https://www.npmjs.com/search?q=%40static-pages) namespace on NPM.
|
|
20
|
+
This project is structured as a toolkit split to many packages, published under the [@static-pages](https://www.npmjs.com/search?q=%40static-pages) namespace on NPM.
|
|
21
21
|
In most cases you should not use this core package directly, but the [@static-pages/starter](https://www.npmjs.com/package/@static-pages/starter) is a good point to begin with.
|
|
22
22
|
|
|
23
23
|
## Where should I use this?
|
|
@@ -42,22 +42,9 @@ staticPages({
|
|
|
42
42
|
},
|
|
43
43
|
to({ title, url, content, now }) {
|
|
44
44
|
const fileName = path.join('public', url + '.html');
|
|
45
|
+
const fileContent = `<html><body><h1>${title}</h1><p>${content}</p><p>generated: ${now}</p></body></html>`;
|
|
45
46
|
fs.mkdirSync(path.dirname(fileName), { recursive: true });
|
|
46
|
-
fs.writeFileSync(fileName,
|
|
47
|
-
}
|
|
48
|
-
}, {
|
|
49
|
-
from: fs.readdir('pages', { recursive: true })
|
|
50
|
-
.map(x => JSON.parse(fs.readFileSync(path.join('pages', x), 'utf8'))),
|
|
51
|
-
controller({ title, url, content }) {
|
|
52
|
-
return {
|
|
53
|
-
url: url,
|
|
54
|
-
content: `<html><body><h1>${title}</h1><p>${content}</p><p>generated: ${new Date().toJSON()}</p></body></html>`,
|
|
55
|
-
};
|
|
56
|
-
},
|
|
57
|
-
to({ url, content }) {
|
|
58
|
-
const fileName = path.join('public', url + '.html');
|
|
59
|
-
fs.mkdirSync(path.dirname(fileName), { recursive: true });
|
|
60
|
-
fs.writeFileSync(fileName, content);
|
|
47
|
+
fs.writeFileSync(fileName, fileContent);
|
|
61
48
|
}
|
|
62
49
|
})
|
|
63
50
|
.catch(error => {
|
|
@@ -68,8 +55,6 @@ staticPages({
|
|
|
68
55
|
|
|
69
56
|
### Notes
|
|
70
57
|
|
|
71
|
-
> The `controller` may return with multiple documents, each will be rendered as a separate page. Alternatively it may return `undefined` to prevent the rendering of the current document.
|
|
72
|
-
|
|
73
58
|
> The usage example above does a rough presentation only and not considered to be a production ready snippet. Helpers to read and write documents are provided in separate packages, eg. [@static-pages/io](https://www.npmjs.com/package/@static-pages/io).
|
|
74
59
|
|
|
75
60
|
## Documentation
|
|
@@ -88,6 +73,8 @@ interface Route<F, T> {
|
|
|
88
73
|
}
|
|
89
74
|
```
|
|
90
75
|
|
|
76
|
+
The `controller` may return with multiple documents, each will be rendered as a separate page. Alternatively it may return `undefined` to prevent the rendering of the current document.
|
|
77
|
+
|
|
91
78
|
## Missing a feature?
|
|
92
79
|
Create an issue describing your needs!
|
|
93
80
|
If it fits the scope of the project I will implement it.
|
package/package.json
CHANGED
|
@@ -1,30 +1,36 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@static-pages/core",
|
|
3
|
-
"version": "7.0.0-
|
|
3
|
+
"version": "7.0.0-beta.1",
|
|
4
4
|
"description": "General purpose static pages renderer.",
|
|
5
5
|
"type": "module",
|
|
6
|
-
"main": "cjs/index.js",
|
|
7
|
-
"module": "esm/index.js",
|
|
8
|
-
"types": "esm/index.d.ts",
|
|
6
|
+
"main": "./cjs/index.js",
|
|
7
|
+
"module": "./esm/index.js",
|
|
8
|
+
"types": "./esm/index.d.ts",
|
|
9
9
|
"exports": {
|
|
10
10
|
".": {
|
|
11
|
+
"import": "./esm/index.js",
|
|
11
12
|
"require": "./cjs/index.js",
|
|
12
|
-
"
|
|
13
|
-
}
|
|
13
|
+
"types": "./types/index.d.ts"
|
|
14
|
+
},
|
|
15
|
+
"./package.json": "./package.json"
|
|
14
16
|
},
|
|
15
17
|
"engines": {
|
|
16
18
|
"node": ">=16.0.0",
|
|
17
19
|
"deno": ">=1.0.0"
|
|
18
20
|
},
|
|
19
21
|
"scripts": {
|
|
20
|
-
"
|
|
22
|
+
"preversion": "npm run build && npm run test",
|
|
21
23
|
"postversion": "git push && git push --tags",
|
|
22
|
-
"clean": "rimraf esm cjs coverage",
|
|
23
|
-
"
|
|
24
|
-
"build:esm": "tsc",
|
|
24
|
+
"clean": "rimraf esm cjs types coverage",
|
|
25
|
+
"prewatch:esm": "npm run build:esm",
|
|
25
26
|
"watch:esm": "tsc --watch",
|
|
26
|
-
"
|
|
27
|
-
"watch:cjs": "
|
|
27
|
+
"prewatch:cjs": "npm run build:cjs",
|
|
28
|
+
"watch:cjs": "tsc --outDir cjs --module commonjs --moduleResolution node --watch",
|
|
29
|
+
"build": "npm run build:esm && npm run build:cjs && npm run build:types",
|
|
30
|
+
"build:esm": "tsc",
|
|
31
|
+
"build:cjs": "tsc --outDir cjs --module commonjs --moduleResolution node",
|
|
32
|
+
"postbuild:cjs": "echo { \"type\": \"commonjs\" }>cjs/package.json",
|
|
33
|
+
"build:types": "tsc --outDir types --declaration --emitDeclarationOnly",
|
|
28
34
|
"lint": "eslint",
|
|
29
35
|
"test": "mocha",
|
|
30
36
|
"coverage": "c8 -r text -r text-summary -r lcov --include \"esm/*\" npm test"
|
package/esm/index.d.ts
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
export interface Route<F = unknown, T = unknown> {
|
|
2
|
-
from: Iterable<F> | AsyncIterable<F>;
|
|
3
|
-
to(data: T): void | Promise<void>;
|
|
4
|
-
controller?(data: F): undefined | T | Iterable<T> | AsyncIterable<T> | Promise<undefined | T | Iterable<T> | AsyncIterable<T>>;
|
|
5
|
-
}
|
|
6
|
-
export declare function staticPages<F1, T1>(...route: [Route<F1, T1>]): Promise<void>;
|
|
7
|
-
export declare function staticPages<F1, T1, F2, T2>(...route: [Route<F1, T1>, Route<F2, T2>]): Promise<void>;
|
|
8
|
-
export declare function staticPages<F1, T1, F2, T2, F3, T3>(...route: [Route<F1, T1>, Route<F2, T2>, Route<F3, T3>]): Promise<void>;
|
|
9
|
-
export declare function staticPages<F1, T1, F2, T2, F3, T3, F4, T4>(...route: [Route<F1, T1>, Route<F2, T2>, Route<F3, T3>, Route<F4, T4>]): Promise<void>;
|
|
10
|
-
export declare function staticPages<F1, T1, F2, T2, F3, T3, F4, T4, F5, T5>(...route: [Route<F1, T1>, Route<F2, T2>, Route<F3, T3>, Route<F4, T4>, Route<F5, T5>]): Promise<void>;
|
|
11
|
-
export declare function staticPages<F1, T1, F2, T2, F3, T3, F4, T4, F5, T5, F6, T6>(...route: [Route<F1, T1>, Route<F2, T2>, Route<F3, T3>, Route<F4, T4>, Route<F5, T5>, Route<F6, T6>]): Promise<void>;
|
|
12
|
-
export declare function staticPages(...routes: Route[]): Promise<void>;
|
|
13
|
-
export default staticPages;
|
|
File without changes
|