Skip to content

Commit 52163ae

Browse files
chore: replace values with env variables
1 parent fb4941d commit 52163ae

3 files changed

Lines changed: 53 additions & 16 deletions

File tree

.env.example

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
VITE_ALGOLIA_APP_ID=
2+
VITE_ALGOLIA_API_KEY=
3+
VITE_ALGOLIA_INDEX_NAME=
4+
VITE_POSTHOG_KEY=

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ docs/.vitepress/cache
1313

1414
# Misc
1515
.DS_Store
16+
.env
1617
.env.local
1718
.env.development.local
1819
.env.test.local

docs/.vitepress/config.ts

Lines changed: 48 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,50 @@
1-
import { defineConfig } from "vitepress";
1+
import { readFileSync } from "fs";
2+
import { resolve } from "path";
3+
import { defineConfig, type HeadConfig } from "vitepress";
24
import { tabsMarkdownPlugin } from "vitepress-plugin-tabs";
35

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+
448
export default defineConfig({
549
title: "Plane",
650
description: "Modern project management software",
@@ -75,13 +119,8 @@ export default defineConfig({
75119
gtag('js', new Date());
76120
gtag('config', 'G-G578SD4VZD');`,
77121
],
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,
85124
[
86125
"script",
87126
{
@@ -153,14 +192,7 @@ export default defineConfig({
153192
label: "On this page",
154193
},
155194

156-
search: {
157-
provider: "algolia",
158-
options: {
159-
appId: "AXICJJC8RP",
160-
apiKey: "23df4157dee1d9a8d435cadd6cae3f26",
161-
indexName: "plane-docs-v3",
162-
},
163-
},
195+
search: searchConfig,
164196

165197
socialLinks: [
166198
{ icon: "github", link: "https://github.com/makeplane/plane" },

0 commit comments

Comments
 (0)