fix: 🩹 website: use docusaurus context

Signed-off-by: jffarge <jf@dagger.io>
This commit is contained in:
jffarge 2022-03-30 16:48:24 +02:00
parent fca6968bff
commit 8c9621e137
4 changed files with 13 additions and 7 deletions

View File

@ -89,7 +89,7 @@ mdlint: # Markdown lint for web
.PHONY: web .PHONY: web
web: # Run the website locally web: # Run the website locally
yarn --cwd "./website" install yarn --cwd "./website" install
yarn --cwd "./website" dev yarn --cwd "./website" start
.PHONY: todo .PHONY: todo
todo: # Find all TODO items todo: # Find all TODO items

View File

@ -15,6 +15,9 @@ module.exports = {
stylesheets: [ stylesheets: [
"https://fonts.googleapis.com/css2?family=Karla&family=Montserrat:wght@700&display=swap", "https://fonts.googleapis.com/css2?family=Karla&family=Montserrat:wght@700&display=swap",
], ],
customFields: {
AMPLITUDE_ID: process.env.REACT_APP_AMPLITUDE_ID
},
themeConfig: { themeConfig: {
sidebarCollapsed: false, sidebarCollapsed: false,
prism: { prism: {

View File

@ -4,7 +4,6 @@
"private": true, "private": true,
"scripts": { "scripts": {
"docusaurus": "docusaurus", "docusaurus": "docusaurus",
"dev": "REACT_APP_AMPLITUDE_ID= docusaurus start",
"start": "docusaurus start", "start": "docusaurus start",
"build": "docusaurus build", "build": "docusaurus build",
"swizzle": "docusaurus swizzle", "swizzle": "docusaurus swizzle",

View File

@ -7,6 +7,7 @@
import React, {useState, useEffect, useCallback} from 'react'; import React, {useState, useEffect, useCallback} from 'react';
import {MDXProvider} from '@mdx-js/react'; import {MDXProvider} from '@mdx-js/react';
import renderRoutes from '@docusaurus/renderRoutes'; import renderRoutes from '@docusaurus/renderRoutes';
import useDocusaurusContext from '@docusaurus/useDocusaurusContext';
import Layout from '@theme/Layout'; import Layout from '@theme/Layout';
import DocSidebar from '@theme/DocSidebar'; import DocSidebar from '@theme/DocSidebar';
import MDXComponents from '@theme/MDXComponents'; import MDXComponents from '@theme/MDXComponents';
@ -139,11 +140,14 @@ function DocPage(props) {
); );
// DocPage Swizzle // DocPage Swizzle
const {siteConfig} = useDocusaurusContext();
useEffect(() => { useEffect(() => {
if(siteConfig.AMPLITUDE_ID) {
var instance1 = amplitude.getInstance().init(process.env.REACT_APP_AMPLITUDE_ID, null, { var instance1 = amplitude.getInstance().init(process.env.REACT_APP_AMPLITUDE_ID, null, {
apiEndpoint: `${window.location.hostname}/t` apiEndpoint: `${window.location.hostname}/t`
}) })
amplitude.getInstance().logEvent('Docs Viewed', { "hostname": window.location.hostname, "path": location.pathname }); amplitude.getInstance().logEvent('Docs Viewed', { "hostname": window.location.hostname, "path": location.pathname });
}
}, [location.pathname]) }, [location.pathname])
// End DocPageSwizzle // End DocPageSwizzle