Skip to content
Snippets Groups Projects
Commit 876f30c7 authored by Martyn Welch's avatar Martyn Welch Committed by Emanuele Aina
Browse files

Convert image paths


The PDF generator can't find the images as the paths are relate to
where Hugo will place them on the website. Tweak the path to to point
to the images. We need to convert the SVG files into something the next
step can handle. Don't leave them in the static directory in case this
results in them being exported to the website.

Signed-off-by: default avatarMartyn Welch <martyn.welch@collabora.com>
parent cc0b699c
No related branches found
No related tags found
1 merge request!52Wip/martyn/t7270 tweak designs
......@@ -71,7 +71,7 @@ def update_local_links(elem, prefix):
link.attrib['href'] = '%s/%s' % (prefix, href)
def convert_svg_images(elem):
def convert_images(elem, imgdir):
imgs = elem.xpath('.//img')
for img in imgs:
src = img.attrib.get('src')
......@@ -85,13 +85,14 @@ def convert_svg_images(elem):
if not url_components.path:
continue # Local url, but doesn't need updating (eg #my-anchor)
if not url_components.path.endswith('.svg'):
continue
src = 'static' + os.path.abspath(src)
converted = src
converted = os.path.abspath(src) + '.pdf'
cmd = ['/usr/bin/rsvg-convert', src, '-f', 'pdf', '-o', converted]
if url_components.path.endswith('.svg'):
converted = imgdir + "/" + os.path.basename(src) + '.pdf'
cmd = ['/usr/bin/rsvg-convert', src, '-f', 'pdf', '-o', converted]
subprocess.check_call(cmd)
subprocess.check_call(cmd)
img.attrib['src'] = converted
......@@ -112,7 +113,9 @@ def transform(args):
if args.remote_prefix:
update_local_links(body, args.remote_prefix)
convert_svg_images(body)
inpath = os.path.dirname(args.input)
tmpdir_path = tempfile.mkdtemp(prefix=os.path.join(inpath, ''))
convert_images(body, tmpdir_path)
output.append('<!DOCTYPE html>')
output.append('<html lang="en">')
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment