mirror of
https://github.com/AnimeThemes/animethemes-api-docs.git
synced 2026-07-11 01:34:06 +02:00
c2b90daf0d
(cherry picked from commit fe9a3017e5)
39 lines
1.2 KiB
JavaScript
39 lines
1.2 KiB
JavaScript
import path from "path";
|
|
|
|
export default function graphqlWarnPlugin() {
|
|
return {
|
|
name: "graphql-warn-plugin",
|
|
enforce: "pre",
|
|
transform(code, id) {
|
|
if (!id.endsWith(".md")) return;
|
|
|
|
const relativePath = path.relative(process.cwd(), id);
|
|
if (!relativePath.includes("graphql")) return;
|
|
|
|
const warningBlock = [
|
|
"::: warning",
|
|
"⚠️ The GraphQL API is experimental and subject to change without notice.",
|
|
":::",
|
|
"",
|
|
].join("\n");
|
|
|
|
if (code.startsWith("---")) {
|
|
const endOfFrontmatter = code.indexOf("---", 3);
|
|
if (endOfFrontmatter !== -1) {
|
|
const before = code.slice(0, endOfFrontmatter + 3);
|
|
const after = code.slice(endOfFrontmatter + 3);
|
|
return {
|
|
code: `${before}\n\n${warningBlock}${after}`,
|
|
map: null,
|
|
};
|
|
}
|
|
}
|
|
|
|
return {
|
|
code: warningBlock + code,
|
|
map: null,
|
|
};
|
|
},
|
|
};
|
|
}
|