because I got bored of customising my CV for every job
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

fix(docs): fix environment variable interpolation in MDX

+48
+48
apps/docs/src/config/env.config.ts
··· 1 + /** 2 + * Environment variable configuration for documentation interpolation 3 + * 4 + * Add new variables here to make them available for interpolation in markdown files 5 + * Usage in markdown: {{VARIABLE_NAME}} 6 + * 7 + * Note: Uses process.env in Node.js context (Vite config/build time) and import.meta.env in client context 8 + */ 9 + const getEnvVar = (key: string, defaultValue: string): string => { 10 + // Check if we're in Node.js context (Vite config/build time) 11 + // This is the context where the remark plugin runs 12 + if (typeof process !== "undefined" && process.env?.[key]) { 13 + return process.env[key] ?? defaultValue; 14 + } 15 + // Check if we're in Vite client context (browser) 16 + // Use type assertion to avoid TypeScript errors when import.meta.env might not be available 17 + try { 18 + const metaEnv = (import.meta as { env?: Record<string, string> })?.env; 19 + if (metaEnv?.[key]) { 20 + return metaEnv[key] ?? defaultValue; 21 + } 22 + } catch { 23 + // import.meta not available in this context 24 + } 25 + return defaultValue; 26 + }; 27 + 28 + export const ENV_VARS: Record<string, string> = { 29 + CLIENT_URL: getEnvVar("VITE_CLIENT_URL", "http://localhost:5173"), 30 + SERVER_URL: getEnvVar("VITE_SERVER_URL", "http://localhost:3000"), 31 + DOCS_URL: getEnvVar("VITE_DOCS_URL", "http://localhost:3001"), 32 + GRAPHQL_URL: getEnvVar("VITE_GRAPHQL_URL", "http://localhost:3000/graphql"), 33 + DB_HOST: getEnvVar("VITE_DB_HOST", "localhost"), 34 + DB_PORT: getEnvVar("VITE_DB_PORT", "5432"), 35 + }; 36 + 37 + /** 38 + * Interpolates environment variables in markdown content 39 + * Replaces {{ENV_VAR_NAME}} with actual values from ENV_VARS 40 + * 41 + * @param content - Raw markdown content with placeholders 42 + * @returns Markdown content with interpolated values 43 + */ 44 + export const interpolateEnvVars = (content: string): string => { 45 + return content.replace(/\{\{(\w+)\}\}/g, (match, varName) => { 46 + return ENV_VARS[varName] ?? match; 47 + }); 48 + };