Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Documentation site (separate from cocoindex) - load posthog and mixpanel API key from env / repo secret keys instead of hardcoded #79

Merged
merged 2 commits into from
Mar 9, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .github/workflows/docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ jobs:
env:
USE_SSH: true
run: |
export COCOINDEX_DOCS_POSTHOG_API_KEY=${{ secrets.COCOINDEX_DOCS_POSTHOG_API_KEY }}
export COCOINDEX_DOCS_MIXPANEL_API_KEY=${{ secrets.COCOINDEX_DOCS_MIXPANEL_API_KEY }}
git config --global user.email "cocoindex.io@gmail.com"
git config --global user.name "CocoIndex"
yarn install --frozen-lockfile
Expand Down
32 changes: 24 additions & 8 deletions docs/docusaurus.config.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import webpack from 'webpack';
import { themes as prismThemes } from 'prism-react-renderer';
import type { Config } from '@docusaurus/types';
import type * as Preset from '@docusaurus/preset-classic';
Expand Down Expand Up @@ -33,14 +34,17 @@ const config: Config = {
},

plugins: [
[
"posthog-docusaurus",
{
apiKey: "phc_SgKiQafwZjHu4jQW2q402gbz6FYQ2NJRkcgooZMNNcy",
appUrl: "https://us.i.posthog.com",
enableInDevelopment: false,
},
],
() => ({
name: 'load-env-vars',
configureWebpack: () => ({
mergeStrategy: { plugins: "append", resolve: "merge" },
plugins: [
new webpack.DefinePlugin({
'process.env.COCOINDEX_DOCS_MIXPANEL_API_KEY': JSON.stringify(process.env.COCOINDEX_DOCS_MIXPANEL_API_KEY),
})
],
}),
}),
],

presets: [
Expand Down Expand Up @@ -147,4 +151,16 @@ const config: Config = {
} satisfies Preset.ThemeConfig,
};


if (!!process.env.COCOINDEX_DOCS_POSTHOG_API_KEY) {
config.plugins.push([
"posthog-docusaurus",
{
apiKey: process.env.COCOINDEX_DOCS_POSTHOG_API_KEY,
appUrl: "https://us.i.posthog.com",
enableInDevelopment: false,
},
]);
}

export default config;
7 changes: 4 additions & 3 deletions docs/src/theme/Root.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@ import React from 'react';
import mixpanel from 'mixpanel-browser';

// Default implementation, that you can customize
export default function Root({children}) {
export default function Root({ children }) {
React.useEffect(() => {
if (typeof window !== 'undefined') {
const mixpanelApiKey = process.env.COCOINDEX_DOCS_MIXPANEL_API_KEY;
if (typeof window !== 'undefined' && !!mixpanelApiKey) {
// Initialize Mixpanel with the token
mixpanel.init('46addeb6bedf8684a445aced6e67c76e', {
mixpanel.init(mixpanelApiKey, {
track_pageview: true,
debug: process.env.NODE_ENV === 'development'
});
Expand Down