aboutsummaryrefslogtreecommitdiff
path: root/blog/feed.py
diff options
context:
space:
mode:
authorBobby <[email protected]>2023-06-16 21:06:20 -0400
committerBobby <[email protected]>2023-06-16 21:06:20 -0400
commit3f58ec2e918d6dcdc1213c58caec2d1691c81d3d (patch)
tree3609454888405e60e65ac3755bbcd7da91da3593 /blog/feed.py
parent66af49f7d066320a409bbc3a305d67dc96c4e281 (diff)
downloadthatcomputerscientist-3f58ec2e918d6dcdc1213c58caec2d1691c81d3d.tar.xz
thatcomputerscientist-3f58ec2e918d6dcdc1213c58caec2d1691c81d3d.zip
Sending complete article in RSS
Diffstat (limited to 'blog/feed.py')
-rw-r--r--blog/feed.py51
1 files changed, 35 insertions, 16 deletions
diff --git a/blog/feed.py b/blog/feed.py
index 85788710..974f5e5a 100644
--- a/blog/feed.py
+++ b/blog/feed.py
@@ -1,37 +1,56 @@
+import re
+
+import requests
+# from .context_processors import add_excerpt
+from bs4 import BeautifulSoup
+from django.conf import settings
from django.contrib.syndication.views import Feed
from django.utils import feedgenerator
from django.utils.feedgenerator import Enclosure
-import requests
-from .context_processors import add_excerpt
+
from .models import Post
-from django.conf import settings
request_domain = settings.DEBUG and 'https://preview.thatcomputerscientist.com' or 'https://thatcomputerscientist.com'
+mathjax_path = f'{request_domain}/static/js/MathJax/MathJax.js?config=default'
+mathjax_config = '''
+<script type="text/x-mathjax-config">
+ MathJax.Hub.Config({
+ jax: ["input/TeX", "output/HTML-CSS"],
+ tex2jax: {
+ inlineMath: [['$','$'], ['\\(','\\)']],
+ processEscapes: true
+ },
+ "HTML-CSS": { availableFonts: ["TeX"] },
+ });
+</script>
+'''
class RSSFeed(Feed):
- title = 'That Computer Scientist - RSS Feed'
+ title = 'That Computer Scientist'
link = '/weblog/'
description = 'RSS Feed for That Computer Scientist Weblog'
feed_type = feedgenerator.Rss201rev2Feed
def items(self):
- unique_items = set()
- items = []
-
- for post in Post.objects.filter(is_public=True).order_by('-date'):
- if post.id not in unique_items:
- unique_items.add(post.id)
- items.append(post)
-
- return items
+ return Post.objects.all().order_by('-date')
def item_title(self, item):
return item.title
def item_description(self, item):
- post_excerpt = add_excerpt(item)
- return post_excerpt
-
+ r = requests.get(f'{request_domain}/weblog/{item.slug}')
+ soup = BeautifulSoup(r.text, 'html.parser')
+ article_body = soup.find(id='article-body')
+ for img in article_body.find_all('img'):
+ if not img.get('id'):
+ img['style'] = 'float: left; margin: 5px 11px 5px 0px; max-width: 710px;' + img.get('style', '')
+
+ article_body = str(article_body)
+ article_body = re.sub(r"[\x00-\x08\x0B-\x1F\x7F-\x9F]", "", str(article_body))
+ article_body += f'<script type="text/javascript" src="{mathjax_path}"></script>'
+ article_body += mathjax_config
+ return article_body
+
def item_link(self, item):
return f'{request_domain}/weblog/{item.slug}'