@sphido/core 2.0.0 → 2.0.3
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/lib/get-pages.js +5 -5
- package/package.json +2 -2
package/lib/get-pages.js
CHANGED
|
@@ -1,27 +1,27 @@
|
|
|
1
1
|
import {join, parse} from 'node:path';
|
|
2
2
|
import {readdir} from 'node:fs/promises';
|
|
3
|
-
import {isPage
|
|
3
|
+
import {isPage} from './is-page.js';
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
6
|
* Retrieve an array tree of pages from path
|
|
7
7
|
* @param {string} path
|
|
8
|
-
* @param {Function}
|
|
8
|
+
* @param {Function} include
|
|
9
9
|
* @param extenders
|
|
10
10
|
* @returns {Promise<Awaited<unknown>[{name, path}]>}
|
|
11
11
|
*/
|
|
12
|
-
export async function getPages({path = 'content',
|
|
12
|
+
export async function getPages({path = 'content', include = isPage} = {}, ...extenders) {
|
|
13
13
|
const dir = await readdir(path, {withFileTypes: true});
|
|
14
14
|
|
|
15
15
|
return Promise.all(
|
|
16
16
|
dir
|
|
17
|
-
.filter(dirent =>
|
|
17
|
+
.filter(dirent => include(dirent, path))
|
|
18
18
|
.map(async dirent => {
|
|
19
19
|
// Page
|
|
20
20
|
const page = {name: parse(dirent.name).name, path: join(path, dirent.name)};
|
|
21
21
|
|
|
22
22
|
// Read subdirectory recursively
|
|
23
23
|
if (dirent.isDirectory()) {
|
|
24
|
-
page.children = await getPages({path: page.path,
|
|
24
|
+
page.children = await getPages({path: page.path, include}, ...extenders);
|
|
25
25
|
}
|
|
26
26
|
|
|
27
27
|
// Calling callbacks
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sphido/core",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.3",
|
|
4
4
|
"author": {
|
|
5
5
|
"name": "Roman Ožana",
|
|
6
6
|
"email": "roman@ozana.cz",
|
|
@@ -40,5 +40,5 @@
|
|
|
40
40
|
"scripts": {
|
|
41
41
|
"test": "ava"
|
|
42
42
|
},
|
|
43
|
-
"gitHead": "
|
|
43
|
+
"gitHead": "c9c4fccbd160f17071fe47c132d0a7e6b0d43da6"
|
|
44
44
|
}
|