diff --git a/gen.py b/gen.py new file mode 100644 index 0000000..a8cc4f5 --- /dev/null +++ b/gen.py @@ -0,0 +1,49 @@ +# coding=utf-8 +import yaml + +with open("mkdocs_template.yml", "r") as f: + raw_data = yaml.load(f) + data = raw_data["pages"] + + +def one(item, depth=0, result=""): + for k, v in item.iteritems(): + if isinstance(v, basestring): + result += " ".join([" " * depth, "-", "[" + k + "](/" + v.rstrip("index.md").rstrip(".md") + ")\n"]) + elif isinstance(v, list): + result += " ".join([" " * depth, "-", k, "\n"]) + for v_item in v: + result += one(v_item, depth+4) + return result + + +def get_all(l): + result = "" + for _ in l: + result += one(_) + return result + +new_data = [] +for _ in data: + name = list(_.iteritems())[0][0] + if name == "Home": + new_data.append(_) + content = get_all(data) + with open("src/index_template.md", "r") as f: + old = f.read() + old = old.replace("", content.encode("utf-8")) + with open("src/index.md", "w") as f: + f.write(old) + else: + content = one(_) + path = name + "/index.md" + with open("src/" + path, "w") as f: + f.write("# Table of contents\n" + content.encode("utf-8")) + tmp = [{"index": path}] + tmp.extend(_[name]) + new_data.append({name: tmp}) + +raw_data["pages"] = new_data + +with open("mkdocs.yml", "w") as f: + yaml.dump(raw_data, f, default_flow_style=False) diff --git a/mkdocs.yml b/mkdocs.yml deleted file mode 100644 index e1bbea2..0000000 --- a/mkdocs.yml +++ /dev/null @@ -1,19 +0,0 @@ -site_name: Online Judge Docs -theme: yeti -docs_dir: 'src' -site_dir: 'docs' -pages: - - Home: 'index.md' - - Judger: -# - 'Index': 'judger/index.md' - - 'English': - - 'API': 'judger/English/index.md' - - JudgeServer: -# - 'Index': 'judge_server/index.md' - - 'English': - - 'API': 'judge_server/English/index.md' - - 'Deploy': 'judge_server/English/deploy.md' -# - '中文': -# - 'API': 'judge_server/Chinese/index.md' -# - '部署': 'judge_server/Chinese/deploy.md' - diff --git a/mkdocs_template.yml b/mkdocs_template.yml new file mode 100644 index 0000000..fbc4607 --- /dev/null +++ b/mkdocs_template.yml @@ -0,0 +1,16 @@ +pages: +- Home: index.md +- Judger: + - English: + - API: Judger/English/index.md +- JudgeServer: + - English: + - API: JudgeServer/English/index.md + - Deploy: JudgeServer/English/deploy.md + - 中文: + - API: JudgeServer/Chinese/index.md + - 部署: JudgeServer/Chinese/deploy.md +docs_dir: src +site_dir: docs +site_name: Online Judge Docs +theme: yeti diff --git a/src/judge_server/Chinese/deploy.md b/src/JudgeServer/Chinese/deploy.md similarity index 100% rename from src/judge_server/Chinese/deploy.md rename to src/JudgeServer/Chinese/deploy.md diff --git a/src/judge_server/Chinese/index.md b/src/JudgeServer/Chinese/index.md similarity index 100% rename from src/judge_server/Chinese/index.md rename to src/JudgeServer/Chinese/index.md diff --git a/src/judge_server/English/deploy.md b/src/JudgeServer/English/deploy.md similarity index 100% rename from src/judge_server/English/deploy.md rename to src/JudgeServer/English/deploy.md diff --git a/src/judge_server/English/index.md b/src/JudgeServer/English/index.md similarity index 100% rename from src/judge_server/English/index.md rename to src/JudgeServer/English/index.md diff --git a/src/JudgeServer/index.md b/src/JudgeServer/index.md new file mode 100644 index 0000000..5f058a4 --- /dev/null +++ b/src/JudgeServer/index.md @@ -0,0 +1,8 @@ +# Table of contents + - JudgeServer + - English + - [API](/JudgeServer/English/) + - [Deploy](/JudgeServer/English/deploy) + - 中文 + - [API](/JudgeServer/Chinese/) + - [部署](/JudgeServer/Chinese/deploy) diff --git a/src/index.md b/src/index_template.md similarity index 92% rename from src/index.md rename to src/index_template.md index d2721d0..41d6274 100644 --- a/src/index.md +++ b/src/index_template.md @@ -3,3 +3,5 @@ 目前此处的文档均为未公开发布版本的,最新release的版本请参考github。 https://github.com/QingdaoU + + diff --git a/src/judge_server/index.md b/src/judge_server/index.md deleted file mode 100644 index d3b5668..0000000 --- a/src/judge_server/index.md +++ /dev/null @@ -1,7 +0,0 @@ -# 中文版本 - -[链接](Chinese) - -# English Version - -[link](English) diff --git a/src/judger/index.md b/src/judger/index.md index d3b5668..547710a 100644 --- a/src/judger/index.md +++ b/src/judger/index.md @@ -1,7 +1,4 @@ -# 中文版本 - -[链接](Chinese) - -# English Version - -[link](English) +# Table of contents + - Judger + - English + - [API](/Judger/English/)