|
1 | | -import { defineConfig } from "vitepress"; |
| 1 | +import { readFileSync } from "fs"; |
| 2 | +import { resolve } from "path"; |
| 3 | +import { defineConfig, type HeadConfig } from "vitepress"; |
2 | 4 | import { tabsMarkdownPlugin } from "vitepress-plugin-tabs"; |
3 | 5 |
|
| 6 | +function loadEnvVar(key: string): string | undefined { |
| 7 | + // process.env takes precedence (CI/hosting platforms set vars here) |
| 8 | + if (key in process.env) return process.env[key] || undefined; |
| 9 | + // Fall back to .env file for local development |
| 10 | + try { |
| 11 | + const envFile = readFileSync(resolve(process.cwd(), ".env"), "utf-8"); |
| 12 | + const match = envFile.match(new RegExp(`^${key}=(.+)$`, "m")); |
| 13 | + return match?.[1]?.trim(); |
| 14 | + } catch { |
| 15 | + return undefined; |
| 16 | + } |
| 17 | +} |
| 18 | + |
| 19 | +const posthogKey = loadEnvVar("VITE_POSTHOG_KEY"); |
| 20 | +const algoliaAppId = loadEnvVar("VITE_ALGOLIA_APP_ID"); |
| 21 | +const algoliaApiKey = loadEnvVar("VITE_ALGOLIA_API_KEY"); |
| 22 | +const algoliaIndexName = loadEnvVar("VITE_ALGOLIA_INDEX_NAME"); |
| 23 | + |
| 24 | +const posthogHead: HeadConfig[] = posthogKey |
| 25 | + ? [ |
| 26 | + [ |
| 27 | + "script", |
| 28 | + {}, |
| 29 | + `!function(t,e){var o,n,p,r;e.__SV||(window.posthog=e,e._i=[],e.init=function(i,s,a){function g(t,e){var o=e.split(".");2==o.length&&(t=t[o[0]],e=o[1]),t[e]=function(){t.push([e].concat(Array.prototype.slice.call(arguments,0)))}}(p=t.createElement("script")).type="text/javascript",p.async=!0,p.src=s.api_host+"/static/array.js",(r=t.getElementsByTagName("script")[0]).parentNode.insertBefore(p,r);var u=e;for(void 0!==a?u=e[a]=[]:a="posthog",u.people=u.people||[],u.toString=function(t){var e="posthog";return"posthog"!==a&&(e+="."+a),t||(e+=" (stub)"),e},u.people.toString=function(){return u.toString(1)+".people (stub)"},o="capture identify alias people.set people.set_once set_config register register_once unregister opt_out_capturing has_opted_out_capturing opt_in_capturing reset isFeatureEnabled onFeatureFlags getFeatureFlag getFeatureFlagPayload reloadFeatureFlags group updateEarlyAccessFeatureEnrollment getEarlyAccessFeatures getActiveMatchingSurveys getSurveys onSessionId".split(" "),n=0;n<o.length;n++)g(u,o[n]);e._i.push([i,s,a])},e.__SV=1)}(document,window.posthog||[]); |
| 30 | + posthog.init('${posthogKey}', {api_host: 'https://us.i.posthog.com', person_profiles: 'identified_only'});`, |
| 31 | + ], |
| 32 | + ] |
| 33 | + : []; |
| 34 | + |
| 35 | +const searchConfig = |
| 36 | + algoliaAppId && algoliaApiKey && algoliaIndexName |
| 37 | + ? { |
| 38 | + provider: "algolia" as const, |
| 39 | + options: { |
| 40 | + appId: algoliaAppId, |
| 41 | + apiKey: algoliaApiKey, |
| 42 | + indexName: algoliaIndexName, |
| 43 | + insights: true, |
| 44 | + }, |
| 45 | + } |
| 46 | + : { provider: "local" as const }; |
| 47 | + |
4 | 48 | export default defineConfig({ |
5 | 49 | title: "Plane", |
6 | 50 | description: "Modern project management software", |
@@ -75,13 +119,8 @@ export default defineConfig({ |
75 | 119 | gtag('js', new Date()); |
76 | 120 | gtag('config', 'G-G578SD4VZD');`, |
77 | 121 | ], |
78 | | - // PostHog |
79 | | - [ |
80 | | - "script", |
81 | | - {}, |
82 | | - `!function(t,e){var o,n,p,r;e.__SV||(window.posthog=e,e._i=[],e.init=function(i,s,a){function g(t,e){var o=e.split(".");2==o.length&&(t=t[o[0]],e=o[1]),t[e]=function(){t.push([e].concat(Array.prototype.slice.call(arguments,0)))}}(p=t.createElement("script")).type="text/javascript",p.async=!0,p.src=s.api_host+"/static/array.js",(r=t.getElementsByTagName("script")[0]).parentNode.insertBefore(p,r);var u=e;for(void 0!==a?u=e[a]=[]:a="posthog",u.people=u.people||[],u.toString=function(t){var e="posthog";return"posthog"!==a&&(e+="."+a),t||(e+=" (stub)"),e},u.people.toString=function(){return u.toString(1)+".people (stub)"},o="capture identify alias people.set people.set_once set_config register register_once unregister opt_out_capturing has_opted_out_capturing opt_in_capturing reset isFeatureEnabled onFeatureFlags getFeatureFlag getFeatureFlagPayload reloadFeatureFlags group updateEarlyAccessFeatureEnrollment getEarlyAccessFeatures getActiveMatchingSurveys getSurveys onSessionId".split(" "),n=0;n<o.length;n++)g(u,o[n]);e._i.push([i,s,a])},e.__SV=1)}(document,window.posthog||[]); |
83 | | - posthog.init('phc_HskAKGRy7x0BEoWfyeHzYWWzcMmKG9DCail7ot7WQkA', {api_host: 'https://us.i.posthog.com', person_profiles: 'identified_only'});`, |
84 | | - ], |
| 122 | + // PostHog (conditionally injected) |
| 123 | + ...posthogHead, |
85 | 124 | [ |
86 | 125 | "script", |
87 | 126 | { |
@@ -153,14 +192,7 @@ export default defineConfig({ |
153 | 192 | label: "On this page", |
154 | 193 | }, |
155 | 194 |
|
156 | | - search: { |
157 | | - provider: "algolia", |
158 | | - options: { |
159 | | - appId: "AXICJJC8RP", |
160 | | - apiKey: "23df4157dee1d9a8d435cadd6cae3f26", |
161 | | - indexName: "plane-docs-v3", |
162 | | - }, |
163 | | - }, |
| 195 | + search: searchConfig, |
164 | 196 |
|
165 | 197 | socialLinks: [ |
166 | 198 | { icon: "github", link: "https://github.com/makeplane/plane" }, |
|
0 commit comments