From 466e21399fb39acf100428362da875657db36c4e Mon Sep 17 00:00:00 2001 From: Matthieu Riegler Date: Fri, 30 Aug 2024 00:00:35 +0200 Subject: [PATCH] docs: api sub-entries should have `/` in urls. (#57593) `@angular/animations/browser` => `api/animations/browser/xyz` PR Close #57593 --- .../helpers/manifest.helper.spec.ts | 35 +++++++++++++++++++ .../references/helpers/manifest.helper.ts | 6 +++- 2 files changed, 40 insertions(+), 1 deletion(-) create mode 100644 adev/src/app/features/references/helpers/manifest.helper.spec.ts diff --git a/adev/src/app/features/references/helpers/manifest.helper.spec.ts b/adev/src/app/features/references/helpers/manifest.helper.spec.ts new file mode 100644 index 00000000000..958c33b87f6 --- /dev/null +++ b/adev/src/app/features/references/helpers/manifest.helper.spec.ts @@ -0,0 +1,35 @@ +/*! + * @license + * Copyright Google LLC All Rights Reserved. + * + * Use of this source code is governed by an MIT-style license that can be + * found in the LICENSE file at https://angular.dev/license + */ + +import {ApiManifestPackage} from '../interfaces/api-manifest'; +import {getApiUrl} from './manifest.helper'; + +describe('ManiferHelper', () => { + describe('getApiUrl', () => { + it('should return the correct URL for a given package and API name', () => { + const packageEntry: ApiManifestPackage = { + moduleName: '@angular/common', + moduleLabel: 'common', + normalizedModuleName: 'angular_common', + entries: [], + }; + const apiName = 'DatePipe'; + const result = getApiUrl(packageEntry, apiName); + expect(result).toBe('api/common/DatePipe'); + + const packageEntry2: ApiManifestPackage = { + moduleName: '@angular/animations/browser', + moduleLabel: 'animations/browser', + normalizedModuleName: 'angular_animations_browser', + entries: [], + }; + const result2 = getApiUrl(packageEntry2, apiName); + expect(result2).toBe('api/animations/browser/DatePipe'); + }); + }); +}); diff --git a/adev/src/app/features/references/helpers/manifest.helper.ts b/adev/src/app/features/references/helpers/manifest.helper.ts index 1cfcdf990e4..d13f70f79b9 100644 --- a/adev/src/app/features/references/helpers/manifest.helper.ts +++ b/adev/src/app/features/references/helpers/manifest.helper.ts @@ -58,7 +58,11 @@ export function getApiNavigationItems(): NavigationItem[] { } export function getApiUrl(packageEntry: ApiManifestPackage, apiName: string): string { - const packageName = packageEntry.normalizedModuleName.replace('angular_', ''); + const packageName = packageEntry.normalizedModuleName + // packages like `angular_core` should be `core` + // packages like `angular_animation_browser` should be `animation/browser` + .replace('angular_', '') + .replace('_', '/'); return `${PagePrefix.API}/${packageName}/${apiName}`; }