Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(types): more accurately represent ParsedContentMeta #1196

Merged
merged 5 commits into from
Jun 3, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 3 additions & 2 deletions src/runtime/server/transformers/path-meta.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { pascalCase } from 'scule'
import slugify from 'slugify'
import { withoutTrailingSlash, withLeadingSlash } from 'ufo'
import { ParsedContentMeta } from '../../types'
import { useRuntimeConfig } from '#imports'

const SEMVER_REGEX = /^(\d+)(\.\d+)*(\.x)?$/
Expand All @@ -12,7 +13,7 @@ const describeId = (_id: string) => {
parts[parts.length - 1] = filename
const _path = parts.join('/')

return {
return <Pick<ParsedContentMeta, '_source' | '_path' | '_extension' | '_file'>> {
_source,
_path,
_extension,
Expand All @@ -33,7 +34,7 @@ export default {

const filePath = parts.join('/')

return {
return <ParsedContentMeta> {
_path: generatePath(filePath),
_draft: isDraft(filePath),
_partial: isPartial(filePath),
Expand Down
18 changes: 13 additions & 5 deletions src/runtime/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,6 @@ export interface ParsedContentMeta {
* Content path, this path is source agnostic and it the content my live in any source
*/
_path?: string
/**
* Content slug
*/
_slug?: string
/**
* Content title
*/
Expand All @@ -33,11 +29,23 @@ export interface ParsedContentMeta {
* Content locale
*/
_locale?: boolean
/**
* File type of the content, i.e `markdown`
*/
_type?: string
/**
* Path to the file relative to the content directory
*/
_file?: string
/**
* Extension of the file
*/
_extension?: string

[key: string]: any
}

export interface ParsedContent extends ParsedContentMeta{
export interface ParsedContent extends ParsedContentMeta {
/**
* Excerpt
*/
Expand Down