Skip to content

Commit f0b5731

Browse files
jonphippsclaude
andcommitted
feat: implement high-impact shared config factories across all sites
- Create 5 new shared config factory functions to eliminate duplication: * createStandardsPresetConfig - standardizes preset configuration * createStandardsFooter - reduces footer config from 60+ lines to 5 lines * createVocabularyConfig - handles complex vocabulary settings * createStaticDirectories - manages shared static directories * createStandardsNavbar - standardizes navigation with flexible options - Apply environment-based configuration to all remaining sites: * Complete FRBR migration with full environment setup * Complete isbd migration with full environment setup * Complete muldicat migration with full environment setup * Complete unimarc migration with full environment setup - Update all sites (portal, ISBDM, LRM, FRBR, isbd, muldicat, unimarc) to use new factories - Achieve 17-25% code reduction across all docusaurus.config.ts files - Maintain site-specific customizations while maximizing code reuse - All sites now use consistent environment-based configuration pattern 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]>
1 parent 69e6af5 commit f0b5731

34 files changed

+1065
-941
lines changed

libs/shared-config/src/index.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,11 @@ export {
99
createProductionPlugins,
1010
type IFLAPluginOptions
1111
} from './lib/createPresetConfig';
12+
export * from './lib/createPresetConfigClassic';
13+
export * from './lib/createStandardsFooter';
14+
export * from './lib/createVocabularyConfig';
15+
export * from './lib/createStaticDirectories';
16+
export * from './lib/createStandardsNavbar';
1217
export * from './lib/utils/loadEnvConfig';
1318
export * from './lib/utils/getSiteUrl';
1419
export * from './lib/types';
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
2+
/**
3+
* Factory function to create classic preset configuration for standards sites
4+
* This is a pure function that returns consistent preset configuration
5+
*/
6+
export function createStandardsPresetConfig(options: {
7+
editUrl: string;
8+
enableBlog?: boolean;
9+
sidebarItemsGenerator?: any;
10+
docsPath?: string;
11+
showLastUpdateAuthor?: boolean;
12+
showLastUpdateTime?: boolean;
13+
}) {
14+
const {
15+
editUrl,
16+
enableBlog = true,
17+
sidebarItemsGenerator,
18+
docsPath = './docs',
19+
showLastUpdateAuthor = true,
20+
showLastUpdateTime = true,
21+
} = options;
22+
23+
return {
24+
docs: {
25+
path: docsPath,
26+
sidebarPath: './sidebars.ts',
27+
editUrl,
28+
showLastUpdateAuthor,
29+
showLastUpdateTime,
30+
remarkPlugins: [],
31+
...(sidebarItemsGenerator && { sidebarItemsGenerator }),
32+
},
33+
...(enableBlog && {
34+
blog: {
35+
showReadingTime: true,
36+
editUrl,
37+
}
38+
}),
39+
theme: {
40+
customCss: './src/css/custom.css',
41+
},
42+
};
43+
}
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
export interface StandardsFooterOptions {
2+
githubUrl: string;
3+
includeRdfDownloads?: boolean;
4+
includeSitemap?: boolean;
5+
customCopyright?: string;
6+
includeBlog?: boolean;
7+
}
8+
9+
/**
10+
* Factory function to create standardized footer for IFLA standards sites
11+
* This is a pure function that returns consistent footer configuration
12+
*/
13+
export function createStandardsFooter(options: StandardsFooterOptions) {
14+
const {
15+
githubUrl,
16+
includeRdfDownloads = true,
17+
includeSitemap = true,
18+
includeBlog = true,
19+
customCopyright,
20+
} = options;
21+
22+
const resourcesItems = [];
23+
if (includeRdfDownloads) {
24+
resourcesItems.push({
25+
label: 'RDF Downloads',
26+
to: '/rdf/',
27+
});
28+
}
29+
if (includeSitemap) {
30+
resourcesItems.push({
31+
label: 'Sitemap',
32+
to: '/sitemap',
33+
});
34+
}
35+
36+
const moreItems = [];
37+
if (includeBlog) {
38+
moreItems.push({
39+
label: 'Blog',
40+
to: '/blog',
41+
});
42+
}
43+
moreItems.push({
44+
label: 'GitHub',
45+
href: githubUrl,
46+
});
47+
48+
const footerLinks = [];
49+
50+
if (resourcesItems.length > 0) {
51+
footerLinks.push({
52+
title: 'Resources',
53+
items: resourcesItems,
54+
});
55+
}
56+
57+
footerLinks.push(
58+
{
59+
title: 'Community',
60+
items: [
61+
{
62+
label: 'IFLA Website',
63+
href: 'https://www.ifla.org/',
64+
},
65+
{
66+
label: 'IFLA Standards',
67+
href: 'https://www.ifla.org/programmes/ifla-standards/',
68+
},
69+
],
70+
},
71+
{
72+
title: 'More',
73+
items: moreItems,
74+
}
75+
);
76+
77+
return {
78+
style: 'dark' as const,
79+
links: footerLinks,
80+
copyright: customCopyright || `
81+
Copyright © ${new Date().getFullYear()} International Federation of Library Associations and Institutions (IFLA)<br />
82+
<a href="https://creativecommons.org/licenses/by/4.0/" target="_blank" rel="noopener noreferrer">
83+
<img src="img/cc0_by.png" alt="CC BY 4.0" style="vertical-align:middle; height:24px;" />
84+
</a>
85+
Gordon Dunsire and Mirna Willer (Main design and content editors).
86+
`,
87+
};
88+
}
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
export interface StandardsNavbarOptions {
2+
title: string;
3+
customItems?: any[];
4+
includeBlog?: boolean;
5+
includeVersionDropdown?: boolean;
6+
includeLocaleDropdown?: boolean;
7+
includeSearch?: boolean;
8+
}
9+
10+
/**
11+
* Factory function to create standardized navbar for IFLA standards sites
12+
* This is a pure function that returns consistent navbar configuration
13+
*/
14+
export function createStandardsNavbar(options: StandardsNavbarOptions) {
15+
const {
16+
title,
17+
customItems = [],
18+
includeBlog = true,
19+
includeVersionDropdown = true,
20+
includeLocaleDropdown = true,
21+
includeSearch = true,
22+
} = options;
23+
24+
const rightItems = [];
25+
26+
if (includeBlog) {
27+
rightItems.push({ to: '/blog', label: 'Blog', position: 'right' });
28+
}
29+
30+
if (includeVersionDropdown) {
31+
rightItems.push({
32+
type: 'docsVersionDropdown',
33+
position: 'right',
34+
});
35+
}
36+
37+
if (includeLocaleDropdown) {
38+
rightItems.push({
39+
type: 'localeDropdown',
40+
position: 'right',
41+
});
42+
}
43+
44+
if (includeSearch) {
45+
rightItems.push({
46+
type: 'search',
47+
position: 'right',
48+
});
49+
}
50+
51+
return [
52+
...customItems,
53+
...rightItems,
54+
];
55+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
/**
2+
* Factory function to create static directories configuration based on site type
3+
* This is a pure function that returns consistent static directory paths
4+
*/
5+
export function createStaticDirectories(siteType: 'portal' | 'standard'): string[] {
6+
const baseDirectories = ['static'];
7+
8+
if (siteType === 'portal') {
9+
// Portal is one level up from packages/theme
10+
return [...baseDirectories, '../packages/theme/static'];
11+
} else {
12+
// Standards are two levels up from packages/theme
13+
return [...baseDirectories, '../../packages/theme/static'];
14+
}
15+
}
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
export interface VocabularyConfigOptions {
2+
prefix: string;
3+
numberPrefix?: string;
4+
uriStyle?: string;
5+
profile?: string;
6+
elementUri?: string;
7+
elementProfile?: string;
8+
rdfLabelMappings?: {
9+
en?: string[];
10+
};
11+
rdfCommentMappings?: {
12+
en?: string[];
13+
};
14+
}
15+
16+
/**
17+
* Factory function to create vocabulary configuration for standards sites
18+
* This is a pure function that returns consistent vocabulary configuration
19+
*/
20+
export function createVocabularyConfig(options: VocabularyConfigOptions) {
21+
const {
22+
prefix,
23+
numberPrefix,
24+
uriStyle,
25+
profile,
26+
elementUri,
27+
elementProfile,
28+
rdfLabelMappings,
29+
rdfCommentMappings,
30+
} = options;
31+
32+
const vocabularyDefaults: any = {
33+
prefix,
34+
...(numberPrefix && { numberPrefix }),
35+
...(uriStyle && { uriStyle }),
36+
...(profile && { profile }),
37+
};
38+
39+
if (elementUri || elementProfile) {
40+
vocabularyDefaults.elementDefaults = {};
41+
if (elementUri) vocabularyDefaults.elementDefaults.uri = elementUri;
42+
if (elementProfile) vocabularyDefaults.elementDefaults.profile = elementProfile;
43+
}
44+
45+
if (rdfLabelMappings || rdfCommentMappings) {
46+
vocabularyDefaults.RDF = {};
47+
if (rdfLabelMappings) vocabularyDefaults.RDF.label = rdfLabelMappings;
48+
if (rdfCommentMappings) vocabularyDefaults.RDF.comment = rdfCommentMappings;
49+
}
50+
51+
return vocabularyDefaults;
52+
}

pnpm-lock.yaml

Lines changed: 72 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)