@sphido/core 2.0.15 → 2.0.17

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2023 Roman Ožana (https://ozana.cz/)
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/lib/all-pages.js CHANGED
@@ -1,9 +1,8 @@
1
1
  /**
2
2
  * Page generator that flatten pages structure
3
3
  *
4
- * @generator
5
- * @param {array} pages
6
- * @yields {name:string, path:string} next page in pages list
4
+ * @param {import('get-pages.js').Pages} pages
5
+ * @return {import('get-pages.js').Page}
7
6
  */
8
7
  export function * allPages(pages) {
9
8
  for (const page of pages) {
package/lib/get-pages.js CHANGED
@@ -4,10 +4,10 @@ import {isPage} from './is-page.js';
4
4
 
5
5
  /**
6
6
  * Retrieve an array tree of pages from path
7
- * @param {string} path
8
- * @param {function(dirent:Dirent, path:string)} include
9
- * @param {Object|function(page:{name:string, path:string}, dirent:Dirent, path:string)} extenders
10
- * @returns {Promise<Awaited<unknown>[{name:string, path:string}]>}
7
+ *
8
+ * @param {Options}
9
+ * @param {Extenders} extenders
10
+ * @return {Promise<Awaited<Pages>[]>}
11
11
  */
12
12
  export async function getPages({path = 'content', include = isPage} = {}, ...extenders) {
13
13
  const dir = await readdir(path, {withFileTypes: true});
@@ -26,6 +26,7 @@ export async function getPages({path = 'content', include = isPage} = {}, ...ext
26
26
 
27
27
  // Calling callbacks in the series
28
28
  for (const cb of extenders.filter(f => typeof f === 'function')) {
29
+ /** @type {ExtenderCallback} */
29
30
  await cb(page, dirent, path);
30
31
  }
31
32
 
@@ -33,3 +34,23 @@ export async function getPages({path = 'content', include = isPage} = {}, ...ext
33
34
  return Object.assign(page, ...extenders.filter(o => typeof o === 'object'));
34
35
  }));
35
36
  }
37
+
38
+ /**
39
+ * @typedef {Array.<Object|ExtenderCallback>} Extenders
40
+ * @typedef {Array.<Page>} Pages
41
+ * @typedef {{name: string, path: string, children?: Pages}} Page
42
+ * @typedef {{path: string, include?: IncludePage}} Options
43
+ */
44
+
45
+ /**
46
+ * @callback ExtenderCallback
47
+ * @param {Page} page
48
+ * @param {import('node:fs').Dirent} dirent
49
+ * @param {string=} path
50
+ */
51
+
52
+ /**
53
+ * @callback IncludePage
54
+ * @param {import('node:fs').Dirent} dirent
55
+ * @param {string=} path
56
+ */
package/lib/is-page.js CHANGED
@@ -6,7 +6,7 @@
6
6
  * - skip drafts files with underscore at the beginning
7
7
  * - accept only *.html and *.md files
8
8
  *
9
- * @param {Dirent} dirent
9
+ * @param {import('node:fs').Dirent} dirent
10
10
  * @returns {boolean}
11
11
  */
12
12
  export function isPage(dirent) {
package/package.json CHANGED
@@ -1,49 +1,54 @@
1
1
  {
2
- "name": "@sphido/core",
3
- "version": "2.0.15",
4
- "author": {
5
- "name": "Roman Ožana",
6
- "email": "roman@ozana.cz",
7
- "url": "https://ozana.cz"
8
- },
9
- "license": "MIT",
10
- "description": "A rocket 🚀 fast, lightweight, static site generator",
11
- "type": "module",
12
- "exports": "./lib/index.js",
13
- "engines": {
14
- "node": ">=14"
15
- },
16
- "keywords": [
17
- "markdown",
18
- "markup",
19
- "content management system",
20
- "cms",
21
- "static",
22
- "static site generator",
23
- "generator",
24
- "framework",
25
- "numjucks",
26
- "blog",
27
- "scaffold"
28
- ],
29
- "homepage": "https://sphido.org",
30
- "bugs": "https://github.com/sphido/sphido/issues",
31
- "repository": {
32
- "type": "git",
33
- "url": "git@github.com:sphido/sphido.git"
34
- },
35
- "devDependencies": {
36
- "@sindresorhus/slugify": "^2.1.1",
37
- "ava": "^5.0.1",
38
- "marked": "^4.1.1"
39
- },
40
- "scripts": {
41
- "test": "ava"
42
- },
43
- "xo": {
44
- "rules": {
45
- "no-await-in-loop": 0
46
- }
47
- },
48
- "gitHead": "b94220085ab26b902780388fcfc11233fb9dcf68"
2
+ "name": "@sphido/core",
3
+ "version": "2.0.17",
4
+ "author": {
5
+ "name": "Roman Ožana",
6
+ "email": "roman@ozana.cz",
7
+ "url": "https://ozana.cz"
8
+ },
9
+ "license": "MIT",
10
+ "description": "A rocket 🚀 fast, lightweight, static site generator",
11
+ "type": "module",
12
+ "exports": "./lib/index.js",
13
+ "engines": {
14
+ "node": ">=16"
15
+ },
16
+ "types": "types/index.d.ts",
17
+ "keywords": [
18
+ "markdown",
19
+ "markup",
20
+ "content management system",
21
+ "cms",
22
+ "static",
23
+ "static site generator",
24
+ "generator",
25
+ "framework",
26
+ "numjucks",
27
+ "blog",
28
+ "scaffold"
29
+ ],
30
+ "homepage": "https://sphido.org",
31
+ "bugs": "https://github.com/sphido/sphido/issues",
32
+ "repository": {
33
+ "type": "git",
34
+ "url": "git@github.com:sphido/sphido.git"
35
+ },
36
+ "devDependencies": {
37
+ "@sindresorhus/slugify": "^2.2.0",
38
+ "ava": "^5.2.0",
39
+ "marked": "^4.2.12"
40
+ },
41
+ "scripts": {
42
+ "test": "ava",
43
+ "types": "tsc lib/*.js --declaration --allowJs --emitDeclarationOnly --outDir types"
44
+ },
45
+ "xo": {
46
+ "ignores": [
47
+ "types/**"
48
+ ],
49
+ "rules": {
50
+ "no-await-in-loop": 0
51
+ }
52
+ },
53
+ "gitHead": "6d977aa261aecb80b4221c9af8ff61e8756a9456"
49
54
  }
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Page generator that flatten pages structure
3
+ *
4
+ * @param {import('get-pages.js').Pages} pages
5
+ * @return {import('get-pages.js').Page}
6
+ */
7
+ export function allPages(pages: any): any;
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Write content to the file and create directory if not exists
3
+ *
4
+ * @param {string} src
5
+ * @param {string} dest
6
+ * @returns {Promise<*>}
7
+ */
8
+ export function copyFile(src: string, dest: string): Promise<any>;
@@ -0,0 +1,21 @@
1
+ /**
2
+ * Retrieve an array tree of pages from path
3
+ *
4
+ * @param {Options}
5
+ * @param {Extenders} extenders
6
+ * @return {Promise<Awaited<Pages>[]>}
7
+ */
8
+ export function getPages({ path, include }?: Options, ...extenders: Extenders): Promise<Awaited<Pages>[]>;
9
+ export type Extenders = Array<any | ExtenderCallback>;
10
+ export type Pages = Array<Page>;
11
+ export type Page = {
12
+ name: string;
13
+ path: string;
14
+ children?: Page[];
15
+ };
16
+ export type Options = {
17
+ path: string;
18
+ include?: IncludePage;
19
+ };
20
+ export type ExtenderCallback = (page: Page, dirent: import('node:fs').Dirent, path?: string | undefined) => any;
21
+ export type IncludePage = (dirent: import('node:fs').Dirent, path?: string | undefined) => any;
@@ -0,0 +1,5 @@
1
+ export { getPages } from "./get-pages.js";
2
+ export { allPages } from "./all-pages.js";
3
+ export { readFile } from "./read-file.js";
4
+ export { writeFile } from "./write-file.js";
5
+ export { copyFile } from "./copy-file.js";
@@ -0,0 +1,12 @@
1
+ /**
2
+ * Default page filter
3
+ *
4
+ * - skip hidden files (starts with .)
5
+ * - skip and directories (starts with .)
6
+ * - skip drafts files with underscore at the beginning
7
+ * - accept only *.html and *.md files
8
+ *
9
+ * @param {import('node:fs').Dirent} dirent
10
+ * @returns {boolean}
11
+ */
12
+ export function isPage(dirent: import('node:fs').Dirent): boolean;
@@ -0,0 +1,6 @@
1
+ /**
2
+ * Read file content as string
3
+ * @param {string} path
4
+ * @returns {Promise<*>}
5
+ */
6
+ export function readFile(path: string): Promise<any>;
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Write content to the file and create directory if not exists
3
+ *
4
+ * @param {string} file
5
+ * @param {string} content
6
+ * @returns {Promise<*>}
7
+ */
8
+ export function writeFile(file: string, content: string): Promise<any>;
package/LICENSE.md DELETED
@@ -1,24 +0,0 @@
1
- MIT License
2
- -----------
3
-
4
- Copyright (c) 2022 Roman Ožana (https://ozana.cz/)
5
- Permission is hereby granted, free of charge, to any person
6
- obtaining a copy of this software and associated documentation
7
- files (the "Software"), to deal in the Software without
8
- restriction, including without limitation the rights to use,
9
- copy, modify, merge, publish, distribute, sublicense, and/or sell
10
- copies of the Software, and to permit persons to whom the
11
- Software is furnished to do so, subject to the following
12
- conditions:
13
-
14
- The above copyright notice and this permission notice shall be
15
- included in all copies or substantial portions of the Software.
16
-
17
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18
- EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
19
- OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
20
- NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
21
- HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
22
- WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
23
- FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
24
- OTHER DEALINGS IN THE SOFTWARE.