Skip to content

Commit

Permalink
feat(docs): use webpack to load openapi yaml schema
Browse files Browse the repository at this point in the history
  • Loading branch information
zikeji committed Oct 19, 2020
1 parent 317c375 commit 33bc537
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 27 deletions.
26 changes: 2 additions & 24 deletions docs/.vuepress/components/OpenAPI.vue
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import prism from "prismjs";
import "prismjs/components/prism-json";
import "prismjs/components/prism-typescript";
import "swagger-ui/dist/swagger-ui.css";
import spec from "../../../openapi.yaml";
const md = new Remarkable({
html: true,
Expand Down Expand Up @@ -66,29 +67,6 @@ const PrismJSPlugin = function (system) {
highlightCode: PrismJSComponent,
Markdown: MarkdownComponent,
},
// wrapComponents: {
// Markdown: (Original) => (props) => {
// console.log(md.render(props.source));
// let result;
// let newSource = props.source;
// while ((result = codeRegex.exec(props.source)) !== null) {
// const lang = result[1];
// if (prism.languages[lang]) {
// const code = prism.highlight(
// result[2],
// prism.languages[lang],
// lang
// );
// newSource = newSource.replace(
// result[0],
// `<pre class="language-${lang}"><code>${code}</code></pre>`
// );
// }
// }
// props.source = newSource;
// return Original(props);
// },
// },
};
};
Expand All @@ -97,7 +75,7 @@ export default {
this.$nextTick(() => {
const domNode = document.getElementById("openapi-wrapper");
SwaggerUI({
url: "/openapi.yaml",
spec,
domNode,
docExpansion: "list",
deepLinking: false,
Expand Down
10 changes: 8 additions & 2 deletions docs/.vuepress/config.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const { writeFileSync, copyFileSync } = require("fs");
const { writeFileSync } = require("fs");
const { resolve } = require("path");
const { config } = require("vuepress-theme-hope");
const { name, version, description, repository } = require("../../package.json");
Expand All @@ -24,7 +24,6 @@ const oembed = {
};

writeFileSync(resolve(__dirname, "public", "oembed.json"), JSON.stringify(oembed, null, 2));
copyFileSync(resolve(__dirname, "../", "../", "openapi.yaml"), resolve(__dirname, "public", "openapi.yaml"));

module.exports = config({
title: name,
Expand Down Expand Up @@ -127,6 +126,13 @@ module.exports = config({
blue: "#2196f3"
},
},
configureWebpack: {
module: {
rules: [
{ test: /\.ya?ml$/, use: 'yaml-loader', type: 'json' }
]
}
},
plugins: [
[
"vuepress-plugin-typedoc",
Expand Down
10 changes: 10 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,8 @@
"typescript": "^4.0.3",
"vuepress": "^1.7.1",
"vuepress-plugin-typedoc": "^0.1.1",
"vuepress-theme-hope": "^1.1.0"
"vuepress-theme-hope": "^1.1.0",
"yaml-loader": "^0.6.0"
},
"config": {
"commitizen": {
Expand Down

0 comments on commit 33bc537

Please sign in to comment.