Skip to content

Commit

Permalink
feat: add slug system
Browse files Browse the repository at this point in the history
  • Loading branch information
Julien-R44 committed Jan 26, 2024
1 parent 29dd900 commit 1c48e5f
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 6 deletions.
8 changes: 4 additions & 4 deletions app/services/packages_fetcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -169,11 +169,11 @@ export class PackagesFetcher {
/**
* Fetch a single package with its readme
*/
async fetchPackage(name: string) {
const pkg = this.packagesList.find((pkg_) => pkg_.name === name)
if (!pkg) throw new Error(`Cannot find package ${name}`)
async fetchPackage(slug: string) {
const pkg = this.packagesList.find((pkg_) => pkg_.slug === slug)
if (!pkg) throw new Error(`Cannot find package ${slug}`)

const stats = await PackageStats.findByOrFail('packageName', name)
const stats = await PackageStats.findByOrFail('packageName', pkg.name)
const readme = await this.#getPackageReadme(pkg)

return {
Expand Down
5 changes: 5 additions & 0 deletions providers/app_provider.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import edge from 'edge.js'
import { join } from 'node:path'
import { readFile } from 'node:fs/promises'
import slugify from '@sindresorhus/slugify'
import { getDirname } from '@poppinss/utils'
import type { ApplicationService } from '@adonisjs/core/types'

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

packagesFile.forEach((pkg: any) => {
pkg.slug = slugify(pkg.name)
})

this.app.container.singleton(PackageFetcher, () => new PackageFetcher())
this.app.container.bind(PackagesDataRefresher, async (resolver) => {
return new PackagesDataRefresher(await resolver.make(PackageFetcher), packagesFile)
Expand Down
2 changes: 1 addition & 1 deletion resources/pages/home/components/package_card.vue
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ const isV6Compatible = computed(() => props.package.compatibility?.adonis.includ
<template>
<Link
class="group card relative flex cursor-pointer gap-y-2 rounded-xl px-5 py-5"
:href="`/packages/${package.name}`"
:href="`/packages/${package.slug}`"
target="_blank"
>
<div class="w-full flex items-center justify-between">
Expand Down
2 changes: 1 addition & 1 deletion tests/functional/commands/add_package.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ test.group('[Commands] Add Package', (group) => {
compatibility: { adonis: '^5.0.0' },
firstReleaseAt: '2022-01-01',
lastReleaseAt: '2023-01-01',
type: 'community',
type: '3rd-party',
category: 'Database',
})
})
Expand Down
5 changes: 5 additions & 0 deletions types/packages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@ export type PackageInfo = {
*/
name: string

/**
* Slug of the package
*/
slug: string

/**
* Description of the package
* Displayed as subline on the website
Expand Down

0 comments on commit 1c48e5f

Please sign in to comment.