From 1ed6d02d34def59d1ce84272a44e589c6179f038 Mon Sep 17 00:00:00 2001 From: Dnomd343 Date: Thu, 29 Dec 2022 20:25:38 +0800 Subject: [PATCH] update: gitbook format --- src/release/gitbook.py | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) mode change 100644 => 100755 src/release/gitbook.py diff --git a/src/release/gitbook.py b/src/release/gitbook.py old mode 100644 new mode 100755 index 9c6addf..4ae96e7 --- a/src/release/gitbook.py +++ b/src/release/gitbook.py @@ -3,7 +3,10 @@ import os import re +import sys +import shutil from common import loadData +from common import rootPath from common import saveFile from common import createFolder @@ -35,15 +38,16 @@ def loadChapters(chapters: dict) -> dict: def loadCover(metadata: dict) -> None: - cover = '---\ndescription: 作者:%s\n---\n\n# %s\n\n' % (metadata['author'], metadata['name']) - cover += '
\n\n' - cover += '\n>\n'.join(['> %s' % x for x in metadata['desc']]) + cover = '---\ndescription: 作者:%s\n---\n\n# 栩栩若生\n\n' % metadata['author'] + cover += '

栩栩若生

\n\n' + cover += '\n>\n'.join(['> %s' % x for x in metadata['desc']]) + '\n\n' + cover += '{% embed url="https://github.com/dnomd343/xxrs-crawler.git" %}\n项目地址\n{% endembed %}\n' saveFile(os.path.join(workDir, 'README.md'), cover + '\n') def loadSummary(catalog: dict) -> None: summary = '# XXRS\n\n' - summary += '* [栩栩若生](README.md)\n\n' + summary += '* [序言](README.md)\n\n' summary += '## 内容 \n\n' for (title, mdFile) in catalog.items(): summary += '* [%s](content/%s)\n' % (title, mdFile) @@ -55,8 +59,12 @@ def loadGitbook(jsonName: str) -> None: loadCover(data['metadata']) catalog = loadChapters(data['content']) loadSummary(catalog) + shutil.copy( + os.path.join(rootPath, './assets/cover.jpg'), + os.path.join(workDir, './assets/cover.jpg') + ) if __name__ == '__main__': initFolder() - loadGitbook('rc-4') + loadGitbook(sys.argv[1])