Переглянути джерело

Merge pull request #509 from moorchegue/features/representative_image/expand_content_type

representative_image plugin: Let all kinds of pages use featured images
Justin Mayer 9 роки тому
батько
коміт
25aafb1f09
1 змінених файлів з 6 додано та 4 видалено
  1. 6 4
      representative_image/representative_image.py

+ 6 - 4
representative_image/representative_image.py

@@ -1,10 +1,11 @@
 from pelican import signals
-from pelican.contents import Content, Article
+from pelican.contents import Article, Draft, Page
 from bs4 import BeautifulSoup
 
+
 def images_extraction(instance):
     representativeImage = None
-    if type(instance) == Article:
+    if type(instance) in (Article, Draft, Page):
         if 'image' in instance.metadata:
             representativeImage = instance.metadata['image']
 
@@ -19,16 +20,17 @@ def images_extraction(instance):
         if len(images) > 0:
             # set _summary field which is based on metadata. summary field is only based on article's content and not settable
             instance._summary = unicode(soup)
-        
+
         # If there are no image in summary, look for it in the content body
         if not representativeImage:
             soup = BeautifulSoup(instance.content, 'html.parser')
             imageTag = soup.find('img')
             if imageTag:
                 representativeImage = imageTag['src']
-        
+
         # Set the attribute to content instance
         instance.featured_image = representativeImage
 
+
 def register():
     signals.content_object_init.connect(images_extraction)