aboutsummaryrefslogtreecommitdiff
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
parent66af49f7d066320a409bbc3a305d67dc96c4e281 (diff)
downloadthatcomputerscientist-3f58ec2e918d6dcdc1213c58caec2d1691c81d3d.tar.xz
thatcomputerscientist-3f58ec2e918d6dcdc1213c58caec2d1691c81d3d.zip
Sending complete article in RSS
-rw-r--r--blog/feed.py51
-rw-r--r--blog/urls.py2
-rw-r--r--blog_admin/views.py5
-rw-r--r--middleware/translationMiddleware.py4
-rw-r--r--templates/blog/post.html2
5 files changed, 42 insertions, 22 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 = [
diff --git a/blog_admin/views.py b/blog_admin/views.py
index c552db05..e28f6429 100644
--- a/blog_admin/views.py
+++ b/blog_admin/views.py
@@ -2,10 +2,11 @@ import re
from datetime import datetime
from django.contrib import messages
+from django.core.paginator import Paginator
from django.http import HttpResponseRedirect
from django.shortcuts import redirect, render, reverse
-from django.core.paginator import Paginator
-from blog.models import Category, Post, Tag, Comment
+
+from blog.models import Category, Comment, Post, Tag
# Create your views here.
diff --git a/middleware/translationMiddleware.py b/middleware/translationMiddleware.py
index a67453d0..06373877 100644
--- a/middleware/translationMiddleware.py
+++ b/middleware/translationMiddleware.py
@@ -1,8 +1,8 @@
import os
-from bs4 import BeautifulSoup
-from django.http import HttpResponse
+from bs4 import BeautifulSoup
from django.conf import settings
+from django.http import HttpResponse
from google.cloud import translate_v2 as translate
cred_path = os.path.join(settings.BASE_DIR, 'credentials-translate.json')
diff --git a/templates/blog/post.html b/templates/blog/post.html
index 3949d929..8ecb1a29 100644
--- a/templates/blog/post.html
+++ b/templates/blog/post.html
@@ -49,7 +49,7 @@
<div id="article-body">
{{ post.first_paragraph | safe }}
- <img style="width: 100%; height: 473.3333px; max-height: 473.3333px; margin: 20px auto; display: block; border-radius: 8px;" src="{% url 'ignis:post_image' '710' post.id %}.gif" alt="Post Image for {{ post.title }}">
+ <img style="width: 100%; height: 473.3333px; max-height: 473.3333px; margin: 20px auto; display: block; border-radius: 8px;" src="{% url 'ignis:post_image' '710' post.id %}.gif" alt="Post Image for {{ post.title }}" id="arpi_">
<hr>
{{ post.body | safe }}
</div>