Rafael Martins avatar Rafael Martins committed 9c0b7c7 Merge

merge with default

Comments (0)

Files changed (7)

blohg/__init__.py

     app.config.setdefault('ENABLE_PLUGINS', False)
     app.config.setdefault('OPENGRAPH', True)
     app.config.setdefault('TIMEZONE', 'UTC')
+    app.config.setdefault('RST_HEADER_LEVEL', 3)
 
     app.config['REPO_PATH'] = repo_path
 

blohg/hgapi/models.py

         return self.parsed_source.get('images', [])
 
     @locked_cached_property
+    def flash_videos(self):
+        return self.parsed_source.get('flash_videos', [])
+
+    @locked_cached_property
     def author_name(self):
         if 'name' in self.parsed_author:
             return self.parsed_author['name']

blohg/rst/__init__.py

 from docutils.core import publish_parts
 from docutils.parsers.rst.directives import register_directive
 from docutils.parsers.rst.roles import register_local_role
+from flask import current_app
 
 from blohg.rst.directives import index as directives_index
 from blohg.rst.roles import index as roles_index
 
 
 def parser(content):
+    settings = {'input_encoding': 'utf-8', 'output_encoding': 'utf-8',
+                'initial_header_level': current_app.config['RST_HEADER_LEVEL'],
+                'docinfo_xform': 0, 'field_name_limit': None}
     parts = publish_parts(source=content, writer=BlohgWriter(),
-                          settings_overrides={'input_encoding': 'utf-8',
-                                              'output_encoding': 'utf-8',
-                                              'initial_header_level': 3,
-                                              'docinfo_xform': 0,
-                                              'field_name_limit': None})
+                          settings_overrides=settings)
     return {'title': parts['title'], 'fragment': parts['fragment'],
             'first_paragraph_as_text': parts['first_paragraph_as_text'],
-            'images': parts['images']}
+            'images': parts['images'], 'flash_videos': parts['flash_videos']}

blohg/rst/directives.py

         'border': directives.length_or_unitless,
         'align': align,
         'allowfullscreen': boolean,
+        'opengraph': directives.flag,
     }
     has_content = False
 
     def run(self):
-        self.options['uri'] = 'http://www.youtube.com/embed/' \
-            + self.arguments[0]
+        self.options['uri'] = 'http://www.youtube.com/embed/%s' % \
+            self.arguments[0]
+        if 'opengraph' in self.options:
+            self.options['raw_uri'] = \
+                'http://www.youtube.com/v/%s?version=3&autohide=1' % \
+                self.arguments[0]
+            self.options['thumbnail_uri'] = \
+                'http://img.youtube.com/vi/%s/hqdefault.jpg' % \
+                self.arguments[0]
         self.options.setdefault('width', '425px')
         self.options.setdefault('height', '344px')
         self.options.setdefault('align', 'center')

blohg/rst/writer.py

         self.parts['first_paragraph_as_text'] = \
             self.visitor.first_paragraph_as_text
         self.parts['images'] = self.visitor.images
+        self.parts['flash_videos'] = self.visitor.flash_videos
 
 
 class BlohgHTMLTranslator(HTMLTranslator):
         HTMLTranslator.__init__(self, document)
         self.first_paragraph_as_text = None
         self.images = []
+        self.flash_videos = []
 
     def visit_iframe_flash_video(self, node):
+        if 'raw_uri' in node:
+            self.flash_videos.append(node['raw_uri'])
+        if 'thumbnail_uri' in node:
+            self.images.append(node['thumbnail_uri'])
         atts = dict(src=node['uri'])
         if 'width' in node:
             atts['width'] = node['width']
             atts['style'] = ' '.join(style)
         if 'align' in node:
             atts['class'] = 'align-%s' % node['align']
-        self.context.append('')
         self.body.append(self.starttag(node, 'iframe', '', **atts) + \
                          '</iframe>\n')
 
     def depart_iframe_flash_video(self, node):
-        self.body.append(self.context.pop())
+        pass
 
     def visit_paragraph(self, node):
         if self.first_paragraph_as_text is None:

blohg/templates/_posts.html

 
 {%- block opengraph_header %}
 {%- if config.OPENGRAPH %}
-<meta property="og:title" content="{% if meta and meta.title %}{{
-    meta.title }}{% else %}{{ config.TITLE }}{% endif %}" />
+<meta prefix="og: http://ogp.me/ns# article: http://ogp.me/ns/article#" />
+<meta property="og:site_name" content="{{ config.TITLE }}" />
+<meta property="og:url" content="{{ request.url }}" />
+<meta property="og:title" content="{{ config.TITLE }}{% if title %} » {{
+    title }}{% endif %}" />
 <meta property="og:description" content="{% if meta and meta.description %}{{
     meta.description }}{% elif tag %}Tag: {{ ' + '.join(tag) }}{% else %}{{
     config.TAGLINE }}{% endif %}" />
 {%- for image in meta.images %}
 <meta property="og:image" content="{{ image }}" />
 {%- endfor %}
+{%- for flash_video in meta.flash_videos %}
+<meta property="og:video" content="{{ flash_video }}" />
+<meta property="og:video:type" content="application/x-shockwave-flash">
+{%- endfor %}
 {%- endif %}
 {%- endif %}
 {%- endblock %}
     if slug.startswith('post'):
         title = u'Post: %s' % page.title
     return render_template('_posts.html', title=title, posts=[page],
-                           full_content=True,
-                           meta=dict(title=page.title,
-                                     description=page.description,
-                                     images=page.images))
+                           full_content=True, meta=page)
 
 
 @views.route('/')
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.