Skip to content

Commit

Permalink
fix(types): more accurately represent ParsedContentMeta (#1196)
Browse files Browse the repository at this point in the history
  • Loading branch information
harlan-zw committed Jun 3, 2022
1 parent adc0143 commit 3fbcd22
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 7 deletions.
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

0 comments on commit 3fbcd22

Please sign in to comment.