Created
March 28, 2023 04:50
-
-
Save guxuerui/ec5de33d0f1146074cfdea79c6e483f2 to your computer and use it in GitHub Desktop.
使用vite,导入markdown文件后读取定义的meta信息
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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