Compare commits

...

4 Commits

Author SHA1 Message Date
Bnyro 8bbaaca6fe
Merge 9e7823df67 into b07c0ae39f 2024-11-02 13:33:43 +08:00
Markus Heiser 9e7823df67 [WIP] <type> element isn't a part of the RSS 2.0 spec [1]
[1] https://cyber.harvard.edu/rss/rss.html

Signed-off-by: Markus Heiser <markus.heiser@darmarit.de>
2024-10-29 15:12:50 +01:00
Bnyro 6303c56c55 [feat] rss: add xsl style to view rss in browser 2024-10-19 16:55:09 +02:00
Bnyro 75b5813031 [chore] rss: rename from searx to SearXNG 2024-10-19 16:54:51 +02:00
4 changed files with 44 additions and 30 deletions

View File

@ -0,0 +1,39 @@
<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html" version="5" encoding="UTF-8" indent="yes" />
<xsl:template match="rss">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title><xsl:value-of select="channel/title" />RSS Feed</title>
<meta charset="UTF-8" />
<meta http-equiv="x-ua-compatible" content="IE=edge,chrome=1" />
<meta name="viewport" content="width=device-width,initial-scale=1" />
</head>
<body>
<header>
<h2>
<xsl:value-of select="channel/description" />
</h2>
</header>
<hr />
<main>
<xsl:for-each select="channel/item">
<article>
<h3>
<a hreflang="en" target="_blank">
<xsl:attribute name="href">
<xsl:value-of select="link" />
</xsl:attribute>
<xsl:value-of select="title" />
</a>
</h3>
<time><xsl:value-of select="pubDate" /></time>
<p><xsl:value-of select="description" /></p>
<hr />
</article>
</xsl:for-each>
</main>
</body>
</html>
</xsl:template>
</xsl:stylesheet>

View File

@ -1,11 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet href="{{ url_for('static', filename='xsl/rss.xsl') }}" type="text/xsl"?>
<rss version="2.0" <rss version="2.0"
xmlns:opensearch="http://a9.com/-/spec/opensearch/1.1/" xmlns:opensearch="http://a9.com/-/spec/opensearch/1.1/"
xmlns:atom="http://www.w3.org/2005/Atom"> xmlns:atom="http://www.w3.org/2005/Atom">
<channel> <channel>
<title>Searx search: {{ q|e }}</title> <title>SearXNG search: {{ q|e }}</title>
<link>{{ url_for('search', _external=True) }}?q={{ q|e }}</link> <link>{{ url_for('search', _external=True) }}?q={{ q|e }}</link>
<description>Search results for "{{ q|e }}" - searx</description> <description>Search results for "{{ q|e }}" - SearXNG</description>
<opensearch:totalResults>{{ number_of_results }}</opensearch:totalResults> <opensearch:totalResults>{{ number_of_results }}</opensearch:totalResults>
<opensearch:startIndex>1</opensearch:startIndex> <opensearch:startIndex>1</opensearch:startIndex>
<opensearch:itemsPerPage>{{ number_of_results }}</opensearch:itemsPerPage> <opensearch:itemsPerPage>{{ number_of_results }}</opensearch:itemsPerPage>
@ -20,34 +21,11 @@
{% for r in results %} {% for r in results %}
<item> <item>
<title>{{ r.title }}</title> <title>{{ r.title }}</title>
<type>result</type>
<link>{{ r.url }}</link> <link>{{ r.url }}</link>
<description>{{ r.content }}</description> <description>{{ r.content }}</description>
{% if r.pubdate %}<pubDate>{{ r.pubdate }}</pubDate>{% endif %} {% if r.pubdate %}<pubDate>{{ r.pubdate }}</pubDate>{% endif %}
</item> </item>
{% endfor %} {% endfor %}
{% if answers %}
{% for a in answers %}
<item>
<title>{{ a }}</title>
<type>answer</type>
</item>
{% endfor %}
{% endif %}
{% if corrections %}
{% for a in corrections %}
<item>
<title>{{ a }}</title>
<type>correction</type>
</item>
{% endfor %}
{% endif %}
{% if suggestions %}
{% for a in suggestions %}
<item>
<title>{{ a }}</title>
<type>suggestion</type>
</item>
{% endfor %}
{% endif %}
</channel> </channel>
</rss> </rss>

View File

@ -740,9 +740,6 @@ def search():
response_rss = render( response_rss = render(
'opensearch_response_rss.xml', 'opensearch_response_rss.xml',
results=results, results=results,
answers=result_container.answers,
corrections=result_container.corrections,
suggestions=result_container.suggestions,
q=request.form['q'], q=request.form['q'],
number_of_results=result_container.number_of_results, number_of_results=result_container.number_of_results,
) )

View File

@ -180,7 +180,7 @@ class ViewsTestCase(SearxTestCase): # pylint: disable=missing-class-docstring,
def test_search_rss(self): def test_search_rss(self):
result = self.app.post('/search', data={'q': 'test', 'format': 'rss'}) result = self.app.post('/search', data={'q': 'test', 'format': 'rss'})
self.assertIn(b'<description>Search results for "test" - searx</description>', result.data) self.assertIn(b'<description>Search results for "test" - SearXNG</description>', result.data)
self.assertIn(b'<opensearch:totalResults>3</opensearch:totalResults>', result.data) self.assertIn(b'<opensearch:totalResults>3</opensearch:totalResults>', result.data)