@sphido/core 2.0.30 → 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.
@@ -0,0 +1,6 @@
1
+ import type { Page, Pages } from "./index.js";
2
+ /**
3
+ * Page generator that flatten pages structure
4
+ */
5
+ export declare function allPages(pages: Pages): Generator<Page>;
6
+ //# sourceMappingURL=all-pages.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"all-pages.d.ts","sourceRoot":"","sources":["../lib/all-pages.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AAE9C;;GAEG;AACH,wBAAiB,QAAQ,CAAC,KAAK,EAAE,KAAK,GAAG,SAAS,CAAC,IAAI,CAAC,CAQvD"}
@@ -0,0 +1,13 @@
1
+ /**
2
+ * Page generator that flatten pages structure
3
+ */
4
+ export function* allPages(pages) {
5
+ for (const page of pages) {
6
+ if (page?.children) {
7
+ yield* allPages(page.children);
8
+ }
9
+ else {
10
+ yield page;
11
+ }
12
+ }
13
+ }
@@ -0,0 +1,5 @@
1
+ /**
2
+ * Write content to the file and create directory if not exists
3
+ */
4
+ export declare function copyFile(src: string, dest: string): Promise<void>;
5
+ //# sourceMappingURL=copy-file.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"copy-file.d.ts","sourceRoot":"","sources":["../lib/copy-file.ts"],"names":[],"mappings":"AAGA;;GAEG;AACH,wBAAsB,QAAQ,CAAC,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAGvE"}
@@ -0,0 +1,9 @@
1
+ import { copyFile as copyFileAsync, mkdir } from "node:fs/promises";
2
+ import { dirname } from "node:path";
3
+ /**
4
+ * Write content to the file and create directory if not exists
5
+ */
6
+ export async function copyFile(src, dest) {
7
+ await mkdir(dirname(dest), { recursive: true });
8
+ return copyFileAsync(src, dest);
9
+ }
@@ -0,0 +1,6 @@
1
+ import type { Extenders, Options, Pages } from "./index.js";
2
+ /**
3
+ * Retrieve an array tree of pages from path
4
+ */
5
+ export declare function getPages({ path, include }?: Options, ...extenders: Extenders): Promise<Pages>;
6
+ //# sourceMappingURL=get-pages.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"get-pages.d.ts","sourceRoot":"","sources":["../lib/get-pages.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAoB,SAAS,EAAE,OAAO,EAAQ,KAAK,EAAE,MAAM,YAAY,CAAC;AAGpF;;GAEG;AACH,wBAAsB,QAAQ,CAC7B,EAAE,IAAgB,EAAE,OAAgB,EAAE,GAAE,OAAY,EACpD,GAAG,SAAS,EAAE,SAAS,GACrB,OAAO,CAAC,KAAK,CAAC,CA2BhB"}
@@ -0,0 +1,28 @@
1
+ import { readdir } from "node:fs/promises";
2
+ import { join, parse } from "node:path";
3
+ import { isPage } from "./is-page.js";
4
+ /**
5
+ * Retrieve an array tree of pages from path
6
+ */
7
+ export async function getPages({ path = "content", include = isPage } = {}, ...extenders) {
8
+ const dir = await readdir(path, { withFileTypes: true });
9
+ return Promise.all(dir
10
+ .filter((dirent) => include(dirent, path.toString()))
11
+ .map(async (dirent) => {
12
+ // Page object
13
+ const page = {
14
+ name: parse(dirent.name).name,
15
+ path: join(path.toString(), dirent.name),
16
+ };
17
+ // Read subdirectory recursively
18
+ if (dirent.isDirectory()) {
19
+ page.children = await getPages({ path: page.path, include }, ...extenders);
20
+ }
21
+ // Calling callbacks in the series
22
+ for (const cb of extenders.filter((f) => typeof f === "function")) {
23
+ await cb(page, dirent, path.toString());
24
+ }
25
+ // Assign objects with page
26
+ return Object.assign(page, ...extenders.filter((o) => typeof o === "object"));
27
+ }));
28
+ }
@@ -0,0 +1,22 @@
1
+ import type { Dirent, PathLike } from "node:fs";
2
+ export { allPages } from "./all-pages.js";
3
+ export { copyFile } from "./copy-file.js";
4
+ export { getPages } from "./get-pages.js";
5
+ export { readFile } from "./read-file.js";
6
+ export { writeFile } from "./write-file.js";
7
+ export type Extenders = Array<ExtenderCallback>;
8
+ export type Page = {
9
+ name: string;
10
+ path: string;
11
+ content?: string;
12
+ children?: Pages;
13
+ [key: string]: any;
14
+ };
15
+ export type Pages = Array<Page>;
16
+ export type Options = {
17
+ path?: PathLike;
18
+ include?: IncludePage;
19
+ };
20
+ export type ExtenderCallback = (page: Page, dirent: Dirent, path?: string) => Promise<void>;
21
+ export type IncludePage = (dirent: Dirent, path?: string) => void;
22
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../lib/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAEhD,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAC1C,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAC1C,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAC1C,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAC1C,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAE5C,MAAM,MAAM,SAAS,GAAG,KAAK,CAAC,gBAAgB,CAAC,CAAC;AAEhD,MAAM,MAAM,IAAI,GAAG;IAClB,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,QAAQ,CAAC,EAAE,KAAK,CAAC;IAEjB,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAC;CACnB,CAAC;AAEF,MAAM,MAAM,KAAK,GAAG,KAAK,CAAC,IAAI,CAAC,CAAC;AAEhC,MAAM,MAAM,OAAO,GAAG;IAAE,IAAI,CAAC,EAAE,QAAQ,CAAC;IAAC,OAAO,CAAC,EAAE,WAAW,CAAA;CAAE,CAAC;AAEjE,MAAM,MAAM,gBAAgB,GAAG,CAAC,IAAI,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,MAAM,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;AAE5F,MAAM,MAAM,WAAW,GAAG,CAAC,MAAM,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,MAAM,KAAK,IAAI,CAAC"}
@@ -0,0 +1,11 @@
1
+ import type { Dirent } from "node:fs";
2
+ /**
3
+ * Default page filter
4
+ *
5
+ * - skip hidden files (starts with .)
6
+ * - skip hidden directories (starts with .)
7
+ * - skip drafts files with underscore (_) at the beginning
8
+ * - accept only *.html and *.md files
9
+ */
10
+ export declare function isPage(dirent: Dirent): boolean;
11
+ //# sourceMappingURL=is-page.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"is-page.d.ts","sourceRoot":"","sources":["../lib/is-page.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,SAAS,CAAC;AAEtC;;;;;;;GAOG;AACH,wBAAgB,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAQ9C"}
@@ -0,0 +1,16 @@
1
+ /**
2
+ * Default page filter
3
+ *
4
+ * - skip hidden files (starts with .)
5
+ * - skip hidden directories (starts with .)
6
+ * - skip drafts files with underscore (_) at the beginning
7
+ * - accept only *.html and *.md files
8
+ */
9
+ export function isPage(dirent) {
10
+ // Accept only *.md, *.html files
11
+ if (dirent.isFile() && !dirent.name.startsWith("_") && !dirent.name.startsWith(".")) {
12
+ return dirent.name.endsWith(".md") || dirent.name.endsWith(".html");
13
+ }
14
+ // Or not hidden directory
15
+ return dirent.isDirectory() && !dirent.name.startsWith(".");
16
+ }
@@ -0,0 +1,5 @@
1
+ /**
2
+ * Read file content as string
3
+ */
4
+ export declare function readFile(path: string): Promise<string>;
5
+ //# sourceMappingURL=read-file.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"read-file.d.ts","sourceRoot":"","sources":["../lib/read-file.ts"],"names":[],"mappings":"AAEA;;GAEG;AACH,wBAAsB,QAAQ,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAE5D"}
@@ -0,0 +1,7 @@
1
+ import { readFile as readFileAsync } from "node:fs/promises";
2
+ /**
3
+ * Read file content as string
4
+ */
5
+ export async function readFile(path) {
6
+ return readFileAsync(path, "utf8");
7
+ }
@@ -0,0 +1,5 @@
1
+ /**
2
+ * Write content to the file and create directory if not exists
3
+ */
4
+ export declare function writeFile(file: string, content: string): Promise<void>;
5
+ //# sourceMappingURL=write-file.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"write-file.d.ts","sourceRoot":"","sources":["../lib/write-file.ts"],"names":[],"mappings":"AAGA;;GAEG;AACH,wBAAsB,SAAS,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAG5E"}
@@ -0,0 +1,9 @@
1
+ import { mkdir, writeFile as writeFileAsync } from "node:fs/promises";
2
+ import { dirname } from "node:path";
3
+ /**
4
+ * Write content to the file and create directory if not exists
5
+ */
6
+ export async function writeFile(file, content) {
7
+ await mkdir(dirname(file), { recursive: true });
8
+ return writeFileAsync(file, content);
9
+ }
package/package.json CHANGED
@@ -1,17 +1,21 @@
1
1
  {
2
2
  "name": "@sphido/core",
3
- "version": "2.0.30",
3
+ "version": "3.0.0",
4
4
  "author": "Roman Ožana <roman@ozana.cz> (https://ozana.cz)",
5
5
  "homepage": "https://sphido.cz",
6
6
  "repository": "sphido/sphido",
7
7
  "license": "MIT",
8
8
  "description": "A rocket 🚀 fast, lightweight, static site generator",
9
9
  "type": "module",
10
- "exports": "./lib/index.js",
11
10
  "engines": {
12
- "node": ">=16"
11
+ "node": ">=22"
13
12
  },
14
- "types": "types/index.d.ts",
13
+ "files": [
14
+ "dist"
15
+ ],
16
+ "exports": "./dist/index.js",
17
+ "types": "dist/index.d.ts",
18
+ "main": "dist/index.js",
15
19
  "keywords": [
16
20
  "markdown",
17
21
  "markup",
@@ -26,21 +30,13 @@
26
30
  ],
27
31
  "bugs": "https://github.com/sphido/sphido/issues",
28
32
  "devDependencies": {
29
- "@sindresorhus/slugify": "^2.2.1",
30
- "ava": "^6.1.2",
31
- "marked": "^13.0.2"
33
+ "@sindresorhus/slugify": "^3.0.0",
34
+ "marked": "^16.4.2",
35
+ "typescript": "^5.9.3",
36
+ "vitest": "^4.0.17"
32
37
  },
33
38
  "scripts": {
34
- "test": "ava",
35
- "types": "tsc lib/*.js --declaration --allowJs --emitDeclarationOnly --outDir types"
36
- },
37
- "xo": {
38
- "ignores": [
39
- "types/**"
40
- ],
41
- "rules": {
42
- "no-await-in-loop": 0
43
- }
44
- },
45
- "gitHead": "7868b45b174ec545fd47df09e57a41df9786dfe5"
46
- }
39
+ "test": "vitest run --passWithNoTests",
40
+ "build": "rm -rf dist/* && tsc"
41
+ }
42
+ }
package/readme.md CHANGED
@@ -1,59 +1,59 @@
1
1
  # @sphido/core
