Skip to content

Instantly share code, notes, and snippets.

@guxuerui
Created March 28, 2023 04:50
Show Gist options
  • Save guxuerui/ec5de33d0f1146074cfdea79c6e483f2 to your computer and use it in GitHub Desktop.
Save guxuerui/ec5de33d0f1146074cfdea79c6e483f2 to your computer and use it in GitHub Desktop.
使用vite,导入markdown文件后读取定义的meta信息
const getMetaData = async () => {
// example file path: ./pages/js/*.md
const allPostFiles = import.meta.glob('./pages/js/*.md')
const iterablePostFiles = Object.entries(allPostFiles)
const allPosts = await Promise.all(
iterablePostFiles.map(async ([path, resolver]) => {
const resolvedPost = await resolver()
return {
title: resolvedPost.title,
abstract: resolvedPost.abstract,
chipText: resolvedPost.tags,
chipColor: resolvedPost.chipColor,
}
}),
)
return allPosts
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment