Commit 9da87d30 authored by gijs's avatar gijs
Browse files

- Added snippet for image to show title and caption.

- The generator now outputs to a temporary directory to avoid deleting the site when an error occurs in the generation process. Also a backup of the previous version is kept.
parent 90edf869
...@@ -84,7 +84,9 @@ def generate (): ...@@ -84,7 +84,9 @@ def generate ():
resetCollections(contentTypes) resetCollections(contentTypes)
basedir = os.path.join(settings.BASE_DIR, 'generator') basedir = os.path.join(settings.BASE_DIR, 'generator')
staticdir = os.path.join(basedir, 'templates', 'static') staticdir = os.path.join(basedir, 'templates', 'static')
outputdir = os.path.join(basedir, 'static', 'generated') backupdir = os.path.join(basedir, 'static', 'generated.old')
finaldir = os.path.join(basedir, 'static', 'generated')
outputdir = os.path.join(basedir, 'static', 'generated.new')
if os.path.exists(outputdir): if os.path.exists(outputdir):
shutil.rmtree(outputdir) shutil.rmtree(outputdir)
...@@ -236,6 +238,22 @@ def generate (): ...@@ -236,6 +238,22 @@ def generate ():
with open(os.path.join(outputdir, 'debug.html'), 'w', encoding='utf-8') as w: with open(os.path.join(outputdir, 'debug.html'), 'w', encoding='utf-8') as w:
w.write(make_index(models)) w.write(make_index(models))
info('Making backup of previous version, putting new version in place')
if os.path.exists(outputdir):
# Test whether there is an existing version of the site
if os.path.exists(finaldir):
# Removing old backup if it exists
if os.path.exists(backupdir):
shutil.rmtree(backupdir)
# Put new backup in place
shutil.move(finaldir, backupdir)
# Put new version of the site in place
shutil.move(outputdir, finaldir)
if not settings.DEBUG: if not settings.DEBUG:
print('Collecting static') print('Collecting static')
call_command('collectstatic', interactive=False) call_command('collectstatic', interactive=False)
......
...@@ -330,7 +330,8 @@ def includeAudio(audio, display_label): ...@@ -330,7 +330,8 @@ def includeAudio(audio, display_label):
return render_to_string('snippets/audio.html', { 'audio': audio }) return render_to_string('snippets/audio.html', { 'audio': audio })
def includeImage(image, display_label): def includeImage(image, display_label):
return '<img src="{}" />'.format(image.image) return render_to_string('snippets/image.html', { 'image': image })
# return '<img src="{}" />'.format(image.image)
def includeQuestion(question, display_label): def includeQuestion(question, display_label):
return render_to_string('snippets/question.html', { 'question': question }) return render_to_string('snippets/question.html', { 'question': question })
......
...@@ -48,10 +48,16 @@ def parse_pads (): ...@@ -48,10 +48,16 @@ def parse_pads ():
name, extension = os.path.splitext(pad.display_slug) name, extension = os.path.splitext(pad.display_slug)
padID = pad.publicpadid if pad.is_public else pad.group.groupID + '$' + urllib.parse.quote(pad.name.replace(settings.PAD_NAMESPACE_SEPARATOR, '_')) padID = pad.publicpadid if pad.is_public else pad.group.groupID + '$' + urllib.parse.quote(pad.name.replace(settings.PAD_NAMESPACE_SEPARATOR, '_'))
source = epclient.getText(padID)['text']
info('Reading {}'.format(pad.display_slug)) info('Reading {}'.format(pad.display_slug))
try:
source = epclient.getText(padID)['text']
except ValueError:
warn('Could not find pad {}'.format(pad.display_slug))
continue
if extension in ['.md', '.markdown']: if extension in ['.md', '.markdown']:
# source, collectedLinkTargets = resolveReferences(source, source=None) # source, collectedLinkTargets = resolveReferences(source, source=None)
......
<figure class="image">
{% if image.title %}
<h3>{{ image.title }}</h3>
{% endif %}
<img src="{{ image.image }}" />
{% if image.caption %}
<figcaption>
{{ image.caption }}
</figcaption>
{% endif %}
</figure>
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment