Procházet zdrojové kódy

Added Image metadata attribute for article to specify a custom representative image.

Jesse Kershaw před 10 roky
rodič
revize
688136057b

+ 2 - 0
representative_image/Readme.md

@@ -2,6 +2,8 @@
 
 This plugin extracts a representative image (i.e, featured image) from the article's summary or article's content. The image can be access at `article.featured_image`. 
 
+To specify an image, set the Image metadata attribute in the content file.
+
 The plugin also remove any images from the summary after extraction to avoid duplication. 
 
 It allows the flexibility on where and how to display the featured image of an article together with its summary in a template page. For example, the article metadata can be displayed in thumbnail format, in which there is a short summary and an image. The layout of the summary and the image can be varied for aesthetical purpose. It doesn't have to depend on article's content format. 

+ 3 - 0
representative_image/representative_image.py

@@ -5,6 +5,9 @@ from bs4 import BeautifulSoup
 def images_extraction(instance):
     representativeImage = None
     if type(instance) == Article:
+        if 'image' in instance.metadata:
+            representativeImage = instance.metadata['image']
+
         # Process Summary:
         # If summary contains images, extract one to be the representativeImage and remove images from summary
         soup = BeautifulSoup(instance.summary, 'html.parser')