diff options
| author | Bobby <[email protected]> | 2023-06-16 21:06:20 -0400 |
|---|---|---|
| committer | Bobby <[email protected]> | 2023-06-16 21:06:20 -0400 |
| commit | 3f58ec2e918d6dcdc1213c58caec2d1691c81d3d (patch) | |
| tree | 3609454888405e60e65ac3755bbcd7da91da3593 /blog | |
| parent | 66af49f7d066320a409bbc3a305d67dc96c4e281 (diff) | |
| download | thatcomputerscientist-3f58ec2e918d6dcdc1213c58caec2d1691c81d3d.tar.xz thatcomputerscientist-3f58ec2e918d6dcdc1213c58caec2d1691c81d3d.zip | |
Sending complete article in RSS
Diffstat (limited to 'blog')
| -rw-r--r-- | blog/feed.py | 51 | ||||
| -rw-r--r-- | blog/urls.py | 2 |
2 files changed, 36 insertions, 17 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}' diff --git a/blog/urls.py b/blog/urls.py index f1fad34d..d62e7464 100644 --- a/blog/urls.py +++ b/blog/urls.py @@ -1,7 +1,7 @@ from django.urls import path -from .feed import RSSFeed from . import views +from .feed import RSSFeed app_name = 'blog' urlpatterns = [ |
