Skip to content

Commit 38c45a2

Browse files
committed
Fix banner loading error handling and web config constants
1 parent f97c27d commit 38c45a2

File tree

4 files changed

+9
-3
lines changed

4 files changed

+9
-3
lines changed

src/generators/web/constants.mjs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { resolve, dirname } from 'node:path';
22
import { fileURLToPath } from 'node:url';
33

44
export const ROOT = dirname(fileURLToPath(import.meta.url));
5+
export const DEFAULT_REMOTE_CONFIG_URL = 'https://nodejs.org/site.json';
56

67
/**
78
* @typedef {Object} JSXImportConfig

src/generators/web/index.mjs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import { join } from 'node:path';
44

5+
import { DEFAULT_REMOTE_CONFIG_URL } from './constants.mjs';
56
import { GITHUB_EDIT_URL } from '../../utils/configuration/templates.mjs';
67
import { createLazyGenerator } from '../../utils/generators.mjs';
78

@@ -33,7 +34,7 @@ export default createLazyGenerator({
3334
title: '{project} v{version} Documentation',
3435
editURL: `${GITHUB_EDIT_URL}/doc/api{path}.md`,
3536
pageURL: '{baseURL}/latest-{version}/api{path}.html',
36-
remoteConfig: 'https://nodejs.org/site.json',
37+
remoteConfig: DEFAULT_REMOTE_CONFIG_URL,
3738
imports: {
3839
'#theme/Logo': '@node-core/ui-components/Common/NodejsLogo',
3940
'#theme/Navigation': join(import.meta.dirname, './ui/components/NavBar'),

src/generators/web/ui/components/AnnouncementBanner/__tests__/loadBanners.test.mjs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,9 @@ describe('loadBanners', () => {
2626
});
2727

2828
it('returns an empty array on non-ok response', async t => {
29+
const banner = { text: 'Global banner', type: 'warning' };
2930
t.mock.method(global, 'fetch', () =>
30-
Promise.resolve(makeResponse({}, false))
31+
Promise.resolve(makeResponse({ index: banner }, false))
3132
);
3233

3334
const result = await loadBanners('https://example.com/site.json', null);

src/generators/web/ui/components/AnnouncementBanner/loadBanners.mjs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { isBannerActive } from '../../utils/banner.mjs';
77
*
88
* @param {string | undefined} remoteConfig
99
* @param {number | null} versionMajor
10-
* @returns {Promise<import('./types.d.ts').BannerEntry[]>}
10+
* @returns {Promise<Array<import('./types.d.ts').BannerEntry>>}
1111
*/
1212
export const loadBanners = async (remoteConfig, versionMajor) => {
1313
if (!remoteConfig) {
@@ -16,6 +16,9 @@ export const loadBanners = async (remoteConfig, versionMajor) => {
1616

1717
try {
1818
const res = await fetch(remoteConfig);
19+
if (!res.ok) {
20+
return [];
21+
}
1922

2023
/** @type {import('./types.d.ts').RemoteConfig} */
2124
const { websiteBanners = {} } = await res.json();

0 commit comments

Comments
 (0)