2
2
 
3
- Sphido core package contains two most important function `getPages()` and `allPages()`.
4
- The `getPages()` function scans directories for all `*.md` and `*.html` files.
5
- Second function `allPages()` is [generator](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Generator)
6
- that allow to iterate over all pages.
3
+ Sphido core package contains the two most important functions `getPages()` and `allPages()`. The `getPages()` function scans
4
+ directories for all `*.md` and `*.html` files. The second function, `allPages()`,
5
+ is a [generator](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Generator)
6
+ that allows you to iterate over all pages.
7
7
 
8
8
  ```javascript
9
- const pages = await getPages({path: 'content'}, /* ...exteners */);
9
+ const pages = await getPages({path: 'content'}, /* ...extenders */);
10
10
  ```
11
11
 
12
- Returned structure is very simple and looks like follow:
12
+ The returned structure is very simple and looks as follows:
13
13
 
14
14
  ```json
15
15
  [
16
- {
17
- "name": "Main page",
18
- "path": "content/Main page.md"
19
- },
20
- {
21
- "name": "Directory",
22
- "children": [
23
- {
24
- "name": "Subpage one",
25
- "path": "content/Directory/Subpage one.md"
26
- },
27
- {
28
- "name": "Subpage two",
29
- "path": "content/Directory/Subpage two.md"
30
- }
31
- ]
32
- }
16
+ {
17
+ "name": "Main page",
18
+ "path": "content/Main page.md"
19
+ },
20
+ {
21
+ "name": "Directory",
22
+ "children": [
23
+ {
24
+ "name": "Subpage one",
25
+ "path": "content/Directory/Subpage one.md"
26
+ },
27
+ {
28
+ "name": "Subpage two",
29
+ "path": "content/Directory/Subpage two.md"
30
+ }
31
+ ]
32
+ }
33
33
  ]
34
34
  ```
