mirror of
https://github.com/searxng/searxng.git
synced 2024-11-25 20:31:00 +00:00
engine npm use the packages.html template
This commit is contained in:
parent
6dd07b88a4
commit
42515d98f7
2 changed files with 70 additions and 19 deletions
67
searx/engines/npm.py
Normal file
67
searx/engines/npm.py
Normal file
|
@ -0,0 +1,67 @@
|
|||
# SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
# lint: pylint
|
||||
"""npms.io
|
||||
|
||||
"""
|
||||
|
||||
from urllib.parse import urlencode
|
||||
from dateutil import parser
|
||||
|
||||
|
||||
about = {
|
||||
"website": "https://npms.io/",
|
||||
"wikidata_id": "Q7067518",
|
||||
"official_api_documentation": "https://api-docs.npms.io/",
|
||||
"use_official_api": False,
|
||||
"require_api_key": False,
|
||||
"results": "JSON",
|
||||
}
|
||||
|
||||
categories = ['it', 'packages']
|
||||
|
||||
|
||||
# engine dependent config
|
||||
paging = True
|
||||
page_size = 25
|
||||
search_api = "https://api.npms.io/v2/search?"
|
||||
|
||||
|
||||
def request(query: str, params):
|
||||
|
||||
args = urlencode(
|
||||
{
|
||||
'from': (params["pageno"] - 1) * page_size,
|
||||
'q': query,
|
||||
'size': page_size,
|
||||
}
|
||||
)
|
||||
params['url'] = search_api + args
|
||||
return params
|
||||
|
||||
|
||||
def response(resp):
|
||||
results = []
|
||||
content = resp.json()
|
||||
for entry in content["results"]:
|
||||
package = entry["package"]
|
||||
publishedDate = package.get("date")
|
||||
if publishedDate:
|
||||
publishedDate = parser.parse(publishedDate)
|
||||
tags = list(entry.get("flags", {}).keys()) + package.get("keywords", [])
|
||||
results.append(
|
||||
{
|
||||
"template": "packages.html",
|
||||
"url": package["links"]["npm"],
|
||||
"title": package["name"],
|
||||
'package_name': package["name"],
|
||||
"content": package.get("description", ""),
|
||||
"version": package.get("version"),
|
||||
"maintainer": package.get("author", {}).get("name"),
|
||||
'publishedDate': publishedDate,
|
||||
"tags": tags,
|
||||
"homepage": package["links"].get("homepage"),
|
||||
"source_code_url": package["links"].get("repository"),
|
||||
}
|
||||
)
|
||||
|
||||
return results
|
|
@ -1191,26 +1191,10 @@ engines:
|
|||
disabled: true
|
||||
|
||||
- name: npm
|
||||
engine: json_engine
|
||||
paging: true
|
||||
first_page_num: 0
|
||||
search_url: https://api.npms.io/v2/search?q={query}&size=25&from={pageno}
|
||||
results_query: results
|
||||
url_query: package/links/npm
|
||||
title_query: package/name
|
||||
content_query: package/description
|
||||
page_size: 25
|
||||
categories: [it, packages]
|
||||
disabled: true
|
||||
timeout: 5.0
|
||||
engine: npm
|
||||
shortcut: npm
|
||||
about:
|
||||
website: https://npms.io/
|
||||
wikidata_id: Q7067518
|
||||
official_api_documentation: https://api-docs.npms.io/
|
||||
use_official_api: false
|
||||
require_api_key: false
|
||||
results: JSON
|
||||
timeout: 5.0
|
||||
disabled: true
|
||||
|
||||
- name: nyaa
|
||||
engine: nyaa
|
||||
|
|
Loading…
Reference in a new issue