Skip to content

Commit

Permalink
Support custom page extensions (#14)
Browse files Browse the repository at this point in the history
  • Loading branch information
fuma-nama authored Nov 5, 2024
1 parent ca3bb81 commit 3d1095d
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions src/scan.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ export type ScanOptions = {

populate?: PopulateParams;
meta?: Record<string, UrlMeta>;
extensions?: string[];
};

export type ScanResult = {
Expand All @@ -48,16 +49,19 @@ function isDirExists(dir: string): Promise<boolean> {
}

export async function scanURLs(options: ScanOptions = {}): Promise<ScanResult> {
const ext = options.extensions ?? ['js', 'jsx', 'tsx', 'md', 'mdx'];
const cwd = options.cwd ?? process.cwd();

async function getFiles() {
const cwd = options.cwd ?? process.cwd();
const suffix = ext.length > 0? `.{${ext.join(",")}}` : '';

const appFiles = await fg('**/page.{js,jsx,tsx}', {
const appFiles = await fg(`**/page${suffix}`, {
cwd: (await isDirExists(path.join(cwd, 'src/app')))
? path.join(cwd, 'src/app')
: path.join(cwd, 'app'),
});

const pagesFiles = await fg('**/*.{js,jsx,tsx}', {
const pagesFiles = await fg(`**/*${suffix}`, {
cwd: (await isDirExists(path.join(cwd, 'src/pages')))
? path.join(cwd, 'src/pages')
: path.join(cwd, 'pages'),
Expand Down

0 comments on commit 3d1095d

Please sign in to comment.