1 Star 0 Fork 0

iswbm/kubernetes-guide

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
pdf_maker.py 1.50 KB
一键复制 编辑 原始数据 按行查看 历史
iswbm 提交于 2022-01-25 00:20 +08:00 . 支持在线文档
#!/usr/local/bin/python3
import os
import glob
import fileinput
import linecache
from functools import partial
repo_dir = os.getcwd()
source_dir = os.path.join(repo_dir, "source")
all_md_path = os.path.join(repo_dir, "kubernetes-guide.pdf",)
count = 0
with open(all_md_path, "w") as all_md:
write = partial(print, file=all_md, end="")
os.chdir(source_dir)
for c_no in sorted(glob.glob("c*")):
if c_no == "chapters" or c_no == "conf.py":
continue
# 读取并记下章节名
c_name = linecache.getline(os.path.join(source_dir, "chapters", f"{c_no.replace('c', 'p')}.rst"), 2)
write(f"# {c_name}\n\n", file=all_md)
# 读取每一节的内容
all_md_file = sorted(glob.glob(f"{source_dir}/{c_no}/*.md"))
for line in fileinput.input(all_md_file):
if "20200804124133" in line or "20200607174235" in line:
continue
if fileinput.isfirstline():
count += 1
if count%5 == 0:
write("![](http://image.iswbm.com/20210606214719.png)", end="\n\n")
if line.startswith("# "):
line = line.replace("# ", "## ")
elif line.startswith("## "):
line = line.replace("## ", "### ")
elif line.startswith("### "):
line = line.replace("### ", "#### ")
elif "gif" in line:
line = line.replace("![]", "![该图为GIF,请前往 k8s.iswbm.com 浏览]")
write(line)
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/iswbm/kubernetes-guide.git
git@gitee.com:iswbm/kubernetes-guide.git
iswbm
kubernetes-guide
kubernetes-guide
master

搜索帮助