mirror of
https://github.com/pesde-pkg/pesde.git
synced 2025-05-04 10:33:47 +01:00
feat(website): versions page
This commit is contained in:
parent
71719dc03d
commit
bc5715e58b
3 changed files with 68 additions and 8 deletions
|
@ -1,7 +1,6 @@
|
|||
<script lang="ts">
|
||||
import { page } from "$app/stores"
|
||||
import type { Snippet } from "svelte"
|
||||
import type { PageData } from "./$types"
|
||||
|
||||
type Props = {
|
||||
tab: string
|
||||
|
@ -9,13 +8,15 @@
|
|||
}
|
||||
|
||||
const { tab, children }: Props = $props()
|
||||
const pkg = $derived(($page.data as PageData).pkg)
|
||||
|
||||
const shortBasePath = $derived(`/packages/${pkg.name}`)
|
||||
const fullBasePath = $derived(`${shortBasePath}/${pkg.version}/${pkg.targets[0].kind}`)
|
||||
|
||||
const isFullPath = $derived($page.url.pathname.startsWith(fullBasePath))
|
||||
const basePath = $derived(isFullPath ? fullBasePath : shortBasePath)
|
||||
const basePath = $derived.by(() => {
|
||||
const { scope, name } = $page.params
|
||||
if ("target" in $page.params) {
|
||||
const { version, target } = $page.params
|
||||
return `/packages/${scope}/${name}/${version}/${target}`
|
||||
}
|
||||
return `/packages/${scope}/${name}`
|
||||
})
|
||||
|
||||
const activeTab = $derived(
|
||||
$page.url.pathname.slice(basePath.length).replace(/^\//, "").replace(/\/$/, ""),
|
||||
|
|
|
@ -0,0 +1,29 @@
|
|||
import {
|
||||
fetchRegistryJson,
|
||||
RegistryHttpError,
|
||||
type PackageVersionsResponse,
|
||||
} from "$lib/registry-api"
|
||||
import { error } from "@sveltejs/kit"
|
||||
import type { PageServerLoad } from "./$types"
|
||||
|
||||
export const load: PageServerLoad = async ({ params, fetch }) => {
|
||||
const { scope, name } = params
|
||||
|
||||
try {
|
||||
const versions = await fetchRegistryJson<PackageVersionsResponse>(
|
||||
`packages/${encodeURIComponent(`${scope}/${name}`)}`,
|
||||
fetch,
|
||||
)
|
||||
|
||||
versions.reverse()
|
||||
|
||||
return {
|
||||
versions,
|
||||
}
|
||||
} catch (e) {
|
||||
if (e instanceof RegistryHttpError && e.response.status === 404) {
|
||||
error(404, "Package not found")
|
||||
}
|
||||
throw e
|
||||
}
|
||||
}
|
|
@ -1 +1,31 @@
|
|||
versions btw
|
||||
<script lang="ts">
|
||||
import { formatDistanceToNow } from "date-fns"
|
||||
|
||||
const { data } = $props()
|
||||
</script>
|
||||
|
||||
<div class="space-y-4 py-4">
|
||||
{#each data.versions as pkg}
|
||||
<article
|
||||
class="relative overflow-hidden rounded bg-card px-5 py-4 transition hover:bg-card-hover"
|
||||
>
|
||||
<h2 class="font-semibold text-heading">
|
||||
<a
|
||||
href={`/packages/${pkg.name}/${pkg.version}/any`}
|
||||
class="after:absolute after:inset-0 after:content-['']"
|
||||
>
|
||||
{pkg.version}
|
||||
</a>
|
||||
</h2>
|
||||
<div class="text-sm font-semibold">
|
||||
<time>{formatDistanceToNow(new Date(pkg.published_at), { addSuffix: true })}</time>
|
||||
·
|
||||
{pkg.targets
|
||||
.map((target) => {
|
||||
return target.kind[0].toUpperCase() + target.kind.slice(1)
|
||||
})
|
||||
.join(", ")}
|
||||
</div>
|
||||
</article>
|
||||
{/each}
|
||||
</div>
|
||||
|
|
Loading…
Add table
Reference in a new issue