我遇到了Docsify(https://docsify.js.org/#/),并尝试了它很有趣。我有兴趣使用自己的Flask服务器而不是Github Pages或与node一起提供一些文档,但是我不知道如何实现它。
如Docsify(https://docsify.js.org/#/quickstart?id=manual-initialization)所述,本地提供简单的index.html
进行渲染,而README.md
作为降价内容的效果很好。
index.html
<!-- index.html -->
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport" content="width=device-width,initial-scale=1">
<meta charset="UTF-8">
<link rel="stylesheet" href="//unpkg.com/docsify/themes/vue.css">
</head>
<body>
<div id="app"></div>
<script>
window.$docsify = {
//...
}
</script>
<script src="//unpkg.com/docsify/lib/docsify.min.js"></script>
</body>
</html>
README.md
# Hi, I'm markdown content
运行静态服务器的命令行(有效):
python -m SimpleHTTPServer 3000
现在,在Flask中,我使用的是app factory + blueprints模式,就Flask而言,一切正常。我可以添加一个新的端点,它可以很好地呈现。我的文件结构:
├── instance
│ └── flask.cfg
├── main.py
├── project
│ ├── __init__.py
│ ├── front
│ │ ├── __init__.py
│ │ ├── routes.py
│ │ └── templates
│ │ └── front
│ │ └── index.html
│ ├── documentation
│ │ ├── __init__.py
│ │ ├── routes.py
│ │ └── templates
│ │ └── documentation
│ │ ├── README.md
│ │ └── index.html
│ ├── static
│ │ ├── favicon.ico
│ │ └── style.css
│ └── templates
│ └── base.html
└── requirements.txt
在project -> documentation -> documentation
文件夹中,我将以与上述Docsify示例相同的级别添加一个README.md
,该示例在本地的投放效果很好。
index.html
通过烧瓶加载(仔细查看,您会看到一个侧边栏和汉堡菜单按钮),但降价内容没有,并且我收到“ 404-未找到”消息。
我只是不知道如何实现它,更不用说如何优雅地做到这一点了。
答案 0 :(得分:0)
这是我的工作:
location /doc/ {
index index.html;
root /www/api/templates;
}
,然后您可以像我的一样通过/ doc访问您的文档: enter image description here
这是我对网站的看法(用纯HTML编写): enter image description here
答案 1 :(得分:0)
如果您将index.html
服务于站点的根目录(即本地开发者的服务级别为3000:localhost:3000/
),则docsify会尝试从同一级别开始获取所有其他文件。对于您而言,它希望在此端点README.md
上找到localhost:3000/README.md
。
您可以执行以下操作:
/documentation
,该路由将提供文档文件夹中的所有文件。这样,您将在README.md
上获得/documentation/README.md
文件basePath
属性(https://docsify.js.org/#/configuration?id=basepath):basePath: '/documentation/'
通过这种方式,您应该能够从路由.md
访问所有/documentation/*
文件,并且docsify将成功呈现它们。