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')
txtRelease(metadata, content)
jsonRelease(metadata, content)
htmlRelease(metadata, content)
# txtRelease(metadata, content)
# jsonRelease(metadata, content)
# htmlRelease(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',
'calibre': 'xxrs.html',
'gitbook': 'xxrs-online/',
'temp': 'xxrs-static/',
}
releaseInfo = { # convert to absolute path
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 json
import shutil
import tempfile
import subprocess
from .common import rootPath
from .common import saveFile
@ -71,7 +73,7 @@ def staticDepends(workDir: str, metadata: dict, content: dict) -> None:
'description': projectDesc,
"language": "zh-hans",
'plugins': [
'-search', '-sharing', 'hints', 'github',
'-lunr', '-search', '-sharing', 'hints', 'github',
'fontsettings', 'image-captions', 'back-to-top-button'
],
'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:
createFolder(releaseInfo['temp'])
# TODO: using temp folder module
staticDepends(releaseInfo['temp'], metadata, content)
# TODO: building static html by docker `node:10-alpine` container
# TODO: confirm running under root
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