【问题标题】:Basic flask implementation of Docsify documentationDocsify 文档的基本烧瓶实现
【发布时间】:2019-06-01 12:56:17
【问题描述】:

我遇到了 Docsify (https://docsify.js.org/#/),并且在尝试它时玩得很开心。我有兴趣使用我自己的烧瓶服务器而不是 Github Pages 或节点来提供一些文档,但是我不知道如何实现它。

如 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 中,我使用的是应用工厂 + 蓝图模式,就 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 -&gt; documentation -&gt; documentation 文件夹中,我添加了一个README.md,其级别与我对上述Docsify 示例所做的相同,该示例在本地提供的服务非常好。

index.html 通过烧瓶加载(仔细查看,您会看到侧边栏和汉堡菜单按钮),但降价内容没有,我收到“404 - 未找到”消息。

我根本不知道如何实现这一点,更不用说如何优雅地做到这一点了。

【问题讨论】:

    标签: python flask docsify


    【解决方案1】:

    这是我的工作:

    location /doc/ {
        index index.html;
        root /www/api/templates;
    }
    

    然后你可以像我一样在 /doc 访问你的文档: enter image description here

    这是我对网站的看法(由纯 html 编写): enter image description here

    【讨论】:

    • 这个需要他使用nginx
    • @alessandrocaprarelli 是的,是的
    【解决方案2】:

    如果您在站点的根目录提供index.html(即 3000 的本地开发人员:localhost:3000/),则 docsify 将尝试从同一级别开始获取所有其他文件。在您的情况下,它希望在此端点 localhost:3000/README.md 找到 README.md

    你可以这样做:

    • 在您的烧瓶服务器中创建一个路由,如/documentation,它为文档文件夹中的所有文件提供服务。这样,您将在/documentation/README.md 处获得README.md 文件
    • 在 docsify 配置中添加 basePath 属性 (https://docsify.js.org/#/configuration?id=basepath):basePath: '/documentation/'

    通过这种方式,您应该能够从路由 /documentation/* 访问您的所有 .md 文件,并且 docsify 将成功呈现它们。

    【讨论】:

      猜你喜欢
      • 2020-10-18
      • 1970-01-01
      • 2017-09-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-06-12
      • 1970-01-01
      相关资源
      最近更新 更多