1
0
mirror of https://github.com/kremalicious/blog.git synced 2024-06-28 00:27:58 +02:00
blog/src/lib/astro/getSlug.ts

22 lines
465 B
TypeScript

import path from 'node:path'
export function getSlug(filePath: string): string {
const parsedPath = path.parse(filePath)
let slug
// construct slug as full path from either file or folder name,
if (parsedPath.base === 'index.md') {
slug = parsedPath.dir
} else {
slug = `${parsedPath.dir}/${parsedPath.name}`
}
// remove folder structure
slug = slug.split('/')[1]
// remove the date prefix
slug = slug.substring(11)
return slug
}