mirror of
https://github.com/Estom/notes.git
synced 2026-04-25 02:52:37 +08:00
修改脚本
This commit is contained in:
@@ -1,5 +1 @@
|
|||||||
<!-- _sidebar.md -->
|
- [首页](.)
|
||||||
|
|
||||||
* 设计模式
|
|
||||||
* [设计模式之美](./设计模式/0%20设计模式之美.md)
|
|
||||||
* [设计模式原则](./设计模式/1.1%20单一职责原则.md)
|
|
||||||
|
|||||||
@@ -7,13 +7,14 @@ base_dir = None
|
|||||||
start_with = None
|
start_with = None
|
||||||
show_file = None
|
show_file = None
|
||||||
ignore_file_name = None
|
ignore_file_name = None
|
||||||
|
include_start_with = None
|
||||||
|
|
||||||
out_file_list = []
|
out_file_list = []
|
||||||
create_depth = -1
|
create_depth = -1
|
||||||
|
|
||||||
|
|
||||||
def read_config():
|
def read_config():
|
||||||
global base_dir, show_file, start_with, ignore_file_name, ReadmeFile, _sidebarFile, out_file_list, create_depth
|
global base_dir, show_file, start_with, ignore_file_name, ReadmeFile, _sidebarFile, out_file_list, create_depth,include_start_with
|
||||||
|
|
||||||
cf = ConfigParser()
|
cf = ConfigParser()
|
||||||
cf.read("config.ini", encoding='utf-8')
|
cf.read("config.ini", encoding='utf-8')
|
||||||
@@ -21,6 +22,7 @@ def read_config():
|
|||||||
start_with = cf.get("config", "ignore_start_with").split("|")
|
start_with = cf.get("config", "ignore_start_with").split("|")
|
||||||
show_file = cf.get("config", "show_file").split('|')
|
show_file = cf.get("config", "show_file").split('|')
|
||||||
ignore_file_name = cf.get("config", "ignore_file_name").split("|")
|
ignore_file_name = cf.get("config", "ignore_file_name").split("|")
|
||||||
|
include_start_with = cf.get("config", "include_start_with").split("|")
|
||||||
|
|
||||||
out_file_list = cf.get("outFile", "eachFile").split("|")
|
out_file_list = cf.get("outFile", "eachFile").split("|")
|
||||||
create_depth = int(cf.get("outFile", "create_depth"))
|
create_depth = int(cf.get("outFile", "create_depth"))
|
||||||
@@ -49,9 +51,32 @@ def check_file_name_satified(file_path):
|
|||||||
file_name = splitext(file_name_with_extension)[0]
|
file_name = splitext(file_name_with_extension)[0]
|
||||||
if file_name[0] in start_with or file_name in ignore_file_name:
|
if file_name[0] in start_with or file_name in ignore_file_name:
|
||||||
return False
|
return False
|
||||||
|
if file_name[0] not in include_start_with:
|
||||||
|
return False
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
|
def create_directory_node():
|
||||||
|
'''
|
||||||
|
创建目录树
|
||||||
|
标记当前目录节点下是否有.md文件
|
||||||
|
'''
|
||||||
|
pass
|
||||||
|
|
||||||
|
def build_next_level():
|
||||||
|
'''
|
||||||
|
创建下一级节点的目录_sidebar.md
|
||||||
|
创建当前目录级别的README.md,如果没有则创建,如果有则不创建。
|
||||||
|
'''
|
||||||
|
pass
|
||||||
|
|
||||||
|
def build_full_level():
|
||||||
|
'''
|
||||||
|
创建所有子节点的目录_sidebar.md
|
||||||
|
创建单签目录级别的README.md,如果没有则创建,如果有则不创建。
|
||||||
|
'''
|
||||||
|
pass
|
||||||
|
|
||||||
def save_structure(root_dir, base_dir=base_dir, depth=0):
|
def save_structure(root_dir, base_dir=base_dir, depth=0):
|
||||||
"""
|
"""
|
||||||
遍历指定目录及其所有子目录,生成并保存目录结构。
|
遍历指定目录及其所有子目录,生成并保存目录结构。
|
||||||
@@ -74,12 +99,12 @@ def save_structure(root_dir, base_dir=base_dir, depth=0):
|
|||||||
if create_depth == 0:
|
if create_depth == 0:
|
||||||
subdir_structure += "- " + subdir_name + '\n'
|
subdir_structure += "- " + subdir_name + '\n'
|
||||||
else:
|
else:
|
||||||
subdir_structure += "- [" + subdir_name + "](" + relpath(root, base_dir) + '\)\n'
|
subdir_structure += "- [" + subdir_name + "](" + relpath(root, base_dir) + ')\n'
|
||||||
else:
|
else:
|
||||||
if create_depth == 0:
|
if create_depth == 0:
|
||||||
subdir_structure += "- " + "首页" + '\n'
|
subdir_structure += "- " + "首页" + '\n'
|
||||||
else:
|
else:
|
||||||
subdir_structure += "- [" + "首页" + "](" + relpath(root, base_dir) + '\)\n'
|
subdir_structure += "- [" + "首页" + "](" + relpath(root, base_dir) + ')\n'
|
||||||
|
|
||||||
for file in files:
|
for file in files:
|
||||||
if check_file_name_satified(join(root, file)):
|
if check_file_name_satified(join(root, file)):
|
||||||
@@ -97,11 +122,11 @@ def save_structure(root_dir, base_dir=base_dir, depth=0):
|
|||||||
|
|
||||||
back_struct = subdir_structure
|
back_struct = subdir_structure
|
||||||
if depth == 1:
|
if depth == 1:
|
||||||
subdir_structure = "- [" + "返回首页" + "](" + "" + '\?id=main)\n' + subdir_structure
|
subdir_structure = "- [" + "返回首页" + "](" + "" + '?id=main)\n' + subdir_structure
|
||||||
elif depth != 0:
|
elif depth != 0:
|
||||||
abs_pre_path = abspath(join(root, ".."))
|
abs_pre_path = abspath(join(root, ".."))
|
||||||
rel_pre_path = relpath(abs_pre_path, base_dir)
|
rel_pre_path = relpath(abs_pre_path, base_dir)
|
||||||
subdir_structure = "- [" + "返回上一级" + "](" + rel_pre_path + '\)\n' + subdir_structure
|
subdir_structure = "- [" + "返回上一级" + "](" + rel_pre_path + ')\n' + subdir_structure
|
||||||
|
|
||||||
subdir_structure = subdir_structure.replace('\\', '/')
|
subdir_structure = subdir_structure.replace('\\', '/')
|
||||||
print("%s : finished" % root_dir)
|
print("%s : finished" % root_dir)
|
||||||
@@ -117,7 +142,18 @@ def save_structure(root_dir, base_dir=base_dir, depth=0):
|
|||||||
return back_struct
|
return back_struct
|
||||||
|
|
||||||
|
|
||||||
|
class Node:
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
'''
|
||||||
|
如果默认n层目录
|
||||||
|
第n-1层会生成n层目录的_sidebar
|
||||||
|
第n层生成之后所有目录的_sidebar
|
||||||
|
'''
|
||||||
|
import os
|
||||||
read_config()
|
read_config()
|
||||||
|
os.chdir(base_dir)
|
||||||
|
print(os.getcwd())
|
||||||
save_structure(base_dir, base_dir, 0)
|
save_structure(base_dir, base_dir, 0)
|
||||||
input()
|
|
||||||
|
|||||||
@@ -7,10 +7,11 @@ ignore_start_with=_|.
|
|||||||
show_file=.md
|
show_file=.md
|
||||||
# 要忽略的文件名,要添加新文件,用“|”分隔
|
# 要忽略的文件名,要添加新文件,用“|”分隔
|
||||||
ignore_file_name=README
|
ignore_file_name=README
|
||||||
|
include_start_with=docker|java
|
||||||
|
|
||||||
|
|
||||||
[outFile]
|
[outFile]
|
||||||
# 想要在几级目录生成文件,默认"-1"表示所有文件夹生成,"0"表示在根目录生成,可以配合侧边栏折叠插件使用
|
# 想要在几级目录生成文件,默认"-1"表示所有文件夹生成,"0"表示在根目录生成,可以配合侧边栏折叠插件使用
|
||||||
create_depth=1
|
create_depth=1
|
||||||
# 每个文件夹下主页文件名称和侧边栏文件名,默认README.md和_sidebar.md文件,想生成其他名称可修改文字,或者添加用“|”分隔
|
# 每个文件夹下主页文件名称和侧边栏文件名,默认README.md和_sidebar.md文件,想生成其他名称可修改文字,或者添加用“|”分隔
|
||||||
eachFile=README.md|_sidebar.md
|
eachFile=_sidebar.md
|
||||||
Reference in New Issue
Block a user