Add Atom and JSON feeds for releases and new packages

Fixes #224
This commit is contained in:
rubenwardy
2024-07-02 20:41:39 +01:00
parent e43a7827c2
commit f8abcaa7c6
7 changed files with 273 additions and 3 deletions

View File

@@ -20,9 +20,23 @@
<link rel="search" type="application/opensearchdescription+xml" href="/static/opensearch.xml" title="ContentDB" />
{% if noindex -%}
<meta name="robots" content="noindex">
<meta name="robots" content="noindex">
{%- endif %}
<link rel="alternate" type="application/json"
href="{{ abs_url_for('feeds.all_json') }}" title="{{ _('ContentDB all') }}">
<link rel="alternate" type="application/json"
href="{{ abs_url_for('feeds.packages_all_json') }}" title="{{ _('ContentDB new packages') }}">
<link rel="alternate" type="application/json"
href="{{ abs_url_for('feeds.releases_all_json') }}" title="{{ _('ContentDB package updates') }}">
<link rel="alternate" type="application/atom+xml"
href="{{ abs_url_for('feeds.all_atom') }}" title="{{ _('ContentDB all') }}">
<link rel="alternate" type="application/atom+xml"
href="{{ abs_url_for('feeds.packages_all_atom') }}" title="{{ _('ContentDB new packages') }}">
<link rel="alternate" type="application/atom+xml"
href="{{ abs_url_for('feeds.releases_all_atom') }}" title="{{ _('ContentDB package updates') }}">
{% block headextra %}{% endblock %}
</head>
<body>

View File

@@ -0,0 +1,39 @@
<?xml version="1.0" encoding="utf-8" ?>
<feed xmlns="http://www.w3.org/2005/Atom" xmlns:media="http://search.yahoo.com/mrss/">
<title>{{ feed["title"] }}</title>
<subtitle>{{ feed["description"] }}</subtitle>
<link href="{{ feed["feed_url"] }}" rel="self" />
<link href="{{ feed["home_page_url"] }}" />
<updated>{{ feed["items"][0]["date_published"] }}</updated>
<id>{{ feed["feed_url"] }}</id>
{% if feed["authors"] %}
<author>
<name>{{ feed["authors"][0]["name"] }}</name>
</author>
{% endif %}
{%- for post in feed["items"] %}
<entry>
<title>{{ post["title"] | escape }}</title>
<link href="{{ post["url"] }}" rel="alternate" type="text/html" title="{{ post["title"] | escape }}" />
<published>{{ post["date_published"] }}</published>
<updated>{{ post["date_published"] }}</updated>
<id>{{ post["url"] }}</id>
<summary type="text">
{{ post["summary"] | escape }}
</summary>
<content xml:lang="{{ post["language"] }}" type="html" xml:base="{{ post["url"] }}">
{{ post["content_html"] | escape }}
</content>
<author>
<name>{{ post["author"] }}</name>
</author>
{% for tag in post["tags"] %}
<category term="{{ tag | escape }}" />
{% endfor %}
{% if post["image"] %}
<media:thumbnail url="{{ post["image"] }}" />
<media:content medium="image" url="{{ post["image"] }}" />
{% endif %}
</entry>
{%- endfor %}
</feed>

View File

@@ -0,0 +1,45 @@
{% extends "packages/package_base.html" %}
{% block title %}
{{ package.title }}
{% endblock %}
{% block content %}
{% if package.check_perm(current_user, "MAKE_RELEASE") %}
<a href="{{ package.get_url('packages.edit_release', id=release.id) }}" class="btn btn-primary float-end">
{{ _("Edit") }}
</a>
{% endif %}
<h1>{{ self.title() }}</h1>
<p>
<a href="{{ package.get_url('packages.view') }}">
{{ _("%(title)s by %(author)s", title=package.title, author=package.author.display_name) }}
</a>
</p>
<p>
{{ _("Name") }}: {{ release.name }}<br>
{{ _("Title") }}: {{ release.title }}
</p>
{% if release.release_notes %}
<div class="markdown panel my-5">
{{ release.release_notes | markdown }}
</div>
{% endif %}
<p>
{{ _("URL") }}: <a href="{{ release.url }}">{{ release.url }}</a><br />
</p>
{% if release.commit_hash %}
<p>
{{ _("Commit Hash") }}: {{ release.commit_hash }}<br />
</p>
{% endif %}
{% if release.task_id %}
<p>
{{ _("Importing...") }}
<a href="{{ url_for('tasks.check', id=release.task_id, r=release.get_edit_url()) }}">{{ _("view task") }}</a><br />
</p>
{% endif %}
{% endblock %}

View File

@@ -16,6 +16,13 @@
{% if package.get_thumb_url(3, True, "png") -%}
<meta name="og:image" content="{{ package.get_thumb_url(3, True, "png") }}"/>
{%- endif %}
<link rel="alternate" type="application/json"
href="{{ package.get_url('feeds.releases_package_json', absolute=True) }}"
title="{{ _('%(title)s releases', title=package.title) }}">
<link rel="alternate" type="application/atom+xml"
href="{{ package.get_url('feeds.releases_package_atom', absolute=True) }}"
title="{{ _('%(title)s releases', title=package.title) }}">
{% endblock %}
{% block scriptextra %}