Browse Source

update: gitbook description meta

master
Dnomd343 2 years ago
parent
commit
44ee554d81
  1. 1
      src/release/utils/common.py
  2. 11
      src/release/utils/release.py
  3. 16
      src/release/utils/sequence.py

1
src/release/utils/common.py

@ -4,6 +4,7 @@
import os
import json
onlineDesc = '《栩栩若生》在线阅读'
projectUrl = 'https://github.com/dnomd343/xxrs-crawler'
rootPath = os.path.join( # project root directory

11
src/release/utils/release.py

@ -10,6 +10,7 @@ import subprocess
from .common import isRoot
from .common import rootPath
from .common import saveFile
from .common import onlineDesc
from .common import projectUrl
from .common import releaseInfo
from .common import createFolder
@ -36,7 +37,8 @@ def gitbookRelease(metadata: dict, content: dict) -> None:
createFolder(os.path.join(releaseInfo['gitbook'], './assets/'))
createFolder(os.path.join(releaseInfo['gitbook'], './chapter/'))
cover = gitbookMetadata(metadata)
cover = '---\ndescription: 作者:%s\n---\n\n' % metadata['author']
cover += gitbookMetadata(metadata)
for (resName, resUrls) in resourceInfo.items():
cover += '{% hint style="success" %}\n' \
+ '### [%s](%s)([备用地址](%s))\n' % (resName, resUrls[1], resUrls[0]) \
@ -57,7 +59,8 @@ def staticDepends(workDir: str, metadata: dict, content: dict) -> None:
createFolder(os.path.join(workDir, './assets/'))
createFolder(os.path.join(workDir, './chapter/'))
cover = gitbookMetadata(metadata) + '<hr/>\n'
cover = '---\ndescription: %s\n---\n\n' % onlineDesc
cover += gitbookMetadata(metadata) + '<hr/>\n'
for (resName, resUrls) in resourceInfo.items():
cover += '\n{% hint style="none" %}\n' \
+ '#### [%s](%s)([备用地址](%s))\n' % (resName, resUrls[1], resUrls[0]) \
@ -66,7 +69,6 @@ def staticDepends(workDir: str, metadata: dict, content: dict) -> None:
bookInfo = json.dumps({
'title': metadata['name'],
'author': metadata['author'],
'description': '%s》在线阅读' % metadata['name'],
"language": "zh-hans",
'plugins': [
'-lunr', '-search', '-sharing', 'hints', 'github',
@ -82,7 +84,8 @@ def staticDepends(workDir: str, metadata: dict, content: dict) -> None:
saveFile(os.path.join(workDir, 'README.md'), cover)
saveFile(os.path.join(workDir, 'book.json'), bookInfo)
saveFile(os.path.join(workDir, 'SUMMARY.md'), gitbookSummary(content))
for (chapterPath, chapterContent) in gitbookChapters(content).items():
descHeader = '---\ndescription: %s\n---\n\n' % onlineDesc
for (chapterPath, chapterContent) in gitbookChapters(content, header = descHeader).items():
saveFile(os.path.join(workDir, chapterPath), chapterContent)
shutil.copy( # gitbook cover
os.path.join(rootPath, './assets/cover.jpg'),

16
src/release/utils/sequence.py

@ -57,11 +57,13 @@ def htmlSerialize(metadata: dict, content: dict) -> str:
def gitbookMetadata(metadata: dict) -> str:
return '---\ndescription: 作者:%s\n---\n\n# %s\n\n' % (
metadata['author'], metadata['name']
) + '<figure style="%s"><img src="%s" alt=""><figcaption><p>%s</p></figcaption></figure>\n\n' % (
'text-align:center', 'assets/cover.jpg', metadata['name']
) + '\n>\n'.join(['> %s' % x for x in metadata['desc']]) + '\n\n'
return ''.join([
'# %s\n\n' % metadata['name'],
'<figure style="text-align:center">',
'<img src="%s" alt=""><figcaption>' % 'assets/cover.jpg',
'<p>%s</p></figcaption></figure>\n\n' % metadata['name'],
'\n>\n'.join(['> %s' % x for x in metadata['desc']]) + '\n\n',
])
def gitbookChapterPath(caption: str) -> str:
@ -79,11 +81,11 @@ def gitbookSummary(chapters: dict) -> str:
return summary
def gitbookChapters(chapters: dict) -> dict:
def gitbookChapters(chapters: dict, header: str = '') -> dict:
result = {}
for (caption, content) in chapters.items():
content = [markdownTransfer(x) for x in content]
result[gitbookChapterPath(caption)] = '# %s\n\n%s\n' % (
result[gitbookChapterPath(caption)] = header + '# %s\n\n%s\n' % (
caption, '\n\n'.join(content)
)
return result

Loading…
Cancel
Save