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 os
import json import json
onlineDesc = '《栩栩若生》在线阅读'
projectUrl = 'https://github.com/dnomd343/xxrs-crawler' projectUrl = 'https://github.com/dnomd343/xxrs-crawler'
rootPath = os.path.join( # project root directory 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 isRoot
from .common import rootPath from .common import rootPath
from .common import saveFile from .common import saveFile
from .common import onlineDesc
from .common import projectUrl from .common import projectUrl
from .common import releaseInfo from .common import releaseInfo
from .common import createFolder 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'], './assets/'))
createFolder(os.path.join(releaseInfo['gitbook'], './chapter/')) 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(): for (resName, resUrls) in resourceInfo.items():
cover += '{% hint style="success" %}\n' \ cover += '{% hint style="success" %}\n' \
+ '### [%s](%s)([备用地址](%s))\n' % (resName, resUrls[1], resUrls[0]) \ + '### [%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, './assets/'))
createFolder(os.path.join(workDir, './chapter/')) 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(): for (resName, resUrls) in resourceInfo.items():
cover += '\n{% hint style="none" %}\n' \ cover += '\n{% hint style="none" %}\n' \
+ '#### [%s](%s)([备用地址](%s))\n' % (resName, resUrls[1], resUrls[0]) \ + '#### [%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({ bookInfo = json.dumps({
'title': metadata['name'], 'title': metadata['name'],
'author': metadata['author'], 'author': metadata['author'],
'description': '%s》在线阅读' % metadata['name'],
"language": "zh-hans", "language": "zh-hans",
'plugins': [ 'plugins': [
'-lunr', '-search', '-sharing', 'hints', 'github', '-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, 'README.md'), cover)
saveFile(os.path.join(workDir, 'book.json'), bookInfo) saveFile(os.path.join(workDir, 'book.json'), bookInfo)
saveFile(os.path.join(workDir, 'SUMMARY.md'), gitbookSummary(content)) 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) saveFile(os.path.join(workDir, chapterPath), chapterContent)
shutil.copy( # gitbook cover shutil.copy( # gitbook cover
os.path.join(rootPath, './assets/cover.jpg'), 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: def gitbookMetadata(metadata: dict) -> str:
return '---\ndescription: 作者:%s\n---\n\n# %s\n\n' % ( return ''.join([
metadata['author'], metadata['name'] '# %s\n\n' % metadata['name'],
) + '<figure style="%s"><img src="%s" alt=""><figcaption><p>%s</p></figcaption></figure>\n\n' % ( '<figure style="text-align:center">',
'text-align:center', 'assets/cover.jpg', metadata['name'] '<img src="%s" alt=""><figcaption>' % 'assets/cover.jpg',
) + '\n>\n'.join(['> %s' % x for x in metadata['desc']]) + '\n\n' '<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: def gitbookChapterPath(caption: str) -> str:
@ -79,11 +81,11 @@ def gitbookSummary(chapters: dict) -> str:
return summary return summary
def gitbookChapters(chapters: dict) -> dict: def gitbookChapters(chapters: dict, header: str = '') -> dict:
result = {} result = {}
for (caption, content) in chapters.items(): for (caption, content) in chapters.items():
content = [markdownTransfer(x) for x in content] 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) caption, '\n\n'.join(content)
) )
return result return result

Loading…
Cancel
Save