|
1 | | -# shared-config |
| 1 | +# @ifla/shared-config |
2 | 2 |
|
3 | | -This library was generated with [Nx](https://nx.dev). |
| 3 | +A collection of pure configuration factory functions for Docusaurus sites in the IFLA Standards monorepo. This library provides environment-based configuration capabilities while maintaining Nx caching compatibility. |
| 4 | + |
| 5 | +## Overview |
| 6 | + |
| 7 | +This library provides factory functions that generate configuration objects for various aspects of Docusaurus sites: |
| 8 | +- Base configuration (title, URL, etc.) |
| 9 | +- Theme configuration (navbar, footer, etc.) |
| 10 | +- Plugin configuration (search, image optimization, etc.) |
| 11 | +- Preset configuration (classic preset options) |
| 12 | +- Environment utilities |
| 13 | + |
| 14 | +All functions are pure and take configuration options as input, returning configuration objects that can be used directly in `docusaurus.config.ts`. |
| 15 | + |
| 16 | +## Installation |
| 17 | + |
| 18 | +This library is internal to the monorepo and available via workspace reference: |
| 19 | + |
| 20 | +```json |
| 21 | +{ |
| 22 | + "dependencies": { |
| 23 | + "@ifla/shared-config": "workspace:*" |
| 24 | + } |
| 25 | +} |
| 26 | +``` |
| 27 | + |
| 28 | +## Usage |
| 29 | + |
| 30 | +### Environment-Based Configuration |
| 31 | + |
| 32 | +```typescript |
| 33 | +// docusaurus.config.ts |
| 34 | +import * as dotenv from 'dotenv'; |
| 35 | +import * as path from 'path'; |
| 36 | +import { createBaseConfig, createThemeConfig, createIFLAPlugins, getEnvironmentName, validateEnvConfig } from '@ifla/shared-config'; |
| 37 | + |
| 38 | +// Load environment variables |
| 39 | +const environment = getEnvironmentName(); |
| 40 | +const envFiles = ['.env', `.env.${environment}`, '.env.local']; |
| 41 | +for (const file of envFiles) { |
| 42 | + dotenv.config({ path: path.resolve(__dirname, file) }); |
| 43 | +} |
| 44 | + |
| 45 | +// Validate environment configuration |
| 46 | +const envConfig = validateEnvConfig(process.env, 'site-name'); |
| 47 | + |
| 48 | +// Create configuration |
| 49 | +const config = { |
| 50 | + ...createBaseConfig({ |
| 51 | + title: envConfig.SITE_TITLE, |
| 52 | + tagline: envConfig.SITE_TAGLINE, |
| 53 | + url: envConfig.SITE_URL, |
| 54 | + baseUrl: envConfig.SITE_BASE_URL, |
| 55 | + projectName: 'site-name', |
| 56 | + }), |
| 57 | + |
| 58 | + presets: [ |
| 59 | + [ |
| 60 | + 'classic', |
| 61 | + { |
| 62 | + docs: { /* ... */ }, |
| 63 | + blog: { /* ... */ }, |
| 64 | + theme: { /* ... */ }, |
| 65 | + }, |
| 66 | + ], |
| 67 | + ], |
| 68 | + |
| 69 | + plugins: [ |
| 70 | + ...createIFLAPlugins({ |
| 71 | + enableIdealImage: environment === 'production', |
| 72 | + enableLocalSearch: true, |
| 73 | + searchConfig: { |
| 74 | + indexBlog: true, |
| 75 | + language: ['en'], |
| 76 | + }, |
| 77 | + }), |
| 78 | + ], |
| 79 | + |
| 80 | + themeConfig: createThemeConfig({ |
| 81 | + navbarTitle: envConfig.SITE_TITLE, |
| 82 | + navbarItems: [ /* ... */ ], |
| 83 | + footerLinks: [ /* ... */ ], |
| 84 | + }), |
| 85 | +}; |
| 86 | +``` |
| 87 | + |
| 88 | +### Plugin Configuration |
| 89 | + |
| 90 | +The library provides flexible plugin configuration through `createIFLAPlugins`: |
| 91 | + |
| 92 | +```typescript |
| 93 | +// Development configuration |
| 94 | +const devPlugins = createIFLAPlugins({ |
| 95 | + enableIdealImage: false, // Disable for faster builds |
| 96 | + enableLocalSearch: false, // Disable in development |
| 97 | +}); |
| 98 | + |
| 99 | +// Production configuration |
| 100 | +const prodPlugins = createIFLAPlugins({ |
| 101 | + enableIdealImage: true, |
| 102 | + enableLocalSearch: true, |
| 103 | + imageConfig: { |
| 104 | + quality: 80, |
| 105 | + max: 1200, |
| 106 | + steps: 3, |
| 107 | + }, |
| 108 | + searchConfig: { |
| 109 | + hashed: true, |
| 110 | + indexBlog: true, |
| 111 | + language: ['en', 'fr'], |
| 112 | + }, |
| 113 | +}); |
| 114 | +``` |
| 115 | + |
| 116 | +### Environment Files |
| 117 | + |
| 118 | +Create environment files for different deployment targets: |
| 119 | + |
| 120 | +```bash |
| 121 | +# .env - Base configuration |
| 122 | +SITE_TITLE=My Site |
| 123 | +SITE_TAGLINE=Documentation |
| 124 | +GITHUB_REPO_URL=https://github.com/org/repo |
| 125 | + |
| 126 | +# .env.development |
| 127 | +SITE_URL=http://localhost:3000 |
| 128 | +SITE_BASE_URL=/ |
| 129 | + |
| 130 | +# .env.production |
| 131 | +SITE_URL=https://mysite.com |
| 132 | +SITE_BASE_URL=/docs/ |
| 133 | +``` |
| 134 | + |
| 135 | +## API Reference |
| 136 | + |
| 137 | +### Configuration Factories |
| 138 | + |
| 139 | +- `createBaseConfig(options)` - Creates base Docusaurus configuration |
| 140 | +- `createThemeConfig(options)` - Creates theme configuration |
| 141 | +- `createIFLAPlugins(options)` - Creates array of IFLA standard plugins |
| 142 | +- `createPluginConfig(options)` - Creates classic preset plugin configuration |
| 143 | + |
| 144 | +### Environment Utilities |
| 145 | + |
| 146 | +- `getEnvironmentName()` - Returns current environment name based on NODE_ENV |
| 147 | +- `validateEnvConfig(env, siteKey)` - Validates required environment variables |
| 148 | + |
| 149 | +### URL Utilities |
| 150 | + |
| 151 | +- `buildSiteUrl(envConfig, path)` - Builds complete URL from environment config |
| 152 | +- `getSiteUrl(url, baseUrl, path)` - Helper for URL construction |
| 153 | + |
| 154 | +## Migration from @ifla/preset-ifla |
| 155 | + |
| 156 | +Instead of using the preset: |
| 157 | + |
| 158 | +```typescript |
| 159 | +// Old approach |
| 160 | +presets: [ |
| 161 | + ['classic', { /* ... */ }], |
| 162 | + '@ifla/preset-ifla', |
| 163 | +], |
| 164 | +``` |
| 165 | + |
| 166 | +Use the plugin factory: |
| 167 | + |
| 168 | +```typescript |
| 169 | +// New approach |
| 170 | +presets: [ |
| 171 | + ['classic', { /* ... */ }], |
| 172 | +], |
| 173 | +plugins: [ |
| 174 | + ...createIFLAPlugins({ /* options */ }), |
| 175 | +], |
| 176 | +``` |
| 177 | + |
| 178 | +This provides more flexibility and better environment-based configuration. |
4 | 179 |
|
5 | 180 | ## Building |
6 | 181 |
|
|
0 commit comments