diff --git a/docs/getting_started.rst b/docs/getting_started.rst index 383acdc4..39007b8e 100644 --- a/docs/getting_started.rst +++ b/docs/getting_started.rst @@ -390,6 +390,23 @@ following to ``pelicanconf.py``:: And then the ``pdfs`` directory would also be copied to ``output/static/``. +Adding videos from YouTube or Vimeo to your content +--------------------------------------------------- + +You can easily embed videos from YouTube or Vimeo using the relevant directives, +each directive requires a video ID and you can optionally specify a width, height +and alignment:: + + .. youtube:: VIDEO_ID + :width: 640 + :height: 480 + :align: center + + .. vimeo:: VIDEO_ID + :width: 640 + :height: 480 + :align: center + Importing an existing blog -------------------------- diff --git a/pelican/rstdirectives.py b/pelican/rstdirectives.py index fb4a6c93..8c2606a7 100644 --- a/pelican/rstdirectives.py +++ b/pelican/rstdirectives.py @@ -98,6 +98,65 @@ class YouTube(Directive): directives.register_directive('youtube', YouTube) + +class Vimeo(Directive): + """ Embed Vimeo video in posts. + + Based on the YouTube directive by Brian Hsu: https://gist.github.com/1422773 + + VIDEO_ID is required, with / height are optional integer, + and align could be left / center / right. + + Usage: + .. vimeo:: VIDEO_ID + :width: 640 + :height: 480 + :align: center + """ + + def align(argument): + """Conversion function for the "align" option.""" + return directives.choice(argument, ('left', 'center', 'right')) + + required_arguments = 1 + optional_arguments = 2 + option_spec = { + 'width': directives.positive_int, + 'height': directives.positive_int, + 'align': align + } + + final_argument_whitespace = False + has_content = False + + def run(self): + videoID = self.arguments[0].strip() + width = 420 + height = 315 + align = 'left' + + if 'width' in self.options: + width = self.options['width'] + + if 'height' in self.options: + height = self.options['height'] + + if 'align' in self.options: + align = self.options['align'] + + url = 'http://player.vimeo.com/video/%s' % videoID + div_block = '