@@ -2,8 +2,6 @@ import fs from 'fs'
22import type { PluginOption } from 'vite'
33import { splitVendorChunkPlugin } from 'vite'
44
5- import consola from 'consola'
6-
75import MarkdownIt from 'markdown-it'
86import matter from 'gray-matter'
97
@@ -13,10 +11,10 @@ import Layouts from 'vite-plugin-vue-layouts'
1311import Components from 'unplugin-vue-components/vite'
1412import VueI18n from '@intlify/vite-plugin-vue-i18n'
1513
16- import { dim , yellow } from 'kolorist'
1714import type { ResolvedValaxyOptions , ValaxyPluginOptions , ValaxyServerOptions } from '../options'
1815import { setupMarkdownPlugins } from '../markdown'
1916// import { createMarkdownPlugin, excerpt_separator } from './markdown'
17+ import { formatMdDate } from '../utils/date'
2018import { createUnocssPlugin } from './unocss'
2119import { createConfigPlugin } from './extendConfig'
2220import { createClientSetupPlugin } from './setupClient'
@@ -117,28 +115,23 @@ export async function ViteValaxyPlugins(
117115 } )
118116
119117 // page is post
120- let isPost = false
121- if ( route . path . startsWith ( '/posts/' ) ) {
122- isPost = true
118+ if ( route . path . startsWith ( '/posts/' ) )
123119 route . meta . layout = 'post'
124- }
125120
126121 // set default frontmatter
127- const defaultFrontmatter = {
128- date : new Date ( ) ,
129- }
130- if ( ! route . meta . frontmatter )
131- route . meta . frontmatter = defaultFrontmatter
122+ const defaultFrontmatter = { }
132123
133124 if ( path . endsWith ( '.md' ) ) {
134125 const md = fs . readFileSync ( path , 'utf-8' )
135126 const { data, excerpt } = matter ( md , { excerpt_separator : '<!-- more -->' } )
136127
137- if ( isPost ) {
138- // warn for post frontmatter
139- if ( ! data . date )
140- consola . warn ( `You forgot to write ${ yellow ( 'date' ) } for post: ${ dim ( `${ route . component } ` ) } ` )
141- }
128+ // todo, optimize it to cache or on demand
129+ formatMdDate (
130+ data ,
131+ path ,
132+ options . config . date . format ,
133+ options . config . lastUpdated ,
134+ )
142135
143136 route . meta = Object . assign ( route . meta , {
144137 frontmatter : Object . assign ( defaultFrontmatter , data ) ,
0 commit comments