[mod] package.html template: additional links (a python dict)

- Closes: https://github.com/searxng/searxng/issues/3456
This commit is contained in:
Daniel Kukula 2024-05-06 07:33:24 +01:00 committed by Markus Heiser
parent 645a840d82
commit cc8b537e34
3 changed files with 21 additions and 10 deletions

View file

@ -563,3 +563,7 @@ type.
* - source_code_url * - source_code_url
- :py:class:`str` - :py:class:`str`
- the location of the project's source code - the location of the project's source code
* - links
- :py:class:`dict`
- additional links in the form of ``{'link_name': 'http://example.com'}``

View file

@ -33,23 +33,22 @@ def response(resp):
results = [] results = []
for package in resp.json(): for package in resp.json():
meta = package["meta"] meta = package["meta"]
publishedDate = package.get("inserted_at") published_date = package.get("updated_at")
if publishedDate: published_date = parser.parse(published_date)
publishedDate = parser.parse(publishedDate) links = meta.get("links")
tags = meta.get("licenses", [])
results.append( results.append(
{ {
"template": "packages.html", "template": "packages.html",
"url": package["url"], "url": package["html_url"],
"title": package["name"], "title": package["name"],
"package_name": package["name"], "package_name": package["name"],
"content": meta.get("description", ""), "content": meta.get("description", ""),
"version": meta.get("latest_version"), "version": meta.get("latest_version"),
"maintainer": ", ".join(meta.get("maintainers", [])), "maintainer": ", ".join(meta.get("maintainers", [])),
"publishedDate": publishedDate, "publishedDate": published_date,
"tags": tags, "license_name": ", ".join(meta.get("licenses", [])),
"homepage": meta.get("links", {}).get("homepage"), "homepage": package["docs_html_url"],
"source_code_url": meta.get("links", {}).get("github"), "links": links,
} }
) )

View file

@ -47,7 +47,7 @@
{%- endif -%} {%- endif -%}
</div> </div>
{%- endif -%} {%- endif -%}
{%- if result.homepage or result.source_code_url -%} {%- if result.homepage or result.source_code_url or result.links -%}
<div class="result_project">{{- '' -}} <div class="result_project">{{- '' -}}
<span>{{ _('Project') }}</span> <span>{{ _('Project') }}</span>
<span>{{- '' -}} <span>{{- '' -}}
@ -58,6 +58,14 @@
{%- if result.source_code_url -%} {%- if result.source_code_url -%}
<a href="{{ result.source_code_url }}" target="_blank">{{ _('Source code') }}</a> <a href="{{ result.source_code_url }}" target="_blank">{{ _('Source code') }}</a>
{%- endif -%} {%- endif -%}
{%- if result.links %}
{%- for name, link in result.links.items() -%}
{% if not loop.first or result.homepage or result.source_code_url %} | {% endif %}
<a href="{{ link }}" target="_blank">
{{- _(name) -}}
</a>
{%- endfor -%}
{%- endif -%}
</span>{{- '' -}} </span>{{- '' -}}
</div> </div>
{%- endif -%} {%- endif -%}