mirror of
https://iceshrimp.dev/Crimekillz/jointrashposs.git
synced 2024-11-22 17:03:50 +01:00
1734b7bff6
* vercel initial * [ci skip] add gitignore * fix config * fix * (add) prerendered routes を自動生成 * fix config * fix path * (fix) trailing slash
30 lines
1020 B
TypeScript
30 lines
1020 B
TypeScript
import fs from 'fs';
|
|
import { resolve, dirname } from 'path';
|
|
import { fileURLToPath } from 'url';
|
|
|
|
export function getStaticEndpoints(): string[] {
|
|
const __dirname = dirname(fileURLToPath(import.meta.url))
|
|
const dir = resolve(`${__dirname}/../pages`);
|
|
const files = getFiles(dir);
|
|
const filtered = files
|
|
.filter((file) => !file.includes('slug')) // exclude dynamic content
|
|
.map((file) => file.split('pages')[1])
|
|
.map((file) => file.replaceAll('\\', '/'))
|
|
.map((file) => {
|
|
return (file.endsWith('index.vue') ? file.replace(/\/index.vue$/, '') : file.split('.vue')[0]) + '/';
|
|
});
|
|
return filtered;
|
|
}
|
|
|
|
/**
|
|
* recursively get all files from /pages folder
|
|
*/
|
|
function getFiles(dir: string): string[] {
|
|
const dirents = fs.readdirSync(dir, { withFileTypes: true });
|
|
const files = dirents.map((dirent) => {
|
|
const res = resolve(dir, dirent.name);
|
|
return dirent.isDirectory() ? getFiles(res) : res;
|
|
})
|
|
return files.flat();
|
|
}
|