Browse Source

update: release output folder

master
Dnomd343 2 years ago
parent
commit
7b038af838
  1. 8
      src/release/calibre_html.py
  2. 12
      src/release/common.py
  3. 17
      src/release/gitbook.py
  4. 8
      src/release/json_dumps.py
  5. 8
      src/release/txt_release.py

8
src/release/calibre_html.py

@ -4,8 +4,7 @@
import sys import sys
from common import loadData from common import loadData
from common import saveFile from common import saveFile
from common import releaseInfo
htmlFile = 'xxrs.html'
def formatMetadata(metadata: dict) -> str: def formatMetadata(metadata: dict) -> str:
@ -25,4 +24,7 @@ def htmlRelease(metadata: dict, content: dict) -> str:
if __name__ == '__main__': if __name__ == '__main__':
data = loadData(sys.argv[1]) data = loadData(sys.argv[1])
saveFile(htmlFile, htmlRelease(data['metadata'], data['content'])) saveFile(
releaseInfo['htmlFile'],
htmlRelease(data['metadata'], data['content'])
)

12
src/release/common.py

@ -9,8 +9,17 @@ rootPath = os.path.join(
os.path.dirname(os.path.realpath(__file__)), '../../' os.path.dirname(os.path.realpath(__file__)), '../../'
) )
dataPath = os.path.join(rootPath, './release/') dataPath = os.path.join(rootPath, './release/')
releasePath = os.path.join(dataPath, './output/')
metadataFile = os.path.join(rootPath, './assets/metadata.json') metadataFile = os.path.join(rootPath, './assets/metadata.json')
releaseInfo = {
'txtFile': 'xxrs.txt',
'htmlFile': 'xxrs.html',
'jsonFile': 'xxrs.json',
'gitbookDir': 'xxrs-online',
}
releaseInfo = {x: os.path.join(releasePath, y) for (x, y) in releaseInfo.items()}
def loadData(jsonName: str) -> dict: # load book data from json file def loadData(jsonName: str) -> dict: # load book data from json file
content = json.loads(open( content = json.loads(open(
@ -31,3 +40,6 @@ def saveFile(fileName: str, content: str) -> None: # save into file
def createFolder(folderName: str) -> None: # create folder def createFolder(folderName: str) -> None: # create folder
if not os.path.exists(folderName): if not os.path.exists(folderName):
os.mkdir(folderName) os.mkdir(folderName)
createFolder(releasePath)

17
src/release/gitbook.py

@ -8,15 +8,14 @@ import shutil
from common import loadData from common import loadData
from common import rootPath from common import rootPath
from common import saveFile from common import saveFile
from common import releaseInfo
from common import createFolder from common import createFolder
workDir = './xxrs-online/'
def initFolder() -> None: def initFolder() -> None:
createFolder(workDir) createFolder(releaseInfo['gitbookDir'])
createFolder(os.path.join(workDir, './assets/')) createFolder(os.path.join(releaseInfo['gitbookDir'], './assets/'))
createFolder(os.path.join(workDir, './content/')) createFolder(os.path.join(releaseInfo['gitbookDir'], './content/'))
def loadChapter(caption: str, content: list) -> str: def loadChapter(caption: str, content: list) -> str:
@ -24,7 +23,7 @@ def loadChapter(caption: str, content: list) -> str:
chapterNum = '0' * (3 - len(chapterNum)) + chapterNum # add `0` prefix chapterNum = '0' * (3 - len(chapterNum)) + chapterNum # add `0` prefix
fileName = 'chapter-%s.md' % chapterNum fileName = 'chapter-%s.md' % chapterNum
saveFile( saveFile(
os.path.join(workDir, './content/', fileName), os.path.join(releaseInfo['gitbookDir'], './content/', fileName),
'# %s\n\n%s\n' % (caption, '\n\n'.join(content)) '# %s\n\n%s\n' % (caption, '\n\n'.join(content))
) )
return fileName return fileName
@ -42,7 +41,7 @@ def loadCover(metadata: dict) -> None:
cover += '<figure><img src="assets/cover.jpg" alt=""><figcaption><p>栩栩若生</p></figcaption></figure>\n\n' cover += '<figure><img src="assets/cover.jpg" alt=""><figcaption><p>栩栩若生</p></figcaption></figure>\n\n'
cover += '\n>\n'.join(['> %s' % x for x in metadata['desc']]) + '\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' cover += '{% embed url="https://github.com/dnomd343/xxrs-crawler.git" %}\n项目地址\n{% endembed %}\n'
saveFile(os.path.join(workDir, 'README.md'), cover + '\n') saveFile(os.path.join(releaseInfo['gitbookDir'], 'README.md'), cover + '\n')
def loadSummary(catalog: dict) -> None: def loadSummary(catalog: dict) -> None:
@ -51,7 +50,7 @@ def loadSummary(catalog: dict) -> None:
summary += '## 内容 <a href="#content" id="content"></a>\n\n' summary += '## 内容 <a href="#content" id="content"></a>\n\n'
for (title, mdFile) in catalog.items(): for (title, mdFile) in catalog.items():
summary += '* [%s](content/%s)\n' % (title, mdFile) summary += '* [%s](content/%s)\n' % (title, mdFile)
saveFile(os.path.join(workDir, 'SUMMARY.md'), summary) saveFile(os.path.join(releaseInfo['gitbookDir'], 'SUMMARY.md'), summary)
def loadGitbook(jsonName: str) -> None: def loadGitbook(jsonName: str) -> None:
@ -61,7 +60,7 @@ def loadGitbook(jsonName: str) -> None:
loadSummary(catalog) loadSummary(catalog)
shutil.copy( shutil.copy(
os.path.join(rootPath, './assets/cover.jpg'), os.path.join(rootPath, './assets/cover.jpg'),
os.path.join(workDir, './assets/cover.jpg') os.path.join(releaseInfo['gitbookDir'], './assets/cover.jpg')
) )

8
src/release/json_dumps.py

@ -5,8 +5,7 @@ import sys
import json import json
from common import loadData from common import loadData
from common import saveFile from common import saveFile
from common import releaseInfo
jsonFile = 'xxrs.json'
def jsonRelease(metadata: dict, content: dict) -> str: def jsonRelease(metadata: dict, content: dict) -> str:
@ -18,4 +17,7 @@ def jsonRelease(metadata: dict, content: dict) -> str:
if __name__ == '__main__': if __name__ == '__main__':
data = loadData(sys.argv[1]) data = loadData(sys.argv[1])
saveFile(jsonFile, jsonRelease(data['metadata'], data['content'])) saveFile(
releaseInfo['jsonFile'],
jsonRelease(data['metadata'], data['content'])
)

8
src/release/release_txt.py → src/release/txt_release.py

@ -4,8 +4,7 @@
import sys import sys
from common import loadData from common import loadData
from common import saveFile from common import saveFile
from common import releaseInfo
txtFile = 'xxrs.txt'
def formatMetadata(metadata: dict) -> str: def formatMetadata(metadata: dict) -> str:
@ -25,4 +24,7 @@ def txtRelease(metadata: dict, content: dict) -> str:
if __name__ == '__main__': if __name__ == '__main__':
data = loadData(sys.argv[1]) data = loadData(sys.argv[1])
saveFile(txtFile, txtRelease(data['metadata'], data['content'])) saveFile(
releaseInfo['txtFile'],
txtRelease(data['metadata'], data['content'])
)
Loading…
Cancel
Save