# knowledge **Repository Path**: mochenyi/mochenyi ## Basic Information - **Project Name**: knowledge - **Description**: 新增知识分享页 - **Primary Language**: Unknown - **License**: MIT - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2023-02-28 - **Last Updated**: 2023-10-13 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # Docsify > 一个可以将 md 文件直接生成页面的博客部署工具,本文简单的介绍下它的使用。 ## 使用 1. 下载它 ```sh npm i docsify-cli -g ``` > warning: 不要使用 cnpm 2. 初始化 在要添加项目的文件夹内打开命令窗口 ```sh docsify init ./docs ``` ./docs 指在当前目录下创建 docs 文件夹,然后将项目文件初始化入该文件 3. 运行服务 ```js docsify serve ./docs ``` 打开服务,默认地址: ## 简介 + `index.html` 入口文件 + `README.md` 会作为主页内容渲染 + `.nojekyll` 用于阻止 GitHub Pages 忽略掉下划线开头的文件 ## 设置 ### 封面设置 ```js window.$docsify = { coverpage: true } ``` 开启封面,并且可以在根目录创建`_coverpage.md`文件,里面写具体配置和页面内容: ```markdown ![logo](_media/icon.svg) # docsify 3.5 > A magical documentation site generator. - Simple and lightweight - No statically built html files - Multiple themes [GitHub](https://github.com/docsifyjs/docsify/) [Get Started](#docsify) ![](_media/bg.png) ![color](#f0f0f0) ``` ### 配置名称 ```js window.$docsify = { name: '技术随身录' } ``` 会在左侧边栏顶部出现 ### 配置github链接 ```js window.$docsify = { repo: 'https://github.com/docsifyjs/docsify/', } ``` 会在屏幕右上角出现 GitHub 的图标,点击会跳转到对应的链接 ### 导航栏配置 可以在当前页面上直接书写导航: ```html
``` 也可以通过`_navbar.md`来设置: ```js window.$docsify = { loadNavbar: true } ``` ```markdown * [En](/) * [chinese](/zh-cn/) ``` ### 侧边栏配置 ```js window.$docsify = { loadNavbar: true } ``` 然后通过`_sidebar.md`来配置侧边栏信息 ```markdown * [Home](/) * [Guide](guide.md) ``` ### 多文件结构 + 直接在根目录以 xx.md 创建文件,那么默认就会有 #/xx 路由显示对应文件; + 若是创建一个文件夹,然后在里面创建 README.md 文件,例如:music/README.md,则访问 #/music/ 可以显示对应文件; 示例 - 文件结构: ```text . └── docs ├── README.md ├── guide.md └── zh-cn ├── README.md └── guide.md ``` 示例 - 匹配的路由 ```text docs/README.md => http://domain.com docs/guide.md => http://domain.com/#/guide docs/zh-cn/README.md => http://domain.com/#/zh-cn/ docs/zh-cn/guide.md => http://domain.com/#/zh-cn/guide ``` ### 配置 404 页 默认显示 “404-Not found” 文本,如下: ```js window.$docsify = { notFoundPage: false } ``` 可以通过 `_404.md` 文件配置: ```js window.$docsify = { notFoundPage: true } ``` 设定不同路由的404页面 ```js window.$docsify = { notFoundPage: { '/': '_404.md', '/de': 'de/_404.md' } } ``` ### 自定义路由 可以通过 routes 对象属性自定义路由,接收`路由路径: 字符串/函数`作为属性,字符串表示某个具体的文档路径,函数则需要返回值为文档内容(默认三个参数:route、matched、next) ```js window.$docsify = { routes: { // Basic match w/ return string '/foo': '# Custom Markdown', // RegEx match w/ synchronous function '/bar/(.*)': function(route, matched) { return '# Custom Markdown'; }, // RegEx match w/ asynchronous function '/baz/(.*)': function(route, matched, next) { // Requires `fetch` polyfill for legacy browsers (https://github.github.io/fetch/) fetch('/api/users?id=12345') .then(function(response) { next('# Custom Markdown'); }) .catch(function(err) { // Handle error... }); } } } ``` ## 插件 ### 搜索 ```js window.$docsify = { search: 'auto', // default search: [ '/', // => /README.md '/guide', // => /guide.md '/get-started', // => /get-started.md '/zh-cn/', // => /zh-cn/README.md ], // complete configuration parameters search: { maxAge: 86400000, // Expiration time, the default one day paths: [], // or 'auto' placeholder: 'Type to search', // Localization placeholder: { '/zh-cn/': '搜索', '/': 'Type to search', }, noData: 'No Results!', // Localization noData: { '/zh-cn/': '找不到结果', '/': 'No Results', }, // Headline depth, 1 - 6 depth: 2, hideOtherSidebarContent: false, // whether or not to hide other sidebar content // To avoid search index collision // between multiple websites under the same domain namespace: 'website-1', // Use different indexes for path prefixes (namespaces). // NOTE: Only works in 'auto' mode. // // When initialiazing an index, we look for the first path from the sidebar. // If it matches the prefix from the list, we switch to the corresponding index. pathNamespaces: ['/zh-cn', '/ru-ru', '/ru-ru/v1'], // You can provide a regexp to match prefixes. In this case, // the matching substring will be used to identify the index pathNamespaces: /^(\/(zh-cn|ru-ru))?(\/(v1|v2))?/, }, }; ``` ### 给代码块添加上复制按钮 在页面引入对应JS文件 ```html ``` [点这里](https://github.com/jperasmus/docsify-copy-code/blob/master/README.md)查看更多细节 ### 添加评论 [Gitalk](https://github.com/gitalk/gitalk) is a modern comment component based on Github Issue and Preact. ```html ```