Browse Source

Added support for multiversion build (wip)

master
Youen 2 years ago
parent
commit
7be5ec701d
  1. 31
      src/data/document.py
  2. 2
      src/web/web_document.py

31
src/data/document.py

@ -53,14 +53,30 @@ class Document:
self.doc_path = doc_path
self.valid = True
# TODO: actually read document settings
self.settings = {
'multiversion': False,
'default_version': 'main'
}
def build(self):
#venv_path = os.getenv('VIRTUAL_ENV')
multiversion_build = self.settings['multiversion']
cmd = []
# update source files from git
cmd.append(['git', 'pull'])
if multiversion_build:
# also fetch all branches and tags, so that sphinx-multiversion knows what versions exist and can pull them
cmd.append(['bash', '-c', 'for BRANCH in $(git branch -a | grep remotes | grep -v HEAD | grep -v master); do git branch --track "${BRANCH#remotes/origin/}" "${BRANCH}" || echo "(ignored)"; done'])
# build the HTML version
cmd.append(['make', 'html_versions', 'BUILDDIR=../build'])
# TODO: build PDF(s) version(s)
else:
# build the HTML version
cmd.append(['make', 'html', 'BUILDDIR=../build'])
@ -70,6 +86,13 @@ class Document:
# Copy the generated PDF file to the HTML directory, so that it is accessible for download by users
cmd.append(['cp', self.doc_path + '/build/weasyprint/vheliotech.pdf', self.doc_path + '/build/html/' + self.doc_name + '.pdf'])
# Now that the build is successfull, move it to the deployment directory (replacing any existing content)
cmd.append(['rm', '-rf', self.doc_path + '/dist'])
if multiversion_build:
cmd.append(['mv', self.doc_path + '/build/html_versions/', self.doc_path + '/dist/'])
else:
cmd.append(['mv', self.doc_path + '/build/html/', self.doc_path + '/dist/'])
task = ProcessTask(cmd, cwd = self.doc_path + "/repo")
task.start()
@ -91,9 +114,15 @@ class Document:
os.rmdir(origin_root)
def get_url(self):
if self.settings['multiversion']:
return "/doc/" + self.encoded_origin + "/" + sanitize_name(self.doc_name)+'/'+sanitize_name(self.branch) + "/" + self.settings['default_version'] + "/index.html"
else:
return "/doc/" + self.encoded_origin + "/" + sanitize_name(self.doc_name)+'/'+sanitize_name(self.branch) + "/index.html"
def get_pdf_url(self):
if self.settings['multiversion']:
return "/doc/" + self.encoded_origin + "/" + sanitize_name(self.doc_name)+'/'+sanitize_name(self.branch) + "/" + self.settings['default_version'] + "/" + self.doc_name + ".pdf"
else:
return "/doc/" + self.encoded_origin + "/" + sanitize_name(self.doc_name)+'/'+sanitize_name(self.branch) + "/" + self.doc_name + ".pdf"
def get_api_key(self):

2
src/web/web_document.py

@ -9,4 +9,4 @@ bp = Blueprint('web_document', __name__, url_prefix='/doc')
@bp.route('/<origin>/<doc_name>/<branch>/<path:path>')
def index(origin, doc_name, branch, path):
doc = Document(origin, doc_name, branch)
return send_from_directory(doc.doc_path + "/build/html", path)
return send_from_directory(doc.doc_path + "/dist", path)

Loading…
Cancel
Save