Slide 19
Slide 19 text
͜͏͢Δʂ(ಛʹେࣄͳͳ͍ͷͰskip)
export function _genPathInfo(source: string[], basePath:
string) {
const outputPath = []
const
im
portPath = []
const slugs = []
let depth = 0;
const basePaths = source.slice(
0
, source.length - 1)
for (const basePath of basePaths) {
depth += 1;
const slugPattern = basePath.
m
atch(SLUG_PARA
M_
PAT
TE
RN)
if (slugPattern) {
slugs.push(slugPattern.at(1));
outputPath.push(`:
$
{slugPattern.at(1)}`);
} else {depth
outputPath.push(basePath);
}
im
portPath.push(basePath)
}
const action = source.at(-1);
if (action !== 'index.tsx') {
depth += 1;
const slugPattern =
action?.
m
atch(SLUG_FILE_ARA
M _
PAT
TE
RN)
if (slugPattern) {
outputPath.push(`:
$
{slugPattern.at(1)}`);
slugs.push(slugPattern.at(1));
} else {
outputPath.push(action?.replace('.tsx', ''));
}
im
portPath.push(action?.replace('.tsx', '') ?? '');
}
return {
path: outputPath.join('/'),
im
portPath: path.join(basePath,
i
m
portPath.join('/')),
filePath: path.join(basePath, source.join('/')),
depth,
slugs,
}
}
https://github.com/jiko21/nextjs-like-framework