forked from Estom/notes
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
15 changed files
with
449 additions
and
21 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<!-- _coverpage.md --> | ||
|
||
![](./blog/image/cat.svg) | ||
|
||
# 乘上梦想的帆,轻轻远航 | ||
|
||
> 💪通灵诗人的个人知识库,欢迎关注。 | ||
[GitHub](https://github.com/Estom) | ||
[Let Go](/README.md) | ||
|
||
<!-- 背景色 --> | ||
<!-- ![color](#f0f0f0) --> | ||
<!-- 背景图 --> | ||
![](./blog/image/cover2.jpg) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
-------------这是页脚------------------- |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1 @@ | ||
<!-- _navbar.md --> | ||
|
||
* 关注我 | ||
* [Github地址](https://github.com/Estom) | ||
* [Gitee地址](https://gitee.com/Eyestorm) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,5 @@ | ||
<!-- _sidebar.md --> | ||
|
||
* Typora+Docsify使用指南 | ||
* [Docsify使用指南](/ProjectDocs/Docsify使用指南.md) <!--注意这里是相对路径--> | ||
* [Typora+Docsify快速入门](/ProjectDocs/Typora+Docsify快速入门.md) | ||
* Docsify部署 | ||
* [Docsify部署教程](/ProjectDocs/Docsify部署教程.md) | ||
* 设计模式 | ||
* [设计模式之美](./设计模式/0%20设计模式之美.md) | ||
* [设计模式原则](./设计模式/1.1%20单一职责原则.md) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,191 @@ | ||
# docsify 侧边栏自动生成脚本 | ||
|
||
# docsify sidebar automatically generates scripts | ||
|
||
> 打包成exe文件,程序大小约为5M,还是比较轻量的,主要文件有: | ||
> 1. buildSidebar.exe -> 执行程序后在config.ini设置的根目录下文件夹生成READMD.md和_sidebar.md(名称可自定义) | ||
> 2. config.ini -> 配置生成文件的一些输出文件\忽略情况等选项,具体可以看config.ini文件中注释 | ||
docsify好像没法自动读取文件夹目录结构并且展示在页面上,需要对每个文件夹配置_sidebar.md文件 | ||
|
||
所以我尝试用python做了一个脚本,基本就用到了os库中的一些函数,所以打包成exe文件大小在可以接受的范围里面,只有5M左右 | ||
|
||
该程序运行的配置参数依赖于config.ini,所以使用前请将config.ini和builSidebar.exe放在同一个目录下 | ||
|
||
在生成md文件结构时,有时想要**忽略一些文件**或者**"_"开头的文件夹**,可以通过config.ini配置 | ||
|
||
```ini | ||
[config] | ||
# docsify根目录 | ||
base_dir=D:\MyData\Data\Docsify\docs | ||
# 忽略以“_”,"."开头的文件,如果要添加新文件,用“|”分隔 | ||
ignore_start_with=_|. | ||
# 只读取".md"格式问价,如果添加新格式,用“|”分隔 | ||
show_file=.md | ||
# 要忽略的文件名,要添加新文件,用“|”分隔 | ||
ignore_file_name=README | ||
|
||
|
||
[outFile] | ||
# 想要在几级目录生成文件,默认"-1"表示所有文件夹生成,"0"表示在根目录生成,可以配合侧边栏折叠插件使用 | ||
create_depth=0 | ||
# 每个文件夹下主页文件名称和侧边栏文件名,默认README.md和_sidebar.md文件,想生成其他名称可修改文字,或者添加用“|”分隔 | ||
eachFile=README.md|_sidebar.md | ||
``` | ||
|
||
# 举例1 | ||
|
||
> 在每一个子文件夹下生成文件 | ||
原先文件夹的结构是 | ||
|
||
``` | ||
docs | ||
│ .nojekyll | ||
│ ceede.md | ||
│ index.html | ||
│ _coverpage.md | ||
│ | ||
├─PLC | ||
│ │ 电梯群控算法.md | ||
│ │ | ||
│ └─最新测试 | ||
│ hi回答.md | ||
│ | ||
├─_media | ||
│ Pasted image 20230403194327.png | ||
│ | ||
└─启发式算法 | ||
│ 差分进化算法.md | ||
│ | ||
└─测试 | ||
测试.md | ||
``` | ||
|
||
我在config.ini设置忽略: | ||
1. 以"_","."开头的文件 | ||
2. 忽略文件名为README的文件 | ||
3. 结构中只包括".md"开头的文件 | ||
|
||
运行程序得到的结构是 | ||
|
||
``` | ||
docs | ||
│ .nojekyll | ||
│ ceede.md | ||
│ index.html | ||
│ README.md | ||
│ _coverpage.md | ||
│ _sidebar.md | ||
│ | ||
├─PLC | ||
│ │ README.md | ||
│ │ _sidebar.md | ||
│ │ 电梯群控算法.md | ||
│ │ | ||
│ └─最新测试 | ||
│ hi回答.md | ||
│ README.md | ||
│ _sidebar.md | ||
│ | ||
├─_media | ||
│ Pasted image 20230403194327.png | ||
│ | ||
└─启发式算法 | ||
│ README.md | ||
│ _sidebar.md | ||
│ 差分进化算法.md | ||
│ | ||
└─测试 | ||
README.md | ||
_sidebar.md | ||
测试.md | ||
``` | ||
|
||
可以看到_media没有被操作,也符合要求 | ||
|
||
## 图片 | ||
|
||
在根目录情况: | ||
|
||
![img0.png](image/img0.png) | ||
|
||
点击PLC之后 | ||
|
||
![img4.png](image/img4.png) | ||
|
||
这种方式生成的结构,点击新文件夹会刷新界面,也可以接受 | ||
|
||
# 举例2 | ||
|
||
> 上面的格式中,点击相应文件夹实际上会跳转,如果不想跳转,可以设置config.ini文件的create_depth参数 | ||
> | ||
> 当参数为-1时候,则每个文件夹生成文件 | ||
> | ||
> 当参数为0时,仅在根目录生成 | ||
该功能配合侧边栏折叠效果更好 | ||
|
||
原先结构 | ||
|
||
``` | ||
docs | ||
│ .nojekyll | ||
│ ceede.md | ||
│ index.html | ||
│ _coverpage.md | ||
│ | ||
├─PLC | ||
│ │ 电梯群控算法.md | ||
│ │ | ||
│ └─最新测试 | ||
│ hi回答.md | ||
│ | ||
├─_media | ||
│ Pasted image 20230403194327.png | ||
│ | ||
└─启发式算法 | ||
│ 差分进化算法.md | ||
│ | ||
└─测试 | ||
测试.md | ||
``` | ||
|
||
config.ini中`create_depth`设为0 | ||
|
||
生成的新结构 | ||
|
||
``` | ||
docs | ||
│ .nojekyll | ||
│ ceede.md | ||
│ index.html | ||
│ README.md | ||
│ _coverpage.md | ||
│ _sidebar.md | ||
│ | ||
├─PLC | ||
│ │ 电梯群控算法.md | ||
│ │ | ||
│ └─最新测试 | ||
│ hi回答.md | ||
│ | ||
├─_media | ||
│ Pasted image 20230403194327.png | ||
│ | ||
└─启发式算法 | ||
│ 差分进化算法.md | ||
│ | ||
└─测试 | ||
测试.md | ||
``` | ||
|
||
可以看到仅在根目录生成了文件 | ||
|
||
## 图片 | ||
|
||
![img.png](image/img.png) | ||
|
||
配合侧边栏折叠插件:https://github.com/iPeng6/docsify-sidebar-collapse | ||
|
||
![img2.png](image/img2.png) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,123 @@ | ||
from configparser import ConfigParser | ||
from os.path import splitext, basename, join, isdir, relpath, abspath | ||
from os import listdir | ||
|
||
|
||
base_dir = None | ||
start_with = None | ||
show_file = None | ||
ignore_file_name = None | ||
|
||
out_file_list = [] | ||
create_depth = -1 | ||
|
||
|
||
def read_config(): | ||
global base_dir, show_file, start_with, ignore_file_name, ReadmeFile, _sidebarFile, out_file_list, create_depth | ||
|
||
cf = ConfigParser() | ||
cf.read("config.ini", encoding='utf-8') | ||
base_dir = cf.get("config", "base_dir") | ||
start_with = cf.get("config", "ignore_start_with").split("|") | ||
show_file = cf.get("config", "show_file").split('|') | ||
ignore_file_name = cf.get("config", "ignore_file_name").split("|") | ||
|
||
out_file_list = cf.get("outFile", "eachFile").split("|") | ||
create_depth = int(cf.get("outFile", "create_depth")) | ||
|
||
|
||
def check_file_extension(file_path): | ||
""" | ||
检查文件后缀是否为指定的后缀 | ||
:param file_path: 文件路径 | ||
:return: 如果文件后缀为指定的后缀,返回True;否则返回False | ||
""" | ||
file_extension = splitext(file_path)[1] | ||
if file_extension in show_file: | ||
return True | ||
else: | ||
return False | ||
|
||
|
||
def check_file_name_satified(file_path): | ||
""" | ||
获取文件名(不包括扩展名) | ||
:param file_path: 文件路径 | ||
:return: 文件名(不包括扩展名) | ||
""" | ||
file_name_with_extension = basename(file_path) | ||
file_name = splitext(file_name_with_extension)[0] | ||
if file_name[0] in start_with or file_name in ignore_file_name: | ||
return False | ||
return True | ||
|
||
|
||
def save_structure(root_dir, base_dir=base_dir, depth=0): | ||
""" | ||
遍历指定目录及其所有子目录,生成并保存目录结构。 | ||
:param root_dir: 要处理的根目录路径 | ||
:param base_dir: 用来获得root_dir对base_dir的相对路径 | ||
:param depth: 递归深度,文件夹深度 | ||
""" | ||
root = root_dir | ||
dirs = [] | ||
files = [] | ||
for item in listdir(root): | ||
if isdir(join(root, item)): | ||
dirs.append(item) | ||
else: | ||
files.append(item) | ||
subdir_structure = '' | ||
subdir_name = basename(root) | ||
|
||
if depth != 0: | ||
if create_depth == 0: | ||
subdir_structure += "- " + subdir_name + '\n' | ||
else: | ||
subdir_structure += "- [" + subdir_name + "](" + relpath(root, base_dir) + '\)\n' | ||
else: | ||
if create_depth == 0: | ||
subdir_structure += "- " + "首页" + '\n' | ||
else: | ||
subdir_structure += "- [" + "首页" + "](" + relpath(root, base_dir) + '\)\n' | ||
|
||
for file in files: | ||
if check_file_name_satified(join(root, file)): | ||
if check_file_extension(file): | ||
subdir_structure += " " + "- [" + file + "](" + relpath(join(root, file), | ||
base_dir) + ')\n' | ||
|
||
for subdir in dirs: | ||
subdir_path = join(root, subdir) | ||
if check_file_name_satified(subdir_path): | ||
next_struct = save_structure(subdir_path, base_dir, depth + 1) | ||
next_struct = next_struct[:-1] if next_struct.endswith("\n") else next_struct | ||
next_struct = next_struct.replace("\n", "\n ") + "\n" | ||
subdir_structure += " " + next_struct | ||
|
||
back_struct = subdir_structure | ||
if depth == 1: | ||
subdir_structure = "- [" + "返回首页" + "](" + "" + '\?id=main)\n' + subdir_structure | ||
elif depth != 0: | ||
abs_pre_path = abspath(join(root, "..")) | ||
rel_pre_path = relpath(abs_pre_path, base_dir) | ||
subdir_structure = "- [" + "返回上一级" + "](" + rel_pre_path + '\)\n' + subdir_structure | ||
|
||
subdir_structure = subdir_structure.replace('\\', '/') | ||
print("%s : finished" % root_dir) | ||
if create_depth == -1: | ||
for file_name in out_file_list: | ||
with open(join(root, file_name), 'w', encoding="utf-8") as f: | ||
f.write(subdir_structure) | ||
else: | ||
if depth == 0 : | ||
for file_name in out_file_list: | ||
with open(join(root, file_name), 'w', encoding="utf-8") as f: | ||
f.write(subdir_structure) | ||
return back_struct | ||
|
||
|
||
if __name__ == "__main__": | ||
read_config() | ||
save_structure(base_dir, base_dir, 0) | ||
input() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
[config] | ||
# docsify根目录 | ||
base_dir=E:\gitee\notes | ||
# 忽略以“_”,"."开头的文件,如果要添加新文件,用“|”分隔 | ||
ignore_start_with=_|. | ||
# 只读取".md"格式问价,如果添加新格式,用“|”分隔 | ||
show_file=.md | ||
# 要忽略的文件名,要添加新文件,用“|”分隔 | ||
ignore_file_name=README | ||
|
||
|
||
[outFile] | ||
# 想要在几级目录生成文件,默认"-1"表示所有文件夹生成,"0"表示在根目录生成,可以配合侧边栏折叠插件使用 | ||
create_depth=1 | ||
# 每个文件夹下主页文件名称和侧边栏文件名,默认README.md和_sidebar.md文件,想生成其他名称可修改文字,或者添加用“|”分隔 | ||
eachFile=README.md|_sidebar.md |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Oops, something went wrong.