-
Hello, I have a loader that parses typescript declaration of the project and returns some metadata about them in json form. meta.data.ts import { defineLoader } from "vitepress";
import { parse } from "@babel/parser";
import * as es from "@babel/types";
import { readFile } from "fs/promises";
export default defineLoader({
watch: "@/../../compiler/lib/commands.d.ts",
async load(watchedFiles) {
if (watchedFiles.length == 0)
throw new Error("No compiler/lib/commands.d.ts file detected");
const fileContent = await readFile(watchedFiles[0], {
encoding: "utf8",
});
const result = parse(fileContent, {
plugins: ["typescript"],
sourceType: "module",
});
if (result.errors.length > 0) {
throw new Error(
`Error parsing commands declaration file: ${result.errors[0]}`,
{ cause: result.errors[0] },
);
}
return computeMetada(result);
},
}); doc.md <script setup>
import { data } from '../examples/commands.data.ts'
</script>
# Internal metadata
```json
{{ data }}
```
|
Beta Was this translation helpful? Give feedback.
Answered by
brc-dd
Oct 5, 2024
Replies: 2 comments
-
I would like to do something similar as well! |
Beta Was this translation helpful? Give feedback.
0 replies
-
Do something like this - #2921 (comment) return md.render(`\`\`\`json\n${data}\n\`\`\``) |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
JeanJPNM
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Do something like this - #2921 (comment)