提交 33755262 编写于 作者: F feilong

增加关键字

上级 4eba44d4
{
"node_id": "gml-62c30f9c31f64a1d96af732c47c93f04",
"keywords": [],
"keywords": [
"Git历史",
"你了解版本控制系统吗?",
"什么是本地版本控制系统",
"什么是集中化的版本控制系统",
"什么是分布式版本控制系统",
"Git 诞生的故事"
],
"children": [],
"export": [
"learn.json"
......
......@@ -2,5 +2,6 @@
"type": "code_options",
"author": "csdn.net",
"source": "learn.md",
"exercise_id": "399ebefcdd3444d4a99c140527c8d98d"
"exercise_id": "399ebefcdd3444d4a99c140527c8d98d",
"notebook_enable": false
}
\ No newline at end of file
{
"node_id": "gml-17121b66f9a942629bc455f320b28910",
"keywords": [],
"keywords": [
"msys git",
"5分钟教你学会 git 安装",
"不同操作系统的安装介绍",
"Git 的环境配置",
"Git 的自定义设置",
"Git 自定义别名"
],
"children": [],
"export": [
"learn.json"
......
......@@ -2,5 +2,6 @@
"type": "code_options",
"author": "csdn.net",
"source": "learn.md",
"exercise_id": "2c2b3735973143c7a001d0f550a9b9c6"
"exercise_id": "2c2b3735973143c7a001d0f550a9b9c6",
"notebook_enable": false
}
\ No newline at end of file
{
"node_id": "gml-598d225d1a78453d8992345f8f7902ba",
"keywords": [],
"keywords": [
"Git基本用法",
"创建仓库: git init / git clone",
"添加文件: git add / git commit",
"查看修改: git status / git diff",
"恢复文件: git log / git reset"
],
"children": [],
"export": [
"learn.json"
......
......@@ -2,5 +2,6 @@
"type": "code_options",
"author": "csdn.net",
"source": "learn.md",
"exercise_id": "ec97e801f80f47e3a8218f511f9ecd06"
"exercise_id": "ec97e801f80f47e3a8218f511f9ecd06",
"notebook_enable": false
}
\ No newline at end of file
{
"node_id": "gml-f0d68868583b48d0851c7add33e2f8ff",
"keywords": [],
"keywords": [
"Git 撤销",
"Git 删除"
],
"children": [],
"export": [
"learn.json"
......
......@@ -2,5 +2,6 @@
"type": "code_options",
"author": "csdn.net",
"source": "learn.md",
"exercise_id": "f8a64858e47e4504989c3b33ba9b11e0"
"exercise_id": "f8a64858e47e4504989c3b33ba9b11e0",
"notebook_enable": false
}
\ No newline at end of file
{
"node_id": "gml-5b37ae204b1f4183b1a2853f32698407",
"keywords": [],
"keywords": [
"git 分支原理",
"修改不同的分支",
"git 合并分支",
"git 合并策略",
"git 创建合并请求",
"解决合并请求中的冲突",
"cherry-pick 介绍及用法",
"git 的多人协作"
],
"children": [],
"export": [
"learn.json"
......
......@@ -2,5 +2,6 @@
"type": "code_options",
"author": "csdn.net",
"source": "learn.md",
"exercise_id": "5591a41efbc049f3ba57daeaf24e2001"
"exercise_id": "5591a41efbc049f3ba57daeaf24e2001",
"notebook_enable": false
}
\ No newline at end of file
{
"node_id": "gml-7b2351b6989f4ec19655498bbb4bafb1",
"keywords": [],
"keywords": [
"git tag"
],
"children": [],
"export": [
"learn.json"
......
......@@ -2,5 +2,6 @@
"type": "code_options",
"author": "csdn.net",
"source": "learn.md",
"exercise_id": "8694fd578817477d8b699cfa801dedc2"
"exercise_id": "8694fd578817477d8b699cfa801dedc2",
"notebook_enable": false
}
\ No newline at end of file
{
"node_id": "gml-e67e64c1c880432ab6bc1b0452124ec0",
"keywords": [],
"keywords": [
"认识 Markdown",
"使用 Markdown 的误区"
],
"children": [],
"export": [
"learn.json"
......
......@@ -2,5 +2,6 @@
"type": "code_options",
"author": "csdn.net",
"source": "learn.md",
"exercise_id": "f033c7a4957a4f908f66f5a348274cde"
"exercise_id": "f033c7a4957a4f908f66f5a348274cde",
"notebook_enable": false
}
\ No newline at end of file
{
"node_id": "gml-627f564073834c8d86e45f126ac628df",
"keywords": [],
"keywords": [
"MarkDown段落",
"MarkDown段落的换行",
"MarkDown斜体",
"MarkDown粗体",
"MarkDown删除线"
],
"children": [],
"export": [
"learn.json"
......
......@@ -2,5 +2,6 @@
"type": "code_options",
"author": "csdn.net",
"source": "learn.md",
"exercise_id": "b03d2e4169a14e2599719ab881974c0a"
"exercise_id": "b03d2e4169a14e2599719ab881974c0a",
"notebook_enable": false
}
\ No newline at end of file
{
"node_id": "gml-30e9989f9a5f44fab349734a8e4479a3",
"keywords": [],
"keywords": [
"Setext 标题",
"Atx 标题"
],
"children": [],
"export": [
"learn.json"
......
......@@ -2,5 +2,6 @@
"type": "code_options",
"author": "csdn.net",
"source": "learn.md",
"exercise_id": "8844d2a58b3744a59f004d067e6ec935"
"exercise_id": "8844d2a58b3744a59f004d067e6ec935",
"notebook_enable": false
}
\ No newline at end of file
{
"node_id": "gml-3cb459e3d1a147a8b89291c1ef4147c7",
"keywords": [],
"keywords": [
"行内链接",
"参考样式链接"
],
"children": [],
"export": [
"learn.json"
......
......@@ -2,5 +2,6 @@
"type": "code_options",
"author": "csdn.net",
"source": "learn.md",
"exercise_id": "48621469905d49ce88133d7af94a3d70"
"exercise_id": "48621469905d49ce88133d7af94a3d70",
"notebook_enable": false
}
\ No newline at end of file
{
"node_id": "gml-2f1e2810b721429dba664414438b6d87",
"keywords": [],
"keywords": [
"行内图片",
"参考样式图片"
],
"children": [],
"export": [
"learn.json"
......
......@@ -2,5 +2,6 @@
"type": "code_options",
"author": "csdn.net",
"source": "learn.md",
"exercise_id": "d2cf04bb0acc417995cb301f45da5eb3"
"exercise_id": "d2cf04bb0acc417995cb301f45da5eb3",
"notebook_enable": false
}
\ No newline at end of file
{
"node_id": "gml-b4a4f06aa5114c3fa6a590d659037370",
"keywords": [],
"keywords": [
"无序列表",
"有序列表",
"任务列表"
],
"children": [],
"export": [
"learn.json"
......
......@@ -2,5 +2,6 @@
"type": "code_options",
"author": "csdn.net",
"source": "learn.md",
"exercise_id": "973934ecb71045beadcf4b5bd3778012"
"exercise_id": "973934ecb71045beadcf4b5bd3778012",
"notebook_enable": false
}
\ No newline at end of file
{
"node_id": "gml-b6b6f01fb86141768c5b242327f1e0fa",
"keywords": [],
"keywords": [
"分隔线",
"区块引用"
],
"children": [],
"export": [
"learn.json"
......
......@@ -2,5 +2,6 @@
"type": "code_options",
"author": "csdn.net",
"source": "learn.md",
"exercise_id": "ed154ec698ce462d9147c16a0bdf0139"
"exercise_id": "ed154ec698ce462d9147c16a0bdf0139",
"notebook_enable": false
}
\ No newline at end of file
{
"node_id": "gml-2e87affacacd4078a3ba55a5a15a8f7a",
"keywords": [],
"keywords": [
"行内代码",
"代码缩进",
"代码高亮",
"代码 Diff"
],
"children": [],
"export": [
"learn.json"
......
......@@ -2,5 +2,6 @@
"type": "code_options",
"author": "csdn.net",
"source": "learn.md",
"exercise_id": "78ab9558c2cb42cabf233350b3ad2095"
"exercise_id": "78ab9558c2cb42cabf233350b3ad2095",
"notebook_enable": false
}
\ No newline at end of file
{
"node_id": "gml-11620ba793c74faa9a5117ca07d748d6",
"keywords": [],
"keywords": [
"创建MarkDown表格",
"MarkDown表格对齐"
],
"children": [],
"export": [
"learn.json"
......
......@@ -2,5 +2,6 @@
"type": "code_options",
"author": "csdn.net",
"source": "learn.md",
"exercise_id": "c028bd1229dd48aa90ce0987a9dd475d"
"exercise_id": "c028bd1229dd48aa90ce0987a9dd475d",
"notebook_enable": false
}
\ No newline at end of file
......@@ -16,42 +16,76 @@
{
"Git简介": {
"node_id": "gml-62c30f9c31f64a1d96af732c47c93f04",
"keywords": [],
"keywords": [
"Git历史",
"你了解版本控制系统吗?",
"什么是本地版本控制系统",
"什么是集中化的版本控制系统",
"什么是分布式版本控制系统",
"Git 诞生的故事"
],
"children": []
}
},
{
"Git安装": {
"node_id": "gml-17121b66f9a942629bc455f320b28910",
"keywords": [],
"keywords": [
"msys git",
"5分钟教你学会 git 安装",
"不同操作系统的安装介绍",
"Git 的环境配置",
"Git 的自定义设置",
"Git 自定义别名"
],
"children": []
}
},
{
"Git使用": {
"node_id": "gml-598d225d1a78453d8992345f8f7902ba",
"keywords": [],
"keywords": [
"Git基本用法",
"创建仓库: git init / git clone",
"添加文件: git add / git commit",
"查看修改: git status / git diff",
"恢复文件: git log / git reset"
],
"children": []
}
},
{
"版本管理": {
"node_id": "gml-f0d68868583b48d0851c7add33e2f8ff",
"keywords": [],
"keywords": [
"Git 撤销",
"Git 删除"
],
"children": []
}
},
{
"分支管理": {
"node_id": "gml-5b37ae204b1f4183b1a2853f32698407",
"keywords": [],
"keywords": [
"git 分支原理",
"修改不同的分支",
"git 合并分支",
"git 合并策略",
"git 创建合并请求",
"解决合并请求中的冲突",
"cherry-pick 介绍及用法",
"git 的多人协作"
],
"children": []
}
},
{
"Git标签": {
"node_id": "gml-7b2351b6989f4ec19655498bbb4bafb1",
"keywords": [],
"keywords": [
"git tag"
],
"children": []
}
}
......@@ -66,63 +100,96 @@
{
"MarkDown介绍": {
"node_id": "gml-e67e64c1c880432ab6bc1b0452124ec0",
"keywords": [],
"keywords": [
"认识 Markdown",
"使用 Markdown 的误区"
],
"children": []
}
},
{
"段落及强调": {
"node_id": "gml-627f564073834c8d86e45f126ac628df",
"keywords": [],
"keywords": [
"MarkDown段落",
"MarkDown段落的换行",
"MarkDown斜体",
"MarkDown粗体",
"MarkDown删除线"
],
"children": []
}
},
{
"标题": {
"node_id": "gml-30e9989f9a5f44fab349734a8e4479a3",
"keywords": [],
"keywords": [
"Setext 标题",
"Atx 标题"
],
"children": []
}
},
{
"链接": {
"node_id": "gml-3cb459e3d1a147a8b89291c1ef4147c7",
"keywords": [],
"keywords": [
"行内链接",
"参考样式链接"
],
"children": []
}
},
{
"图片": {
"node_id": "gml-2f1e2810b721429dba664414438b6d87",
"keywords": [],
"keywords": [
"行内图片",
"参考样式图片"
],
"children": []
}
},
{
"列表": {
"node_id": "gml-b4a4f06aa5114c3fa6a590d659037370",
"keywords": [],
"keywords": [
"无序列表",
"有序列表",
"任务列表"
],
"children": []
}
},
{
"分隔线及引用": {
"node_id": "gml-b6b6f01fb86141768c5b242327f1e0fa",
"keywords": [],
"keywords": [
"分隔线",
"区块引用"
],
"children": []
}
},
{
"代码块": {
"node_id": "gml-2e87affacacd4078a3ba55a5a15a8f7a",
"keywords": [],
"keywords": [
"行内代码",
"代码缩进",
"代码高亮",
"代码 Diff"
],
"children": []
}
},
{
"表格": {
"node_id": "gml-11620ba793c74faa9a5117ca07d748d6",
"keywords": [],
"keywords": [
"创建MarkDown表格",
"MarkDown表格对齐"
],
"children": []
}
}
......
......@@ -4,6 +4,8 @@ import os
import re
import sys
import uuid
import re
import git
id_set = set()
logger = logging.getLogger(__name__)
......@@ -12,6 +14,11 @@ handler = logging.StreamHandler(sys.stdout)
formatter = logging.Formatter('%(asctime)s - %(levelname)s - %(message)s')
handler.setFormatter(formatter)
logger.addHandler(handler)
repo = git.Repo(".")
def user_name():
return repo.config_reader().get_value("user", "name")
def load_json(p):
......@@ -103,6 +110,7 @@ class TreeWalker:
full_path = os.path.join(
chapter_path, f"{index + 1}.{section_title}")
if os.path.isdir(full_path):
self.check_section_keywords(full_path)
self.ensure_exercises(full_path)
tree_path = os.path.join(self.root, "tree.json")
......@@ -302,9 +310,71 @@ class TreeWalker:
def ensure_exercises(self, section_path):
config = self.ensure_section_config(section_path)
flag = False
for e in os.listdir(section_path):
base, ext = os.path.splitext(e)
_, source = os.path.split(e)
if ext != ".md":
continue
mfile = base + ".json"
meta_path = os.path.join(section_path, mfile)
self.ensure_exercises_meta(meta_path, source)
export = config.get("export", [])
if mfile not in export and self.name != "algorithm":
export.append(mfile)
flag = True
config["export"] = export
if flag:
dump_json(os.path.join(section_path, "config.json"),
config, True, True)
for e in config.get("export", []):
full_name = os.path.join(section_path, e)
exercise = load_json(full_name)
if "exercise_id" not in exercise:
exercise["exercise_id"] = uuid.uuid4().hex
if "exercise_id" not in exercise or exercise.get("exercise_id") in id_set:
eid = uuid.uuid4().hex
exercise["exercise_id"] = eid
dump_json(full_name, exercise, True, True)
else:
id_set.add(exercise["exercise_id"])
def ensure_exercises_meta(self, meta_path, source):
_, mfile = os.path.split(meta_path)
meta = None
if os.path.exists(meta_path):
with open(meta_path) as f:
content = f.read()
if content:
meta = json.loads(content)
if "exercise_id" not in meta:
meta["exercise_id"] = uuid.uuid4().hex
if "notebook_enable" not in meta:
meta["notebook_enable"] = self.default_notebook()
if "source" not in meta:
meta["source"] = source
if "author" not in meta:
meta["author"] = user_name()
if "type" not in meta:
meta["type"] = "code_options"
if meta is None:
meta = {
"type": "code_options",
"author": user_name(),
"source": source,
"notebook_enable": self.default_notebook(),
"exercise_id": uuid.uuid4().hex
}
dump_json(meta_path, meta, True, True)
def default_notebook(self):
if self.name in ["python", "java", "c"]:
return True
else:
return False
def check_section_keywords(self, full_path):
config = self.ensure_section_config(full_path)
if not config.get("keywords", []):
self.logger.error(f"节点 [{full_path}] 的关键字为空,请修改配置文件写入关键字")
sys.exit(1)
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册
新手
引导
客服 返回
顶部