commit
d5fe1d3635
@ -17,6 +17,7 @@ include requirements.txt
|
|||||||
include tox.ini
|
include tox.ini
|
||||||
include qutebrowser.py
|
include qutebrowser.py
|
||||||
|
|
||||||
|
prune www
|
||||||
prune scripts/dev
|
prune scripts/dev
|
||||||
exclude scripts/asciidoc2html.py
|
exclude scripts/asciidoc2html.py
|
||||||
exclude doc/notes
|
exclude doc/notes
|
||||||
|
@ -29,6 +29,7 @@ import glob
|
|||||||
import shutil
|
import shutil
|
||||||
import tempfile
|
import tempfile
|
||||||
import argparse
|
import argparse
|
||||||
|
import io
|
||||||
|
|
||||||
sys.path.insert(0, os.path.join(os.path.dirname(__file__), os.pardir))
|
sys.path.insert(0, os.path.join(os.path.dirname(__file__), os.pardir))
|
||||||
|
|
||||||
@ -76,6 +77,7 @@ class AsciiDoc:
|
|||||||
self._build_docs()
|
self._build_docs()
|
||||||
|
|
||||||
def _build_docs(self):
|
def _build_docs(self):
|
||||||
|
"""Build the documentation by rendering .asciidoc files to .html sites."""
|
||||||
files = self.FILES[:]
|
files = self.FILES[:]
|
||||||
for src in glob.glob('doc/help/*.asciidoc'):
|
for src in glob.glob('doc/help/*.asciidoc'):
|
||||||
name, _ext = os.path.splitext(os.path.basename(src))
|
name, _ext = os.path.splitext(os.path.basename(src))
|
||||||
@ -85,6 +87,7 @@ class AsciiDoc:
|
|||||||
self.call(src, dst)
|
self.call(src, dst)
|
||||||
|
|
||||||
def _build_website(self):
|
def _build_website(self):
|
||||||
|
"""Prepare and build the website."""
|
||||||
theme_file = os.path.abspath(os.path.join('www', 'qute.css'))
|
theme_file = os.path.abspath(os.path.join('www', 'qute.css'))
|
||||||
shutil.copy(theme_file, self._themedir)
|
shutil.copy(theme_file, self._themedir)
|
||||||
|
|
||||||
@ -110,35 +113,53 @@ class AsciiDoc:
|
|||||||
modified_src = os.path.join(self._tempdir, src_basename)
|
modified_src = os.path.join(self._tempdir, src_basename)
|
||||||
shutil.copy('www/header.asciidoc', modified_src)
|
shutil.copy('www/header.asciidoc', modified_src)
|
||||||
|
|
||||||
with open(modified_src, 'a', encoding='utf-8') as outfp:
|
outfp = io.StringIO()
|
||||||
with open(src, 'r', encoding='utf-8') as infp:
|
|
||||||
outfp.write('\n')
|
|
||||||
hidden = False
|
|
||||||
replaced_title = False
|
|
||||||
|
|
||||||
for line in infp:
|
with open(modified_src, 'r', encoding='utf-8') as header_file:
|
||||||
if line.strip() == '// QUTE_WEB_HIDE':
|
header = header_file.read()
|
||||||
assert not hidden
|
header += "\n\n"
|
||||||
hidden = True
|
|
||||||
elif line.strip() == '// QUTE_WEB_HIDE_END':
|
|
||||||
assert hidden
|
|
||||||
hidden = False
|
|
||||||
|
|
||||||
if not replaced_title:
|
with open(src, 'r', encoding='utf-8') as infp:
|
||||||
if re.match(r'^=+$', line):
|
outfp.write("\n\n")
|
||||||
line = line.replace('=', '-')
|
hidden = False
|
||||||
replaced_title = True
|
found_title = False
|
||||||
elif re.match(r'^= .+', line):
|
title = ""
|
||||||
line = '==' + line[1:]
|
last_line = ""
|
||||||
replaced_title = True
|
|
||||||
|
|
||||||
if not hidden:
|
for line in infp:
|
||||||
outfp.write(line)
|
if line.strip() == '// QUTE_WEB_HIDE':
|
||||||
|
assert not hidden
|
||||||
|
hidden = True
|
||||||
|
elif line.strip() == '// QUTE_WEB_HIDE_END':
|
||||||
|
assert hidden
|
||||||
|
hidden = False
|
||||||
|
|
||||||
|
if not found_title:
|
||||||
|
if re.match(r'^=+$', line):
|
||||||
|
line = line.replace('=', '-')
|
||||||
|
found_title = True
|
||||||
|
title = last_line + "=" * (len(last_line) - 1)
|
||||||
|
elif re.match(r'^= .+', line):
|
||||||
|
line = '==' + line[1:]
|
||||||
|
found_title = True
|
||||||
|
title = last_line + "=" * (len(last_line) - 1)
|
||||||
|
|
||||||
|
if not hidden:
|
||||||
|
outfp.write(line.replace(".asciidoc[", ".html["))
|
||||||
|
last_line = line
|
||||||
|
|
||||||
|
current_lines = outfp.getvalue()
|
||||||
|
outfp.close()
|
||||||
|
|
||||||
|
with open(modified_src, 'w+', encoding='utf-8') as final_version:
|
||||||
|
final_version.write(title + "\n\n" + header + current_lines)
|
||||||
|
|
||||||
self.call(modified_src, dst, '--theme=qute')
|
self.call(modified_src, dst, '--theme=qute')
|
||||||
|
|
||||||
for path in ['icons', 'doc/img']:
|
copy = {'icons': 'icons', 'doc/img': 'doc/img', 'www/media': 'media/'}
|
||||||
shutil.copytree(path, os.path.join(outdir, path))
|
|
||||||
|
for src, dest in copy.items():
|
||||||
|
shutil.copytree(src, os.path.join(outdir, dest))
|
||||||
|
|
||||||
os.symlink('README.html', os.path.join(outdir, 'index.html'))
|
os.symlink('README.html', os.path.join(outdir, 'index.html'))
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user