35
35
 
36
- Then iterate over pages like follow:
36
+ Then iterate over the pages like this:
37
37
 
38
38
  ```javascript
39
39
  for (const page of allPages(pages)) {
40
- console.log(page);
40
+ console.log(page);
41
41
  }
42
42
  ```
43
43
 
44
44
  ## Extending `page` object
45
45
 
46
- Every single `page` object inside structure can be modified with extender. Extenders are set as additional parameters of the `getPages()` function.
47
- There are two types of extenders:
46
+ Every single `page` object inside structure can be modified with extender. Extenders are set as additional parameters of
47
+ the `getPages()` function. There are two types of extenders:
48
48
 
49
49
  ### *Callback* extenders
50
50
 
51
- Callback extender is a function that is called during recursion over each page with three
52
- parameters passed to the function `page`, `path` and [`dirent`](https://nodejs.org/api/fs.html#class-fsdirent).
51
+ Callback extender is a function that is called during recursion over each page with three parameters passed to the
52
+ function `page`, `path` and [`dirent`](https://nodejs.org/api/fs.html#class-fsdirent).
53
53
 
54
54
  ```javascript
55
55
  const callbackExtender = (page, path, dirent) => {
56
- // do anything with page object
56
+ // do anything with page object
57
57
  }
58
58
 
59
59
  const pages = await getPages({path: 'content'}, callbackExtender);
@@ -61,23 +61,24 @@ const pages = await getPages({path: 'content'}, callbackExtender);
61
61
 
62
62
  ### *Object* extenders
63
63
 
64
- This extender is just a simple JavaScript object that is combined with the `page` object using the [Object.assign()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/assign) function.
64
+ This extender is just a simple JavaScript object that is combined with the `page` object using
65
+ the [Object.assign()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/assign)
66
+ function.
65
67
 
66
68
  ```javascript
67
69
  const objectExtender = {
68
- author: 'Roman Ožana'
70
+ author: 'Roman Ožana'
69
71
  }
70
72
 
71
73
  const pages = await getPages({path: 'content'}, objectExtender);
72
74
  ```
73
75
 
74
- There is no limit to the number of extenders, you can combine as many as you want.
75
- Let's have the following code:
76
+ There is no limit to the number of extenders, you can combine as many as you want. Let's have the following code:
76
77
 
77
78
  ```javascript
78
79
  const extenders = [
79
80
 
80
- // callback extenders will be called during iteration ony by one
81
+ // callback extenders will be called during iteration one by one
81
82
 
82
83
  (page) => {
83
84
  // add property
@@ -91,13 +92,13 @@ const extenders = [
91
92
  },
92
93
 
93
94
  // callback extenders are called in the series
94
-
95
+
95
96
  (page) => {
96
97
  page.counter++;
97
98
  },
98
99
 
99
100
  // object extender will be merged with page object
100
-
101
+
101
102
  {
102
103
  "author": "Roman Ožana",
103
104
  "getLink": function () {
@@ -113,47 +114,50 @@ then you get this structure:
113
114
 
114
115
  ```json
115
116
  [
116
- {
117
- "name": "Main page",
118
- "path": "content/Main page.md",
119
- "title": "Main page | my best website",
120
- "counter": 2,
121
- "author": "Roman Ožana",
122
- "getDate": "[Function: getDate]",
123
- "getLink": "[Function: getLink]"
124
- }
117
+ {
118
+ "name": "Main page",
119
+ "path": "content/Main page.md",
120
+ "title": "Main page | my best website",
121
+ "counter": 2,
122
+ "author": "Roman Ožana",
123
+ "getDate": "[Function: getDate]",
124
+ "getLink": "[Function: getLink]"
125
+ }
125
126
  ]
126
127
  ```
127
128
 
128
129
  ## Installation
129
130
 
131
+ Requires [Node.js](https://nodejs.org/) 22 or newer.
132
+
130
133
  ```bash
131
- yarn add @sphido/core
134
+ pnpm add @sphido/core
132
135
  ```
133
136
 
134
137
  ## Example
135
138
 
136
- Following example read all `*.md` files in `content` directory and process them with [marked](https://github.com/markedjs/marked) to HTML files
139
+ The following example reads all `*.md` files in the `content` directory and processes them
140
+ with [marked](https://github.com/markedjs/marked) into HTML files.
137
141
 
138
142
  ```javascript
139
143
  #!/usr/bin/env node
140
144
 
141
- import {dirname, relative, join} from 'node:path';
142
- import {getPages, allPages, readFile, writeFile} from '@sphido/core';
145
+ import { dirname, relative, join } from 'node:path';
146
+ import { getPages, allPages, readFile, writeFile } from '@sphido/core';
143
147
  import slugify from '@sindresorhus/slugify';
144
- import {marked} from 'marked';
148
+ import { marked } from 'marked';
145
149
 
146
150
  const pages = await getPages({path: 'content'}, // ... extenders
147
- (page) => {
148
- page.slug = slugify(page.name) + '.html';
149
- page.dir = dirname(page.path);
150
- });
151
+ (page) => {
152
+ page.slug = slugify(page.name) + '.html';
153
+ page.dir = dirname(page.path);
154
+ });
151
155
 
152
156
  for (const page of allPages(pages)) {
153
- page.output = join('public', relative('content', page.dir), page.slug);
154
- page.content = marked(await readFile(page.path));
157
+ page.output = join('public', relative('content', page.dir), page.slug);
158
+ page.content = marked(await readFile(page.path));
155
159
 
156
- await writeFile(page.output, `<!DOCTYPE html>
160
+ await writeFile(page.output, `<!DOCTYPE html>
157
161
  <html lang="en" dir="ltr">
158
162
  <head>
159
163
  <meta charset="UTF-8">
@@ -167,6 +171,6 @@ for (const page of allPages(pages)) {
167
171
  }
168
172
  ```
169
173
 
170
- ## Source codes
174
+ ## Source code
171
175
 
172
176
  [@sphido/core](https://github.com/sphido/sphido/tree/main/packages/sphido-core)
package/lib/all-pages.js DELETED
@@ -1,15 +0,0 @@
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) {
8
- for (const page of pages) {
9
- if (page?.children) {
10
- yield * allPages(page.children);
11
- } else {
12
- yield page;
13
- }
14
- }
15
- }
package/lib/copy-file.js DELETED
@@ -1,15 +0,0 @@
1
- import {copyFile as copyFileAsync} from 'node:fs/promises';
2
- import {dirname} from 'node:path';
3
- import {mkdir} from 'node:fs/promises';
4
-
5
- /**
6
- * Write content to the file and create directory if not exists
7
- *
8
- * @param {string} src
9
- * @param {string} dest
10
- * @returns {Promise<*>}
11
- */
12
- export async function copyFile(src, dest) {
13
- await mkdir(dirname(dest), {recursive: true});
14
- return copyFileAsync(src, dest);
15
- }
package/lib/get-pages.js DELETED
@@ -1,56 +0,0 @@
1
- import {join, parse} from 'node:path';
2
- import {readdir} from 'node:fs/promises';
3
- import {isPage} from './is-page.js';
4
-
5
- /**
6
- * Retrieve an array tree of pages from path
7
- *
8
- * @param {Options}
9
- * @param {Extenders} extenders
10
- * @return {Promise<Awaited<Pages>[]>}
11
- */
12
- export async function getPages({path = 'content', include = isPage} = {}, ...extenders) {
13
- const dir = await readdir(path, {withFileTypes: true});
14
-
15
- return Promise.all(
16
- dir
17
- .filter(dirent => include(dirent, path))
18
- .map(async dirent => {
19
- // Page object
20
- const page = {name: parse(dirent.name).name, path: join(path, dirent.name)};
21
-
22
- // Read subdirectory recursively
23
- if (dirent.isDirectory()) {
24
- page.children = await getPages({path: page.path, include}, ...extenders);
25
- }
26
-
27
- // Calling callbacks in the series
28
- for (const cb of extenders.filter(f => typeof f === 'function')) {
29
- /** @type {ExtenderCallback} */
30
- await cb(page, dirent, path);
31
- }
32
-
33
- // Assign objects with page
34
- return Object.assign(page, ...extenders.filter(o => typeof o === 'object'));
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/index.js DELETED
@@ -1,5 +0,0 @@
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';
package/lib/is-page.js DELETED
@@ -1,20 +0,0 @@
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) {
13
- // Accept only *.md, *.html files
14
- if (dirent.isFile() && !dirent.name.startsWith('_') && !dirent.name.startsWith('.')) {
15
- return dirent.name.endsWith('.md') || dirent.name.endsWith('.html');
16
- }
17
-
18
- // Or not hidden directory
19
- return dirent.isDirectory() && !dirent.name.startsWith('.');
20
- }
package/lib/read-file.js DELETED
@@ -1,10 +0,0 @@
1
- import {readFile as readFileAsync} from 'node:fs/promises';
2
-
3
- /**
4
- * Read file content as string
5
- * @param {string} path
6
- * @returns {Promise<*>}
7
- */
8
- export async function readFile(path) {
9
- return readFileAsync(path, 'utf8');
10
- }
package/lib/write-file.js DELETED
@@ -1,15 +0,0 @@
1
- import {writeFile as writeFileAsync} from 'node:fs/promises';
2
- import {dirname} from 'node:path';
3
- import {mkdir} from 'node:fs/promises';
4
-
5
- /**
6
- * Write content to the file and create directory if not exists
7
- *
8
- * @param {string} file
9
- * @param {string} content
10
- * @returns {Promise<*>}
11
- */
12
- export async function writeFile(file, content) {
13
- await mkdir(dirname(file), {recursive: true});
14
- return writeFileAsync(file, content);
15
- }
@@ -1,7 +0,0 @@
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;
@@ -1,8 +0,0 @@
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>;
@@ -1,21 +0,0 @@
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;
@@ -1,12 +0,0 @@
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;
@@ -1,6 +0,0 @@
1
- /**
2
- * Read file content as string
3
- * @param {string} path
4
- * @returns {Promise<*>}
5
- */
6
- export function readFile(path: string): Promise<any>;
@@ -1,8 +0,0 @@
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>;
@@ -1,5 +1,5 @@
1
- export { getPages } from "./get-pages.js";
2
1
  export { allPages } from "./all-pages.js";
2
+ export { copyFile } from "./copy-file.js";
3
+ export { getPages } from "./get-pages.js";
3
4
  export { readFile } from "./read-file.js";
4
5
  export { writeFile } from "./write-file.js";
5
- export { copyFile } from "./copy-file.js";