Skip to content

Commit 1c48e5f

Browse files
committed
feat: add slug system
1 parent 29dd900 commit 1c48e5f

File tree

5 files changed

+16
-6
lines changed

5 files changed

+16
-6
lines changed

app/services/packages_fetcher.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -169,11 +169,11 @@ export class PackagesFetcher {
169169
/**
170170
* Fetch a single package with its readme
171171
*/
172-
async fetchPackage(name: string) {
173-
const pkg = this.packagesList.find((pkg_) => pkg_.name === name)
174-
if (!pkg) throw new Error(`Cannot find package ${name}`)
172+
async fetchPackage(slug: string) {
173+
const pkg = this.packagesList.find((pkg_) => pkg_.slug === slug)
174+
if (!pkg) throw new Error(`Cannot find package ${slug}`)
175175

176-
const stats = await PackageStats.findByOrFail('packageName', name)
176+
const stats = await PackageStats.findByOrFail('packageName', pkg.name)
177177
const readme = await this.#getPackageReadme(pkg)
178178

179179
return {

providers/app_provider.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import edge from 'edge.js'
22
import { join } from 'node:path'
33
import { readFile } from 'node:fs/promises'
4+
import slugify from '@sindresorhus/slugify'
45
import { getDirname } from '@poppinss/utils'
56
import type { ApplicationService } from '@adonisjs/core/types'
67

@@ -18,6 +19,10 @@ export default class AppProvider {
1819
const packagesFilePath = join(getDirname(import.meta.url), '../content/build/packages.json')
1920
const packagesFile = JSON.parse(await readFile(packagesFilePath, 'utf-8'))
2021

22+
packagesFile.forEach((pkg: any) => {
23+
pkg.slug = slugify(pkg.name)
24+
})
25+
2126
this.app.container.singleton(PackageFetcher, () => new PackageFetcher())
2227
this.app.container.bind(PackagesDataRefresher, async (resolver) => {
2328
return new PackagesDataRefresher(await resolver.make(PackageFetcher), packagesFile)

resources/pages/home/components/package_card.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ const isV6Compatible = computed(() => props.package.compatibility?.adonis.includ
1818
<template>
1919
<Link
2020
class="group card relative flex cursor-pointer gap-y-2 rounded-xl px-5 py-5"
21-
:href="`/packages/${package.name}`"
21+
:href="`/packages/${package.slug}`"
2222
target="_blank"
2323
>
2424
<div class="w-full flex items-center justify-between">

tests/functional/commands/add_package.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ test.group('[Commands] Add Package', (group) => {
6262
compatibility: { adonis: '^5.0.0' },
6363
firstReleaseAt: '2022-01-01',
6464
lastReleaseAt: '2023-01-01',
65-
type: 'community',
65+
type: '3rd-party',
6666
category: 'Database',
6767
})
6868
})

types/packages.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,11 @@ export type PackageInfo = {
2424
*/
2525
name: string
2626

27+
/**
28+
* Slug of the package
29+
*/
30+
slug: string
31+
2732
/**
2833
* Description of the package
2934
* Displayed as subline on the website

0 commit comments

Comments
 (0)