forked from boyska/sito-hackit-17
each talk can have a resource directory
This commit is contained in:
parent
f1b402769f
commit
6de17acfc0
1 changed files with 17 additions and 17 deletions
|
@ -9,6 +9,7 @@ from functools import wraps
|
||||||
import logging
|
import logging
|
||||||
import re
|
import re
|
||||||
import datetime
|
import datetime
|
||||||
|
import shutil
|
||||||
|
|
||||||
from docutils import nodes
|
from docutils import nodes
|
||||||
from docutils.parsers.rst import directives, Directive
|
from docutils.parsers.rst import directives, Directive
|
||||||
|
@ -43,10 +44,6 @@ def get_talk_names():
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
def warn(s):
|
|
||||||
print('WARN:', s)
|
|
||||||
|
|
||||||
|
|
||||||
@memoize
|
@memoize
|
||||||
def get_talk_data(talkname):
|
def get_talk_data(talkname):
|
||||||
fname = os.path.join(TALKS_PATH, talkname, 'meta.yaml')
|
fname = os.path.join(TALKS_PATH, talkname, 'meta.yaml')
|
||||||
|
@ -63,7 +60,7 @@ def get_talk_data(talkname):
|
||||||
logging.warn("Talk <{}> has no `text` field".format(talkname))
|
logging.warn("Talk <{}> has no `text` field".format(talkname))
|
||||||
data['text'] = ''
|
data['text'] = ''
|
||||||
if 'duration' not in data:
|
if 'duration' not in data:
|
||||||
logging.warn("Talk <{}> has no `duration` field".format(talkname))
|
logging.info("Talk <{}> has no `duration` field".format(talkname))
|
||||||
data['duration'] = 50
|
data['duration'] = 50
|
||||||
data['duration'] = int(data['duration'])
|
data['duration'] = int(data['duration'])
|
||||||
if 'room' not in data:
|
if 'room' not in data:
|
||||||
|
@ -78,6 +75,9 @@ def get_talk_data(talkname):
|
||||||
else:
|
else:
|
||||||
logging.error("Talk <{}> has malformed `time`".format(talkname))
|
logging.error("Talk <{}> has malformed `time`".format(talkname))
|
||||||
data['id'] = talkname
|
data['id'] = talkname
|
||||||
|
resdir = os.path.join(TALKS_PATH, talkname, 'res')
|
||||||
|
if os.path.isdir(resdir) and os.listdir(resdir):
|
||||||
|
data['resources'] = resdir
|
||||||
return data
|
return data
|
||||||
|
|
||||||
|
|
||||||
|
@ -93,12 +93,6 @@ class TalkListDirective(Directive):
|
||||||
final_argument_whitespace = True
|
final_argument_whitespace = True
|
||||||
has_content = True
|
has_content = True
|
||||||
|
|
||||||
# TODO: use a jinja template
|
|
||||||
tmpl = u'''<div id="talk-{t[id]}">
|
|
||||||
<h3 class="talk-title">{t[title]}</h3>
|
|
||||||
<div class="talk-description">{t[text]}</div>
|
|
||||||
</div>'''
|
|
||||||
|
|
||||||
def run(self):
|
def run(self):
|
||||||
tmpl = jinja_env.get_template('talk.html')
|
tmpl = jinja_env.get_template('talk.html')
|
||||||
return [
|
return [
|
||||||
|
@ -114,11 +108,17 @@ class TalksGenerator(generators.Generator):
|
||||||
super(TalksGenerator, self).__init__(*args, **kwargs)
|
super(TalksGenerator, self).__init__(*args, **kwargs)
|
||||||
|
|
||||||
def generate_context(self):
|
def generate_context(self):
|
||||||
self.talks.append('sblindola')
|
self.talks = {n: get_talk_data(n) for n in get_talk_names()}
|
||||||
self.talks.append('tapioco')
|
self._update_context(('talks',))
|
||||||
if os.path.isdir(self.settings['TALKS_PATH']):
|
|
||||||
self.talks += os.listdir(self.settings['TALKS_PATH'])
|
def generate_output(self, writer=None):
|
||||||
self._update_context(('talks', ))
|
for talkname in self.talks:
|
||||||
|
if 'resources' in self.talks[talkname]:
|
||||||
|
outdir = os.path.join(self.output_path, 'talks', talkname,
|
||||||
|
'res')
|
||||||
|
if os.path.isdir(outdir):
|
||||||
|
shutil.rmtree(outdir)
|
||||||
|
shutil.copytree(self.talks[talkname]['resources'], outdir)
|
||||||
|
|
||||||
|
|
||||||
def add_talks_option_defaults(pelican):
|
def add_talks_option_defaults(pelican):
|
||||||
|
@ -139,6 +139,6 @@ except ImportError:
|
||||||
else:
|
else:
|
||||||
|
|
||||||
def register():
|
def register():
|
||||||
#signals.get_generators.connect(get_generators)
|
signals.get_generators.connect(get_generators)
|
||||||
signals.initialized.connect(add_talks_option_defaults)
|
signals.initialized.connect(add_talks_option_defaults)
|
||||||
directives.register_directive('talklist', TalkListDirective)
|
directives.register_directive('talklist', TalkListDirective)
|
||||||
|
|
Loading…
Reference in a new issue