Skip to content

Commit 4a3bdd5

Browse files
committed
refactor: unify configuration management across standards sites
- Replaced individual Docusaurus config files with centralized `docusaurus.config.factory.ts` for modular and consistent setup. - Added dynamic navbar and footer generation for ISBD, UNIMARC, ISBDM, LRM, and Muldicat using `SiteConfigBuilder`. - Resolved build-time caching contamination with environment-aware dynamic configuration. - Standardized introduction docs and removed redundant `DocsEnv` imports.
1 parent b484284 commit 4a3bdd5

19 files changed

+685
-570
lines changed

packages/preset-ifla/src/index.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,7 @@ const preset: IFLAPresetFunction = function (
3838
projectName = siteKey,
3939
env,
4040
vocabularyDefaults,
41-
customNavbarItems = [],
42-
navigation = {},
43-
footer = {},
41+
// customNavbarItems, navigation, footer - DEPRECATED: ignored, use docusaurus.config.factory.ts
4442
editUrl,
4543
// additionalPlugins = [], // TODO: implement when needed
4644
// redirects, // TODO: implement when needed
@@ -64,7 +62,7 @@ const preset: IFLAPresetFunction = function (
6462
// Merge vocabulary defaults with user overrides
6563
const mergedVocabularyDefaults = mergeVocabularyDefaults(vocabularyDefaults);
6664

67-
// Build base theme configuration (no navbar/footer - those are built in individual configs)
65+
// Build base theme configuration (no navbar/footer - those are built in individual site configs)
6866
const themeConfig = buildThemeConfig(
6967
prismTheme,
7068
prismDarkTheme,
@@ -182,4 +180,4 @@ export default preset;
182180
export { getSiteConfig } from './utils';
183181

184182
// Export types for consumer use
185-
export type { IFLAPresetOptions, IFLANavigationOptions, IFLAFooterOptions } from './types';
183+
export type { IFLAPresetOptions } from './types';

packages/preset-ifla/src/types.ts

Lines changed: 7 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -36,32 +36,8 @@ export interface VocabularyDefaults {
3636
};
3737
}
3838

39-
/**
40-
* Navigation options for the preset
41-
*/
42-
export interface IFLANavigationOptions {
43-
/** Hide the current site from the Standards dropdown */
44-
hideCurrentSiteFromStandardsDropdown?: boolean;
45-
/** Position of the Standards dropdown in navbar */
46-
standardsDropdownPosition?: 'left' | 'right';
47-
/** Whether to include the Resources dropdown */
48-
includeResourcesDropdown?: boolean;
49-
/** Whether to include the Documentation navbar item */
50-
includeDocumentationItem?: boolean;
51-
}
52-
53-
/**
54-
* Footer customization options
55-
*/
56-
export interface IFLAFooterOptions {
57-
/** Additional resource links to add to the footer */
58-
additionalResourceLinks?: Array<{
59-
label: string;
60-
href: string;
61-
}>;
62-
/** Hide default resource links (RDF Downloads, Sitemap) for sites that don't have them */
63-
hideDefaultResourceLinks?: boolean;
64-
}
39+
// NOTE: Navigation and footer options removed - these should be handled
40+
// in individual site configs using SiteConfigBuilder to prevent caching contamination
6541

6642
/**
6743
* Redirect configuration options
@@ -135,14 +111,14 @@ export interface IFLAPresetOptions {
135111
/** Vocabulary configuration overrides */
136112
vocabularyDefaults?: Partial<VocabularyDefaults>;
137113

138-
/** Custom navbar items to add (in addition to standard items) */
114+
/** Custom navbar items to add (in addition to standard items) - DEPRECATED: Use docusaurus.config.factory.ts */
139115
customNavbarItems?: NavbarItem[];
140116

141-
/** Navigation customization options */
142-
navigation?: IFLANavigationOptions;
117+
/** Navigation customization options - DEPRECATED: Use docusaurus.config.factory.ts */
118+
navigation?: Record<string, any>;
143119

144-
/** Footer customization options */
145-
footer?: IFLAFooterOptions;
120+
/** Footer customization options - DEPRECATED: Use docusaurus.config.factory.ts */
121+
footer?: Record<string, any>;
146122

147123
/** GitHub edit URL base */
148124
editUrl?: string;
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
import type { Config } from '@docusaurus/types';
2+
import preset, { getSiteConfig } from '../../packages/preset-ifla/dist/index.js';
3+
import navbarItems from './navbar';
4+
5+
// Get site URLs based on environment
6+
const { url, baseUrl, env } = getSiteConfig('FRBR');
7+
8+
const config: Config = {
9+
...preset(undefined as any, {
10+
siteKey: 'FRBR',
11+
title: 'IFLA FR Family of Models',
12+
tagline: 'Conceptual Models for Bibliographic Information',
13+
url,
14+
baseUrl,
15+
env,
16+
17+
// FRBR-specific vocabulary configuration
18+
vocabularyDefaults: {
19+
prefix: "ifla",
20+
numberPrefix: "T",
21+
profile: "vocabulary-profile.csv",
22+
elementDefaults: {
23+
uri: "https://www.iflastandards.info/elements",
24+
classPrefix: "class",
25+
propertyPrefix: "prop",
26+
profile: "elements-profile.csv",
27+
profileShapeId: "ElementShape",
28+
}
29+
},
30+
31+
// Custom navbar items
32+
customNavbarItems: navbarItems,
33+
34+
// Navigation customization
35+
navigation: {
36+
hideCurrentSiteFromStandardsDropdown: true,
37+
standardsDropdownPosition: 'right',
38+
includeResourcesDropdown: false,
39+
},
40+
41+
// GitHub configuration
42+
editUrl: 'https://github.com/iflastandards/FRBR/tree/main/',
43+
})
44+
};
45+
46+
export default config;
Lines changed: 2 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,2 @@
1-
import type { Config } from '@docusaurus/types';
2-
import preset, { getSiteConfig } from '../../packages/preset-ifla/dist/index.js';
3-
import navbarItems from './navbar';
4-
5-
// Get site URLs based on environment
6-
const { url, baseUrl, env } = getSiteConfig('FRBR');
7-
8-
const config: Config = {
9-
...preset(undefined as any, {
10-
siteKey: 'FRBR',
11-
title: 'IFLA FR Family of Models',
12-
tagline: 'Conceptual Models for Bibliographic Information',
13-
url,
14-
baseUrl,
15-
env,
16-
17-
// FRBR-specific vocabulary configuration
18-
vocabularyDefaults: {
19-
prefix: "ifla",
20-
numberPrefix: "T",
21-
profile: "vocabulary-profile.csv",
22-
elementDefaults: {
23-
uri: "https://www.iflastandards.info/elements",
24-
classPrefix: "class",
25-
propertyPrefix: "prop",
26-
profile: "elements-profile.csv",
27-
profileShapeId: "ElementShape",
28-
}
29-
},
30-
31-
// Custom navbar items
32-
customNavbarItems: navbarItems,
33-
34-
// Navigation customization
35-
navigation: {
36-
hideCurrentSiteFromStandardsDropdown: true,
37-
standardsDropdownPosition: 'right',
38-
includeResourcesDropdown: false,
39-
},
40-
41-
// GitHub configuration
42-
editUrl: 'https://github.com/iflastandards/FRBR/tree/main/',
43-
})
44-
};
45-
46-
export default config;
1+
// Import the factory configuration to prevent build-time caching contamination
2+
export { default } from './docusaurus.config.factory.js';

standards/ISBDM/docusaurus.config.factory.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import type { Config } from '@docusaurus/types';
22
import type { SidebarItemsGeneratorArgs, NormalizedSidebarItem } from '@docusaurus/plugin-content-docs/lib/sidebars/types';
33
import preset from '../../packages/preset-ifla/dist/index.js';
44
import { SiteConfigBuilder } from '../../packages/theme/dist/index.js';
5-
import { DocsEnv } from '../../packages/theme/dist/config/siteConfigCore.js';
65
import navbarItems from './navbar';
76

87
// Use the SiteConfigBuilder function to dynamically resolve configuration
Lines changed: 127 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,127 @@
1+
import type { Config } from '@docusaurus/types';
2+
import type { SidebarItemsGeneratorArgs, NormalizedSidebarItem } from '@docusaurus/plugin-content-docs/lib/sidebars/types';
3+
import preset, { getSiteConfig } from '../../packages/preset-ifla/dist/index.js';
4+
import navbarItems from './navbar';
5+
6+
// Get site URLs based on environment
7+
const { url, baseUrl, env } = getSiteConfig('ISBDM');
8+
9+
// Create a custom type that includes the undocumented `defaultSidebarItemsGenerator`
10+
type CustomSidebarItemsGeneratorArgs = SidebarItemsGeneratorArgs & {
11+
defaultSidebarItemsGenerator: (args: SidebarItemsGeneratorArgs) => Promise<NormalizedSidebarItem[]> | NormalizedSidebarItem[];
12+
};
13+
14+
// Custom sidebar generator for ISBDM
15+
const isbdmSidebarGenerator = async (generatorArgs: SidebarItemsGeneratorArgs) => {
16+
const { defaultSidebarItemsGenerator, ...args } = generatorArgs as CustomSidebarItemsGeneratorArgs;
17+
const sidebarItems: NormalizedSidebarItem[] = await defaultSidebarItemsGenerator(args);
18+
19+
function filterIndexMdx(items: NormalizedSidebarItem[]): NormalizedSidebarItem[] {
20+
return items
21+
.filter((item: NormalizedSidebarItem) => {
22+
if (item.type === 'doc') {
23+
const docId = item.id || (item as any).docId || '';
24+
if (docId === 'index' ||
25+
docId.endsWith('/index') ||
26+
docId.split('/').pop() === 'index') {
27+
return false;
28+
}
29+
}
30+
return true;
31+
})
32+
.map((item: NormalizedSidebarItem) => {
33+
if (item.type === 'category' && item.items) {
34+
return {
35+
...item,
36+
items: filterIndexMdx(item.items as NormalizedSidebarItem[]),
37+
};
38+
}
39+
return item;
40+
});
41+
}
42+
43+
return filterIndexMdx(sidebarItems);
44+
};
45+
46+
const config: Config = {
47+
...preset(undefined as any, {
48+
siteKey: 'ISBDM',
49+
title: 'ISBD for Manifestation',
50+
tagline: 'International Standard Bibliographic Description for Manifestation',
51+
url,
52+
baseUrl,
53+
env,
54+
55+
// ISBDM-specific vocabulary configuration
56+
vocabularyDefaults: {
57+
prefix: "isbdm",
58+
numberPrefix: "T",
59+
profile: "isbdm-values-profile-revised.csv",
60+
elementDefaults: {
61+
uri: "https://www.iflastandards.info/ISBDM/elements",
62+
classPrefix: "class",
63+
propertyPrefix: "prop",
64+
profile: "isbdm-elements-profile.csv",
65+
profileShapeId: "ElementShape",
66+
}
67+
},
68+
69+
// Custom navbar items
70+
customNavbarItems: navbarItems,
71+
72+
// Navigation customization
73+
navigation: {
74+
hideCurrentSiteFromStandardsDropdown: true,
75+
standardsDropdownPosition: 'right',
76+
includeResourcesDropdown: false,
77+
includeDocumentationItem: false, // ISBDM has custom navigation structure
78+
},
79+
80+
// Footer customization
81+
footer: {
82+
additionalResourceLinks: [],
83+
},
84+
85+
// Custom redirects for ISBDM
86+
redirects: {
87+
redirects: [],
88+
createRedirects: (existingPath: string) => {
89+
// Only process element paths - be very specific to avoid interfering with other routes
90+
// This regex specifically matches element paths with numeric IDs only
91+
const elementMatch = existingPath.match(/^\/docs\/(attributes|statements|notes|relationships)\/(\d+)$/);
92+
if (elementMatch) {
93+
const elementId = elementMatch[2];
94+
// Only create redirect if it's a valid numeric element ID
95+
if (/^\d+$/.test(elementId)) {
96+
return [`/docs/elements/${elementId}`];
97+
}
98+
}
99+
// Don't redirect anything else - this prevents interference with other routes
100+
return undefined;
101+
},
102+
},
103+
104+
// Use custom sidebar generator
105+
customSidebarGenerator: true,
106+
107+
// GitHub configuration
108+
editUrl: 'https://github.com/iflastandards/ISBDM/tree/main/',
109+
110+
// Override settings for ISBDM
111+
overrides: {
112+
onBrokenLinks: 'ignore', // Override: ignore generated element links
113+
onBrokenAnchors: 'ignore', // Override: ignore generated anchor links
114+
onBrokenMarkdownLinks: 'ignore', // Override: ignore generated markdown links
115+
}
116+
})
117+
};
118+
119+
// Apply custom sidebar generator to the config
120+
if (config.presets && config.presets[0] && Array.isArray(config.presets[0]) && config.presets[0][1]) {
121+
const presetOptions = config.presets[0][1] as any;
122+
if (presetOptions.docs) {
123+
presetOptions.docs.sidebarItemsGenerator = isbdmSidebarGenerator;
124+
}
125+
}
126+
127+
export default config;

0 commit comments

Comments
 (0)