better typing

This commit is contained in:
Rachel Lambda Samuelsson 2024-07-17 16:49:08 +02:00
parent 80c8733481
commit 96e99061e9

View File

@ -1,4 +1,4 @@
import type { ComponentOptions } from 'vue' import type { Component, ComponentOptions } from 'vue'
import { h, defineComponent } from 'vue' import { h, defineComponent } from 'vue'
import ThePost from '../components/ThePost.vue' import ThePost from '../components/ThePost.vue'
@ -9,29 +9,31 @@ export type Post = {
path : string, path : string,
url : string, url : string,
excerpt : string, excerpt : string,
component : ComponentOptions, component : Component,
} }
const imports = await Promise.all( type Import = {
Object.values(import.meta.glob('./*.md')).map((m) => m()) default : ComponentOptions & { __name : string },
) date : Date
title : string
excerpt : string
}
const imports : Import[] = await Promise.all(
Object.values(import.meta.glob('./*.md')).map((m) => m())
) as Import[]
// @ts-ignore
const posts : Post[] = imports.map((post) => { const posts : Post[] = imports.map((post) => {
// @ts-ignore
const slug = post.default.__name const slug = post.default.__name
const path = "/posts/" + slug const path = "/posts/" + slug
const url = path + ".html" const url = path + ".html"
// @ts-ignore
const date = new Date(post.date) const date = new Date(post.date)
// @ts-ignore
const title = post.title const title = post.title
return { return {
// @ts-ignore
excerpt: post.excerpt, excerpt: post.excerpt,
title, date, slug, path, url, title, date, slug, path, url,
component: defineComponent( component: defineComponent(
(props) => { (_) => {
return () => { return () => {
return h( return h(
ThePost, ThePost,
@ -40,7 +42,6 @@ const posts : Post[] = imports.map((post) => {
title: title title: title
}, },
{ {
// @ts-ignore
default: post.default.render default: post.default.render
} }
) )