mirror of
https://github.com/pesde-pkg/pesde.git
synced 2025-05-04 10:33:47 +01:00
31 lines
754 B
TypeScript
31 lines
754 B
TypeScript
import { fetchRegistryJson, type SearchResponse } from "$lib/registry-api"
|
|
import type { PageLoad } from "./$types"
|
|
|
|
const PAGE_SIZE = 50
|
|
|
|
export const load: PageLoad = async ({ fetch, url }) => {
|
|
const query = url.searchParams.get("q") ?? ""
|
|
|
|
let page = parseInt(url.searchParams.get("page") ?? "1")
|
|
if (isNaN(page) || page < 1) {
|
|
page = 1
|
|
}
|
|
|
|
const params = new URLSearchParams()
|
|
params.set("query", query)
|
|
params.set("offset", String((page - 1) * PAGE_SIZE))
|
|
|
|
const result = fetchRegistryJson<SearchResponse>(`search?${params}`, fetch)
|
|
|
|
return {
|
|
query,
|
|
page,
|
|
pageSize: PAGE_SIZE,
|
|
result,
|
|
|
|
meta: {
|
|
title: query === "" ? "search" : `results for "${query}"`,
|
|
description: "Search for packages in the pesde registry.",
|
|
},
|
|
}
|
|
}
|