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