Closed capsloq closed 8 months ago
Answering my own Question:
There is a context object as an argument within transform:
schema: s
.object({
title: s.string().max(99),
...
})
.transform((data, ctx) => ({ ...data,
// computed fields
permalink: `/${data.slug}`,
fileInfo: ctx.meta.file.path,
fileInfo2: ctx.meta.file.basename,
fileInfo3: ctx.meta.file.dirname,
fileInfo4: ctx.meta.file.extname,
}))
Still suggesting to add an example to the docs for "file based slugs" so folks migrating from contentlayer have it easier
Yup, but it is recommended to use file.stem
, which is more similar to flattenedPath
.
refer to VFile.stem
for more details.
path: s.path()
// => flattened path, e.g. 'posts/2021-01-01-hello-world'
First of all great substitute for contentlayer thank you for that. I am testing out velite by migrating a contentlayer project.
In contentlayer my slugs were based on the filepath. For a nested MDX file in e.g. content/firstfolder/secondfolder/test.mdx that meant the slug would be /firstfolder/secondfolder/test
To achieve that in contentlayer we had
raw.flattenedPath
likeI did read the velite documentation but how would that be achieved in velite? I understand you can either use .transform for collection based computed fields or prepare for all collections.
If there is a solutions to this might consider adding it to the docs
Thank you