diff --git a/README.md b/README.md index c20051e..2909a11 100644 --- a/README.md +++ b/README.md @@ -18,7 +18,8 @@ - [By vendor](#by-vendor) - [By maintainer](#by-maintainer) - [Themes](#themes) - - [Add own themes](#add-own-themes) + - [Add own themes](#add-own-themes) +- [Skip Bundles](#skip-bundles) - [Caching](#caching) ## Top bundles @@ -64,5 +65,18 @@ To add your own themes, do the following: - Place your styles inside the theme file and export your theme - Create a pull request e.g. `feature/add-theme-{theme-name}` +## Skip Bundles +You can skip bundles you don't want to display +- How to use: + ```markdown + /api/packagist/card?vendor={your-packagist-user}&skip={bundle-name1, bundle-name2, ..} + ``` +- Example: + ```markdown + ![Packagist Top Bundles](https://github-readme-packagist-stats.vercel.app/api/packagist/card?vendor=agonyz&skip=contao-countdown-bundle,contao-pagespeed-insights-bundle) + ``` + ![Packagist Top Bundles](https://github-readme-packagist-stats.vercel.app/api/packagist/card?vendor=agonyz&skip=contao-countdown-bundle,contao-pagespeed-insights-bundle) + + ## Caching - In order to not overuse the packagist api a cache time of `12 hours` was implemented. \ No newline at end of file diff --git a/src/routes/routes.ts b/src/routes/routes.ts index de7e426..96270db 100644 --- a/src/routes/routes.ts +++ b/src/routes/routes.ts @@ -20,6 +20,7 @@ class MainRouter { const maintainer: string | null = (req.query.maintainer as string) ?? null; const theme: string | null = (req.query.theme as string) ?? null; + const skip: string | null = (req.query.skip as string) ?? null; // throw error if vendor is missing if (!vendor) { @@ -38,7 +39,8 @@ class MainRouter { const packagistData = await this.packagistService.getPackagistData( vendor, - maintainer + maintainer, + skip ); if (!packagistData) { diff --git a/src/services/bundle.service.ts b/src/services/bundle.service.ts new file mode 100644 index 0000000..7ae6c9d --- /dev/null +++ b/src/services/bundle.service.ts @@ -0,0 +1,25 @@ +import { PackagesByOrganization } from '@agonyz/packagist-api-client/lib/interfaces'; + +export class BundleService { + static skipBundles( + skip: string, + packages: PackagesByOrganization, + vendor: string + ): PackagesByOrganization | null { + const bundlesToSkip = new Set( + skip.split(',').map((bundle) => bundle.trim()) + ); + + packages.packageNames = packages.packageNames + .filter((bundle) => { + const bundleName = bundle.replace(vendor + '/', ''); + return !bundlesToSkip.has(bundleName); + }) + .map((bundle) => vendor + '/' + bundle.replace(vendor + '/', '')); + + if (packages.packageNames.length <= 0) { + return null; + } + return packages; + } +} diff --git a/src/services/packagist.service.ts b/src/services/packagist.service.ts index d5dc0bd..e8fcd9d 100644 --- a/src/services/packagist.service.ts +++ b/src/services/packagist.service.ts @@ -7,6 +7,7 @@ import { } from '@agonyz/packagist-api-client/lib/interfaces'; import { SortedPackage } from '../interfaces/packagist.interface'; import { LoggerService } from './logger.service'; +import { BundleService } from './bundle.service'; export class PackagistService { private client: PackagistApi; @@ -23,10 +24,12 @@ export class PackagistService { * * @param vendor * @param maintainer + * @param skip */ async getPackagistData( vendor: string, - maintainer: string | null + maintainer: string | null, + skip: string | null ): Promise { // get packages by vendor let packages; @@ -40,6 +43,14 @@ export class PackagistService { return null; } + // skip bundles if skip is set + if (skip) { + packages = BundleService.skipBundles(skip, packages, vendor); + if (!packages) { + return null; + } + } + // get maintainer top bundles if maintainer is set if (maintainer) { const maintainerBundles: Package[] | null =