sybotan-vue-doc 项目提供在 vuepress 文档上引入 git 源代码功能。目前只支持基于 gogs 的 git 仓库。
修改项目文件 “package.json”。在 “dependencies” 项目下增加 "sybotan-vue-doc"依赖。
"dependencies": {
......
"sybotan-vue-doc": "^1.1.21",
......
},
在 Windows 控制台 或 IDE 开发环境的控制台窗口,切换到文档项目所在文件夹。执行以下安装命令。
npm install
修改项目文件 “docs/.vuepress/enhanceApp.js“,如果不存在则创建该文件。
import Vue from "vue"
import SDoc from "sybotan-vue-doc"
Vue.use(SDoc);
PCodeGit 组件用于在文档中引入 git 代码。例如,以下代码引用 git 仓库 ”libs/sybotan-ts“ 的代码 ”/base/src/core/SObject.ts“。
<PCodeGit repos="libs/sybotan-ts" src="/base/src/core/SObject.ts" lang="javascript"></PCodeGit>
| 属性 | 说明 | 默认值 | 必须 |
|---|---|---|---|
| repos | git 仓库名称 | - | 是 |
| src | 源码路径 | - | 是 |
| branch | 分枝 | master | - |
| lang | 语言 | javascript | - |
git 仓库与文档可能不在一个服务器上,这将导至跨域访问问题。因此,需要配置代理来解决跨域问题。
修改 vuepress 项目的项目配置文件 “docs/.vuepress/config.js”。在 module.exports 配置中增加 git 代理设置。
module.exports = {
......
devServer: {
proxy: {
'/gogs/': {
target: 'http://git.sybotan.com',
ws: true,
changeOrigin: true,
pathRewrite: {
'^/gogs/': '/'
},
bypass: function(req, res, proxyOptions) {
req.headers["Authorization"] = "Basic Z29nczoxMjM0NTY="
}
}
}
}
}
说明:
nginx 的配置文件在 ”/etc/nginx/conf.d/“ 文件夹下。以下示例为文档放在 http://docs.sybotan.com ,gogs 仓库部署在 http://git.sybotan.com 的示例配置。
server {
listen 80;
server_name docs.sybotan.com;
location / {
root /web/docs;
index index.html index.htm;
}
location /gogs {
proxy_pass http://git.sybotan.com;
proxy_set_header Authorization "Basic Z29nczoxMjM0NTY=";
rewrite ^/gogs/(.*)$ /$1 break;
}
}
说明: