Browse Source

feat: use node container to build static web pages

master
Dnomd343 2 years ago
parent
commit
142c8436fb
  1. 8
      src/release/release.py
  2. 1
      src/release/utils/common.py
  3. 33
      src/release/utils/release.py

8
src/release/demo.py → src/release/release.py

@ -11,8 +11,8 @@ from utils import gitbookRelease
metadata, content = loadBook('rc-5') metadata, content = loadBook('rc-5')
txtRelease(metadata, content) # txtRelease(metadata, content)
jsonRelease(metadata, content) # jsonRelease(metadata, content)
htmlRelease(metadata, content) # htmlRelease(metadata, content)
staticRelease(metadata, content) staticRelease(metadata, content)
gitbookRelease(metadata, content) # gitbookRelease(metadata, content)

1
src/release/utils/common.py

@ -22,7 +22,6 @@ releaseInfo = { # release file name
'static': 'XXRS.tar.xz', 'static': 'XXRS.tar.xz',
'calibre': 'xxrs.html', 'calibre': 'xxrs.html',
'gitbook': 'xxrs-online/', 'gitbook': 'xxrs-online/',
'temp': 'xxrs-static/',
} }
releaseInfo = { # convert to absolute path releaseInfo = { # convert to absolute path
key: os.path.join(releasePath, file) for (key, file) in releaseInfo.items() key: os.path.join(releasePath, file) for (key, file) in releaseInfo.items()

33
src/release/utils/release.py

@ -4,6 +4,8 @@
import os import os
import json import json
import shutil import shutil
import tempfile
import subprocess
from .common import rootPath from .common import rootPath
from .common import saveFile from .common import saveFile
@ -71,7 +73,7 @@ def staticDepends(workDir: str, metadata: dict, content: dict) -> None:
'description': projectDesc, 'description': projectDesc,
"language": "zh-hans", "language": "zh-hans",
'plugins': [ 'plugins': [
'-search', '-sharing', 'hints', 'github', '-lunr', '-search', '-sharing', 'hints', 'github',
'fontsettings', 'image-captions', 'back-to-top-button' 'fontsettings', 'image-captions', 'back-to-top-button'
], ],
'pluginsConfig': { 'pluginsConfig': {
@ -89,8 +91,29 @@ def staticDepends(workDir: str, metadata: dict, content: dict) -> None:
) )
def staticBuild(workDir: str) -> None:
buildDir = '/xxrs/'
nodeImage = 'node:10-alpine'
buildCommand = 'docker run --rm -v %s:%s --entrypoint sh %s -c "%s"' % (
workDir, buildDir, nodeImage,
'npm install gitbook-cli -g && gitbook install %s && gitbook build %s --log=debug' % (
buildDir, buildDir
)
)
print('Gitbook Build -> %s' % workDir)
subprocess.Popen(buildCommand, shell = True).wait() # blocking wait
os.chdir(os.path.join(workDir, './_book'))
os.popen('tar cJf %s *' % releaseInfo['static'])
def staticRelease(metadata: dict, content: dict) -> None: def staticRelease(metadata: dict, content: dict) -> None:
createFolder(releaseInfo['temp'])
# TODO: using temp folder module # TODO: confirm running under root
staticDepends(releaseInfo['temp'], metadata, content)
# TODO: building static html by docker `node:10-alpine` container tempDir = tempfile.TemporaryDirectory() # access temporary directory
content = {x: content[x] for x in list(content)[:20]} # TODO: just for test
staticDepends(tempDir.name, metadata, content)
staticBuild(tempDir.name)
tempDir.cleanup()

Loading…
Cancel
Save