Skip to content

Commit

Permalink
slug customization
Browse files Browse the repository at this point in the history
  • Loading branch information
sidd88 committed Oct 18, 2024
1 parent baf5b7b commit fa4527b
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
16 changes: 15 additions & 1 deletion contentlayer.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ const computedFields: ComputedFields = {
readingTime: { type: 'json', resolve: (doc) => readingTime(doc.body.raw) },
slug: {
type: 'string',
resolve: (doc) => doc._raw.flattenedPath.replace(/^.+?(\/)/, ''),
resolve: (doc) => getSlug(doc._raw.flattenedPath),
},
path: {
type: 'string',
Expand Down Expand Up @@ -90,6 +90,20 @@ function createSearchIndex(allBlogs) {
}
}

/**
* Customization function to clean the SLUG
*/
function getSlug(slug: string): string {
let path = slug.replace(/^.+?(\/)/, '')

// Remove filename prefix if exist
if (path.includes('__')) {
const pathArr = path.split('__')
path = pathArr[pathArr.length - 1]
}
return path
}

export const Blog = defineDocumentType(() => ({
name: 'Blog',
filePathPattern: 'blog/**/*.mdx',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
title: Mac setup for Developer
date: '2024-09-28'
tags: ['dev-env']
date: '2024-10-18'
tags: ['mac setup']
draft: false
summary: Some useful setup guides for developers with a new Mac.
images: []
Expand Down

0 comments on commit fa4527b

Please sign in to comment.