-
Notifications
You must be signed in to change notification settings - Fork 6.5k
Expand file tree
/
Copy pathnext.helpers.mjs
More file actions
35 lines (29 loc) · 1.12 KB
/
next.helpers.mjs
File metadata and controls
35 lines (29 loc) · 1.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
'use strict';
import { fileURLToPath } from 'node:url';
import { glob } from 'glob';
/**
* This gets the relative path from `import.meta.url`
*
* @param {string} path the current import path
* @returns {string} the relative path from import
*/
export const getRelativePath = path => fileURLToPath(new URL('.', path));
/**
* This method is responsible for retrieving a glob of all files that exist
* within a given language directory
*
* Note that we ignore the blog directory for static builds as otherwise generating
* that many pages would be too much for the build process to handle.
*
* @param {string} root the root directory to search from
* @param {string} cwd the given locale code
* @param {Array<string>} ignore an array of glob patterns to ignore
* @returns {Promise<Array<string>>} a promise containing an array of paths
*/
export const getMarkdownFiles = async (root, cwd, ignore = []) => {
const cacheKey = `${root}${cwd}${ignore.join('')}`;
if (!globCacheByPath.has(cacheKey)) {
globCacheByPath.set(cacheKey, glob('**/*.{md,mdx}', { root, cwd, ignore }));
}
return globCacheByPath.get(cacheKey);
};