oxen-website/utils/routing.ts

15 lines
342 B
TypeScript
Raw Permalink Normal View History

2021-01-22 03:43:42 +01:00
export const generateURL = (slug: string) => {
2021-02-04 01:57:27 +01:00
// Trim slug and remove slashes
const trimmed = slug.trim().replace('/', '');
2021-01-22 03:43:42 +01:00
// Route to 404 if the link is invalid
2021-02-04 01:57:27 +01:00
if (!trimmed || !trimmed.length) {
2021-01-22 03:43:42 +01:00
return { href: '/404', as: '/404' };
}
return {
2021-02-04 01:57:27 +01:00
href: '/blog/[slug]/',
as: `/blog/${trimmed}`.toLowerCase(),
2021-01-22 03:43:42 +01:00
};
};