You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
arthas/site/docs/.vuepress/plugins/vuepress-plugin-loadVersion/index.js

34 lines
931 B
JavaScript

const fs = require("fs");
const fetch = require("node-fetch");
const convert = require("xml-js");
exports.loadVersionPlugin = () => {
const data = fs.readFileSync("../pom.xml");
const pom = convert.xml2js(data.toString(), { compact: true });
const getVersionByMaven = async () => {
return await fetch(
"https://search.maven.org/solrsearch/select?q=arthas&rows=1&wt=json"
)
.then((res) => res.json())
.then((res) => res.response.docs[0].latestVersion);
};
const version = pom.project.properties.revision._text;
return {
name: "vuepress-plugin-loadVersion",
extendsPage: async (page) => {
const injectVersionPagePaths = ["/", "/en/"];
if (!injectVersionPagePaths.includes(page.data.path)) return;
if (version.includes("SNAPSHOT")) {
page.data.version = await getVersionByMaven();
} else {
page.data.version = version;
}
},
};
};