mirror of
https://codeberg.org/rimu/pyfedi
synced 2025-01-23 19:36:56 -08:00
rss feeds with images in them
This commit is contained in:
parent
cf131a7039
commit
8da4cce68a
3 changed files with 18 additions and 2 deletions
|
@ -22,7 +22,7 @@ from app.community import bp
|
|||
from app.utils import get_setting, render_template, allowlist_html, markdown_to_html, validation_required, \
|
||||
shorten_string, gibberish, community_membership, ap_datetime, \
|
||||
request_etag_matches, return_304, instance_banned, can_create_post, can_upvote, can_downvote, user_filters_posts, \
|
||||
joined_communities, moderating_communities, blocked_domains
|
||||
joined_communities, moderating_communities, blocked_domains, mimetype_from_url
|
||||
from feedgen.feed import FeedGenerator
|
||||
from datetime import timezone, timedelta
|
||||
|
||||
|
@ -233,6 +233,10 @@ def show_community_rss(actor):
|
|||
fe = fg.add_entry()
|
||||
fe.title(post.title)
|
||||
fe.link(href=f"https://{current_app.config['SERVER_NAME']}/post/{post.id}")
|
||||
if post.url:
|
||||
type = mimetype_from_url(post.url)
|
||||
if type and not type.startswith('text/'):
|
||||
fe.enclosure(post.url, type=type)
|
||||
fe.description(post.body_html)
|
||||
fe.guid(post.profile_id(), permalink=True)
|
||||
fe.author(name=post.author.user_name)
|
||||
|
|
|
@ -15,7 +15,7 @@ from app.topic import bp
|
|||
from app import db, celery, cache
|
||||
from app.topic.forms import ChooseTopicsForm
|
||||
from app.utils import render_template, user_filters_posts, moderating_communities, joined_communities, \
|
||||
community_membership, blocked_domains, validation_required
|
||||
community_membership, blocked_domains, validation_required, mimetype_from_url
|
||||
|
||||
|
||||
@bp.route('/topic/<topic_name>', methods=['GET'])
|
||||
|
@ -113,6 +113,10 @@ def show_topic_rss(topic_name):
|
|||
fe = fg.add_entry()
|
||||
fe.title(post.title)
|
||||
fe.link(href=f"https://{current_app.config['SERVER_NAME']}/post/{post.id}")
|
||||
if post.url:
|
||||
type = mimetype_from_url(post.url)
|
||||
if type and not type.startswith('text/'):
|
||||
fe.enclosure(post.url, type=type)
|
||||
fe.description(post.body_html)
|
||||
fe.guid(post.profile_id(), permalink=True)
|
||||
fe.author(name=post.author.user_name)
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
from __future__ import annotations
|
||||
|
||||
import hashlib
|
||||
import mimetypes
|
||||
import random
|
||||
import urllib
|
||||
from collections import defaultdict
|
||||
|
@ -327,6 +328,13 @@ def ensure_directory_exists(directory):
|
|||
rebuild_directory += '/'
|
||||
|
||||
|
||||
def mimetype_from_url(url):
|
||||
parsed_url = urlparse(url)
|
||||
path = parsed_url.path.split('?')[0] # Strip off anything after '?'
|
||||
mime_type, _ = mimetypes.guess_type(path)
|
||||
return mime_type
|
||||
|
||||
|
||||
def validation_required(func):
|
||||
@wraps(func)
|
||||
def decorated_view(*args, **kwargs):
|
||||
|
|
Loading…
Reference in a new issue