1
0
Fork 0
mirror of https://github.com/YunoHost/apps.git synced 2024-09-03 20:06:07 +02:00

store: add rss for news

Co-authored-by: oleole39
This commit is contained in:
Alexandre Aubin 2024-05-11 18:42:04 +02:00
parent 0c330f0fd9
commit 3ff5a3d3a7
3 changed files with 63 additions and 2 deletions

View file

@ -11,6 +11,7 @@ import hmac
import string
import random
import urllib
from datetime import datetime
from slugify import slugify
from flask import (
Flask,
@ -19,6 +20,7 @@ from flask import (
session,
redirect,
request,
make_response,
)
from flask_babel import Babel
from flask_babel import gettext as _
@ -89,6 +91,13 @@ def days_ago(timestamp):
return int((time.time() - timestamp) / (60 * 60 * 24))
@app.template_filter("format_datetime")
def format_datetime(value, format="%d %b %Y %I:%M %p"):
if value is None:
return ""
return datetime.strptime(value, "%b %d %Y").strftime(format)
@app.context_processor
def utils():
d = {
@ -487,6 +496,22 @@ def charts():
)
@app.route("/news.rss")
def news_rss():
news_per_date = json.loads(open(".cache/news.json").read())
# Keepy only the last N entries
news_per_date = {d: infos for d, infos in reversed(list(news_per_date.items())[-2:])}
rss_xml = render_template('news_rss.xml', news_per_date=news_per_date, catalog=get_catalog())
response = make_response(rss_xml)
response.headers['Content-Type'] = 'application/rss+xml'
response.headers['Content-Disposition'] = "inline; filename=news_rss.xml"
return response
###############################################################################
# Session / SSO using Discourse #
###############################################################################

View file

@ -10,8 +10,13 @@
<div id="levelHistory" class="h-80"></div>
</div>
<div class="mx-auto w-80">
<h1 class="text-center font-medium text-2xl py-2">{{ _("History") }}</h1>
<div class="mx-auto w-80 py-2">
<h1 class="text-center font-medium text-2xl pt-4">
{{ _("History") }}
<link rel="alternate" type="application/rss+xml" title="YunoHost apps catalog news" href="{{ url_for('news_rss')}}" />
<a href="{{ url_for('news_rss')}}" class="btn btn-sm h-6 bg-orange-500 text-white !font-bold align-middle !px-2 !py-1"><i class="fa fa-rss-square" aria-hidden="true"></i> Suscribe via RSS</a>
</h1>
<div>
{% for date, news in news_per_date.items()|reverse %}
<h2 class="text-center font-medium text-xl py-4">{{ date }}</h2>

View file

@ -0,0 +1,31 @@
<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
xmlns:content="http://purl.org/rss/1.0/modules/content/"
xmlns:wfw="http://wellformedweb.org/CommentAPI/"
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:atom="http://www.w3.org/2005/Atom"
xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
>
<channel>
<title>YunoHost apps catalog News</title>
<link>{{ url_for('news_rss')}}</link>
<atom:link href="{{ url_for('news_rss')}}" rel="self" type="application/rss+xml" />
<description>YunoHost apps catalog news</description>
{%- for date, news in news_per_date.items() %}
{%- for status in ("added", "repaired", "broke", "removed") %}i
{%- for app, url in news[status] %}
{% set manifest = catalog["apps"][app]["manifest"] %}
<item>
<title>[{{ status|capitalize }}] {{ manifest['name'] }}</title>
<link>{{ url_for('app_info', app_id=app) }}</link>
<guid>{{ app }}#{{ date|format_datetime("%Y%m%d") }}</guid>
<pubDate>{{ date|format_datetime("%a, %d %b %Y %H:%M:%S +0000") }}</pubDate>
<description>{{ manifest["description"].get("en") }}</description>
<content:encoded>{{ manifest["description"].get("en") }}</content:encoded>
</item>
{% endfor -%}
{% endfor -%}
{% endfor %}
</channel>
</rss>