1
0
mirror of https://github.com/kremalicious/blog.git synced 2024-06-30 13:41:54 +02:00
blog/src/lib/astro/getSlug.ts

22 lines
465 B
TypeScript
Raw Normal View History

import path from 'node:path'
2023-10-04 02:54:41 +02:00
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)
2023-10-04 02:54:41 +02:00
return slug
}