summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--app/blog/models.py18
-rw-r--r--design/templates/details/entry.html3
2 files changed, 16 insertions, 5 deletions
diff --git a/app/blog/models.py b/app/blog/models.py
index 513ce05..fbbf1db 100644
--- a/app/blog/models.py
+++ b/app/blog/models.py
@@ -9,7 +9,7 @@ from django import forms
import markdown
from photos.models import PhotoGallery
from locations.models import Location
-
+from bs4 import BeautifulSoup
def get_upload_path(self, filename):
return "images/post-images/%s/%s" % (datetime.datetime.today().strftime("%Y"), filename)
@@ -19,10 +19,17 @@ def get_tn_path(self, filename):
return "images/post-thumbnail/%s/%s" % (datetime.datetime.today().strftime("%Y"), filename)
-def image_url_replace(str):
- str = str.replace('[[base_url]]', settings.IMAGES_URL)
- return str
+def image_url_replace(s):
+ s = s.replace('[[base_url]]', settings.IMAGES_URL)
+ return s
+def extract_images(s):
+ soup = BeautifulSoup(s)
+ imgs = []
+ for img in soup.find_all('img'):
+ print(img['src'])
+ imgs.append(img['src'])
+ return imgs
class PostImage(models.Model):
title = models.CharField(max_length=100)
@@ -110,6 +117,9 @@ class Entry(models.Model):
img = os.path.splitext(img)[0]
return '/media/images/home-images/hero%s_sm.jpg' % (img)
+ def get_images(self):
+ return extract_images(self.body_html)
+
@property
def state(self):
return self.location.state
diff --git a/design/templates/details/entry.html b/design/templates/details/entry.html
index ce71987..7982c29 100644
--- a/design/templates/details/entry.html
+++ b/design/templates/details/entry.html
@@ -18,7 +18,8 @@
<meta property="article:published_time" content="{{object.pub_date|date:'c'}}" />
<meta property="article:author" content="Luxagraf" />
<meta property="og:site_name" content="Luxagraf" />
- <meta property="og:image" content="{{object.get_image_url}}" />
+ <meta property="og:image" content="{{object.get_image_url}}" />{% for image in object.get_images %}
+ <meta property="og:image" content="{{image}}" />{% endfor %}
<meta property="og:locale" content="en_US" />
<meta name="twitter:card" content="summary_large_image"/>
<meta name="twitter:description" content="{{object.meta_description}}"/>