Fix minor script things.

This commit is contained in:
Niels G. W. Serup 2016-08-25 01:35:03 +02:00
parent cba5b8d2ae
commit 96de50de15
1 changed files with 12 additions and 12 deletions

View File

@ -23,14 +23,14 @@ def load_settings(settings_file):
in (line.split('=', 1) for line in in (line.split('=', 1) for line in
f.read().strip().split('\n'))} f.read().strip().split('\n'))}
return settings return settings
def load_media(media_file): def load_media(media_file):
with open(media_file) as f: with open(media_file) as f:
c = yaml.load(f) c = yaml.load(f)
c['year'] = int(c['year']) c['year'] = int(c['year'])
c['ident'] = ident(media_file) c['ident'] = ident(media_file)
return c return c
def ident(media_file): def ident(media_file):
return os.path.splitext(os.path.split(media_file)[1])[0] return os.path.splitext(os.path.split(media_file)[1])[0]
@ -43,9 +43,8 @@ def thumbnail_url(link):
def setup_directory_structure(settings, base_dir, template_dir): def setup_directory_structure(settings, base_dir, template_dir):
site_new_dir = os.path.join(base_dir, 'site-new') site_new_dir = os.path.join(base_dir, 'site-new')
os.mkdir(site_new_dir) os.mkdir(site_new_dir)
extern_dir = os.path.join(base_dir, 'extern')
extern_dir_site = os.path.join(site_new_dir, 'extern') extern_dir_site = os.path.join(site_new_dir, 'extern')
os.symlink(extern_dir, extern_dir_site) os.symlink(os.path.join('..', 'extern'), extern_dir_site)
style = read(os.path.join(template_dir, 'style.css')) style = read(os.path.join(template_dir, 'style.css'))
style_out = style.replace('{', '{{').replace('}', '}}') \ style_out = style.replace('{', '{{').replace('}', '}}') \
@ -62,7 +61,7 @@ def publish_new_site(site_dir, site_new_dir):
def generate_index_page(out_dir, base_html, section_html, medias): def generate_index_page(out_dir, base_html, section_html, medias):
sections = [generate_video_section_html(section_html, media) sections = [generate_video_section_html(section_html, media)
for media in medias] for media in medias]
all_sections = '\n'.join(sections) all_sections = '\n'.join(sections)
html_out = base_html.format(content=all_sections, html_out = base_html.format(content=all_sections,
style_url='style.css') style_url='style.css')
@ -83,19 +82,20 @@ def generate_video_section_html(section_html, media):
def extern_video(file_src): def extern_video(file_src):
url = '../extern/' + file_src url = '../extern/' + file_src
return '''\ return '''\
<video src="{file_src}" controls height="427"> <video src="{url}" controls height="427">
Your browser cannot play this video. You can download it here instead: Your browser cannot play this video. You can download it here instead:
<a href="{file_src}">{file_src}</a> <a href="{url}">{url}</a>
</video> </video>
'''.format(file_src=file_src) '''.format(url=url)
def youtube_video(file_src): def youtube_video(file_src):
yt_id = file_src
return '''\ return '''\
<iframe type="text/html" width="760" height="427" <iframe type="text/html" width="760" height="427"
src="https://www.youtube.com/embed/{file_src}?controls=2" src="https://www.youtube.com/embed/{yt_id}?controls=2"
allowfullscreen frameborder="0"> allowfullscreen frameborder="0">
</iframe> </iframe>
'''.format(file_src=file_src) '''.format(yt_id=yt_id)
def generate_video_page(base_dir, out_dir, base_html, showing_html, media): def generate_video_page(base_dir, out_dir, base_html, showing_html, media):
title = media['title'] title = media['title']
@ -115,7 +115,7 @@ def generate_video_page(base_dir, out_dir, base_html, showing_html, media):
'youtube': youtube_video 'youtube': youtube_video
} }
video_html = actions[file_type](file_src) video_html = actions[file_type](file_src)
html_inner = showing_html.format( html_inner = showing_html.format(
title=html.escape(title), title=html.escape(title),
year=str(year), year=str(year),
@ -151,7 +151,7 @@ def main():
media) media)
site_dir = os.path.join(base_dir, 'site') site_dir = os.path.join(base_dir, 'site')
publish_new_site(site_dir, site_new_dir) publish_new_site(site_dir, site_new_dir)
return 0 return 0
if __name__ == '__main__': if __name__ == '__main__':