From e4d2c736614e59247e59ee51d404fd87ff0f47d0 Mon Sep 17 00:00:00 2001 From: Harlan Wilton Date: Thu, 2 Jun 2022 14:17:22 +1000 Subject: [PATCH 1/5] fix(types): more accurately represent `ParsedContentMeta` --- src/runtime/server/transformers/path-meta.ts | 5 +++-- src/runtime/types.d.ts | 20 ++++++++++++++++---- 2 files changed, 19 insertions(+), 6 deletions(-) diff --git a/src/runtime/server/transformers/path-meta.ts b/src/runtime/server/transformers/path-meta.ts index 53bc2a925..2929f4e06 100644 --- a/src/runtime/server/transformers/path-meta.ts +++ b/src/runtime/server/transformers/path-meta.ts @@ -1,11 +1,12 @@ 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)?$/ -const describeId = (_id: string) => { +const describeId = (_id: string): Partial => { const [_source, ...parts] = _id.split(':') const [, filename, _extension] = parts[parts.length - 1].match(/(.*)\.([^.]+)$/) @@ -33,7 +34,7 @@ export default { const filePath = parts.join('/') - return { + return { _path: generatePath(filePath), _draft: isDraft(filePath), _partial: isPartial(filePath), diff --git a/src/runtime/types.d.ts b/src/runtime/types.d.ts index f0df92b64..940f57a3c 100644 --- a/src/runtime/types.d.ts +++ b/src/runtime/types.d.ts @@ -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 */ @@ -33,6 +29,22 @@ export interface ParsedContentMeta { * Content locale */ _locale?: boolean + /** + * Content is empty + */ + _empty?: boolean + /** + * File type of the content, i.e `markdown` + */ + _type?: boolean + /** + * Path to the file relative to the content directory. + */ + _file?: string + /** + * Extension of the file + */ + _extension?: string [key: string]: any } From 3609fabcf03b5734c7b328bc4d1905f11f97422a Mon Sep 17 00:00:00 2001 From: Harlan Wilton Date: Thu, 2 Jun 2022 15:32:45 +1000 Subject: [PATCH 2/5] fix: _empty, markdown only --- src/runtime/types.d.ts | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/runtime/types.d.ts b/src/runtime/types.d.ts index 940f57a3c..e89489535 100644 --- a/src/runtime/types.d.ts +++ b/src/runtime/types.d.ts @@ -29,10 +29,6 @@ export interface ParsedContentMeta { * Content locale */ _locale?: boolean - /** - * Content is empty - */ - _empty?: boolean /** * File type of the content, i.e `markdown` */ From e268530752438572073589831d5d7a975aec00c9 Mon Sep 17 00:00:00 2001 From: Harlan Wilton Date: Thu, 2 Jun 2022 15:40:14 +1000 Subject: [PATCH 3/5] fix: prefer `Pick` over `Partial` --- src/runtime/server/transformers/path-meta.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/runtime/server/transformers/path-meta.ts b/src/runtime/server/transformers/path-meta.ts index 2929f4e06..2cdb67156 100644 --- a/src/runtime/server/transformers/path-meta.ts +++ b/src/runtime/server/transformers/path-meta.ts @@ -6,14 +6,14 @@ import { useRuntimeConfig } from '#imports' const SEMVER_REGEX = /^(\d+)(\.\d+)*(\.x)?$/ -const describeId = (_id: string): Partial => { +const describeId = (_id: string) => { const [_source, ...parts] = _id.split(':') const [, filename, _extension] = parts[parts.length - 1].match(/(.*)\.([^.]+)$/) parts[parts.length - 1] = filename const _path = parts.join('/') - return { + return > { _source, _path, _extension, From 34d93b90a120c4212d15dabefd1a9055ab6c5ba6 Mon Sep 17 00:00:00 2001 From: Harlan Wilton Date: Thu, 2 Jun 2022 15:45:50 +1000 Subject: [PATCH 4/5] fix: minor inconsistencies --- src/runtime/types.d.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/runtime/types.d.ts b/src/runtime/types.d.ts index e89489535..8defc3370 100644 --- a/src/runtime/types.d.ts +++ b/src/runtime/types.d.ts @@ -34,7 +34,7 @@ export interface ParsedContentMeta { */ _type?: boolean /** - * Path to the file relative to the content directory. + * Path to the file relative to the content directory */ _file?: string /** @@ -45,7 +45,7 @@ export interface ParsedContentMeta { [key: string]: any } -export interface ParsedContent extends ParsedContentMeta{ +export interface ParsedContent extends ParsedContentMeta { /** * Excerpt */ From 1591b6c2f5dac3d439c2cb257a0287c63900a0d9 Mon Sep 17 00:00:00 2001 From: Harlan Wilton Date: Thu, 2 Jun 2022 15:49:21 +1000 Subject: [PATCH 5/5] fix: use correct type for `_type` --- src/runtime/types.d.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/runtime/types.d.ts b/src/runtime/types.d.ts index 8defc3370..febb92a9b 100644 --- a/src/runtime/types.d.ts +++ b/src/runtime/types.d.ts @@ -32,7 +32,7 @@ export interface ParsedContentMeta { /** * File type of the content, i.e `markdown` */ - _type?: boolean + _type?: string /** * Path to the file relative to the content directory */