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 re
|
||||
import datetime
|
||||
import shutil
|
||||
|
||||
from docutils import nodes
|
||||
from docutils.parsers.rst import directives, Directive
|
||||
|
@ -43,10 +44,6 @@ def get_talk_names():
|
|||
]
|
||||
|
||||
|
||||
def warn(s):
|
||||
print('WARN:', s)
|
||||
|
||||
|
||||
@memoize
|
||||
def get_talk_data(talkname):
|
||||
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))
|
||||
data['text'] = ''
|
||||
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'] = int(data['duration'])
|
||||
if 'room' not in data:
|
||||
|
@ -78,6 +75,9 @@ def get_talk_data(talkname):
|
|||
else:
|
||||
logging.error("Talk <{}> has malformed `time`".format(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
|
||||
|
||||
|
||||
|
@ -93,12 +93,6 @@ class TalkListDirective(Directive):
|
|||
final_argument_whitespace = 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):
|
||||
tmpl = jinja_env.get_template('talk.html')
|
||||
return [
|
||||
|
@ -114,12 +108,18 @@ class TalksGenerator(generators.Generator):
|
|||
super(TalksGenerator, self).__init__(*args, **kwargs)
|
||||
|
||||
def generate_context(self):
|
||||
self.talks.append('sblindola')
|
||||
self.talks.append('tapioco')
|
||||
if os.path.isdir(self.settings['TALKS_PATH']):
|
||||
self.talks += os.listdir(self.settings['TALKS_PATH'])
|
||||
self.talks = {n: get_talk_data(n) for n in get_talk_names()}
|
||||
self._update_context(('talks',))
|
||||
|
||||
def generate_output(self, writer=None):
|
||||
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):
|
||||
pelican.settings.setdefault('TALKS_PATH', TALKS_PATH)
|
||||
|
@ -139,6 +139,6 @@ except ImportError:
|
|||
else:
|
||||
|
||||
def register():
|
||||
#signals.get_generators.connect(get_generators)
|
||||
signals.get_generators.connect(get_generators)
|
||||
signals.initialized.connect(add_talks_option_defaults)
|
||||
directives.register_directive('talklist', TalkListDirective)
|
||||
|
|
Loading…
Reference in a new issue