Include cheatsheet images in offline help
Fixes #329. Note the png's are kind of outdated right now.
This commit is contained in:
parent
6631c6456c
commit
e3a8d00f27
BIN
doc/img/cheatsheet-big.png
Normal file
BIN
doc/img/cheatsheet-big.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 942 KiB |
BIN
doc/img/cheatsheet-small.png
Normal file
BIN
doc/img/cheatsheet-small.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 43 KiB |
@ -210,7 +210,10 @@ def qute_help(win_id, request):
|
|||||||
message.error(win_id, "Your documentation is outdated! Please re-run "
|
message.error(win_id, "Your documentation is outdated! Please re-run "
|
||||||
"scripts/asciidoc2html.py.")
|
"scripts/asciidoc2html.py.")
|
||||||
path = 'html/doc/{}'.format(urlpath)
|
path = 'html/doc/{}'.format(urlpath)
|
||||||
return utils.read_file(path).encode('UTF-8', errors='xmlcharrefreplace')
|
if urlpath.endswith('.png'):
|
||||||
|
return utils.read_file(path, binary=True)
|
||||||
|
else:
|
||||||
|
return utils.read_file(path).encode('UTF-8', errors='xmlcharrefreplace')
|
||||||
|
|
||||||
|
|
||||||
@add_handler('settings')
|
@add_handler('settings')
|
||||||
|
@ -76,6 +76,7 @@ class AsciiDoc:
|
|||||||
self._build_website()
|
self._build_website()
|
||||||
else:
|
else:
|
||||||
self._build_docs()
|
self._build_docs()
|
||||||
|
self._copy_images()
|
||||||
|
|
||||||
def _build_docs(self):
|
def _build_docs(self):
|
||||||
"""Render .asciidoc files to .html sites."""
|
"""Render .asciidoc files to .html sites."""
|
||||||
@ -84,8 +85,39 @@ class AsciiDoc:
|
|||||||
name, _ext = os.path.splitext(os.path.basename(src))
|
name, _ext = os.path.splitext(os.path.basename(src))
|
||||||
dst = 'qutebrowser/html/doc/{}.html'.format(name)
|
dst = 'qutebrowser/html/doc/{}.html'.format(name)
|
||||||
files.append((src, dst))
|
files.append((src, dst))
|
||||||
|
|
||||||
|
# patch image links to use local copy
|
||||||
|
modified_files = []
|
||||||
|
replacements = [
|
||||||
|
("http://qutebrowser.org/img/cheatsheet-big.png",
|
||||||
|
"qute://help/img/cheatsheet-big.png"),
|
||||||
|
("http://qutebrowser.org/img/cheatsheet-small.png",
|
||||||
|
"qute://help/img/cheatsheet-small.png")
|
||||||
|
]
|
||||||
|
|
||||||
for src, dst in files:
|
for src, dst in files:
|
||||||
self.call(src, dst)
|
src_basename = os.path.basename(src)
|
||||||
|
modified_src = os.path.join(self._tempdir, src_basename)
|
||||||
|
with open(modified_src, 'w', encoding='utf-8') as modified_f, \
|
||||||
|
open(src, 'r', encoding='utf-8') as f:
|
||||||
|
for line in f:
|
||||||
|
for orig, repl in replacements:
|
||||||
|
line = line.replace(orig, repl)
|
||||||
|
modified_f.write(line)
|
||||||
|
self.call(modified_src, dst)
|
||||||
|
|
||||||
|
def _copy_images(self):
|
||||||
|
"""Copy image files to qutebrowser/html/doc."""
|
||||||
|
print("Copying files...")
|
||||||
|
dst_path = os.path.join('qutebrowser', 'html', 'doc', 'img')
|
||||||
|
try:
|
||||||
|
os.mkdir(dst_path)
|
||||||
|
except FileExistsError:
|
||||||
|
pass
|
||||||
|
for filename in ['cheatsheet-big.png', 'cheatsheet-small.png']:
|
||||||
|
src = os.path.join('doc', 'img', filename)
|
||||||
|
dst = os.path.join(dst_path, filename)
|
||||||
|
shutil.copy(src, dst)
|
||||||
|
|
||||||
def _build_website_file(self, root, filename):
|
def _build_website_file(self, root, filename):
|
||||||
"""Build a single website file."""
|
"""Build a single website file."""
|
||||||
|
Loading…
Reference in New Issue
Block a user