Skip to content

Commit c366bc0

Browse files
Add darkmode support, add analytics
1 parent 7022d6b commit c366bc0

File tree

7 files changed

+58
-30
lines changed

7 files changed

+58
-30
lines changed

src/components/LLMButtons/CopyForLLM/index.tsx

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import useBaseUrl from '@docusaurus/useBaseUrl';
21
import React, { useState } from 'react';
32

43
import styles from '../styles.module.css';
@@ -15,11 +14,18 @@ function ButtonText({ isLoading, isCopied }: { isLoading: boolean; isCopied: boo
1514
}
1615

1716
export default function CopyForLLM() {
18-
const copyIcon = useBaseUrl('/img/copy.svg');
1917
const [isLoading, setIsLoading] = useState(false);
2018
const [isCopied, setIsCopied] = useState(false);
2119

2220
const handleCopy = async () => {
21+
if ((window as any).analytics) {
22+
(window as any).analytics.track('Clicked', {
23+
app: 'docs',
24+
button_text: 'Copy for LLM',
25+
element: 'llm-buttons.copyForLLM',
26+
});
27+
}
28+
2329
try {
2430
setIsLoading(true);
2531

@@ -56,14 +62,7 @@ export default function CopyForLLM() {
5662
disabled={isLoading}
5763
>
5864
<span
59-
className={styles.llmButtonIcon}
60-
style={{
61-
backgroundImage: `url(${copyIcon})`,
62-
backgroundSize: 'contain',
63-
backgroundRepeat: 'no-repeat',
64-
backgroundPosition: 'center',
65-
display: 'inline-block',
66-
}}
65+
className={`${styles.llmButtonIcon} ${styles.llmButtonIconBackgroundCopy}`}
6766
aria-label="Copy for LLM"
6867
/>
6968
<ButtonText isLoading={isLoading} isCopied={isCopied} />

src/components/LLMButtons/ViewAsMarkdown/index.tsx

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,17 @@
1-
import useBaseUrl from '@docusaurus/useBaseUrl';
21
import React from 'react';
32

43
import styles from '../styles.module.css';
54

65
export default function ViewAsMarkdown() {
7-
const markdownIcon = useBaseUrl('/img/markdown.svg');
8-
96
const handleClick = () => {
7+
if ((window as any).analytics) {
8+
(window as any).analytics.track('Clicked', {
9+
app: 'docs',
10+
button_text: 'View as Markdown',
11+
element: 'llm-buttons.viewAsMarkdown',
12+
});
13+
}
14+
1015
try {
1116
const currentUrl = window.location.href;
1217
const markdownUrl = `${currentUrl}.md`;
@@ -23,14 +28,7 @@ export default function ViewAsMarkdown() {
2328
onClick={handleClick}
2429
>
2530
<span
26-
className={styles.llmButtonIcon}
27-
style={{
28-
backgroundImage: `url(${markdownIcon})`,
29-
backgroundSize: 'contain',
30-
backgroundRepeat: 'no-repeat',
31-
backgroundPosition: 'center',
32-
display: 'inline-block',
33-
}}
31+
className={`${styles.llmButtonIcon} ${styles.llmButtonIconBackgroundMarkdown}`}
3432
aria-label="View as Markdown"
3533
/>
3634
View as Markdown

src/components/LLMButtons/index.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@ import ViewAsMarkdown from './ViewAsMarkdown';
77
export default function LLMButtons() {
88
return (
99
<div className={styles.llmButtonsContainer}>
10-
<CopyForLLM />
11-
<div className={styles.llmButtonsSeparator}></div>
1210
<ViewAsMarkdown />
11+
<div className={styles.llmButtonsSeparator}></div>
12+
<CopyForLLM />
1313
</div>
1414
);
1515
}

src/components/LLMButtons/styles.module.css

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@
33
align-items: center;
44
gap: 12px;
55
margin-top: -8px;
6-
margin-bottom: calc(var(--ifm-h1-vertical-rhythm-bottom) * var(--ifm-leading));;
6+
margin-bottom: calc(var(--ifm-h1-vertical-rhythm-bottom) * var(--ifm-leading));
77
}
88

99
.llmButtonsSeparator {
1010
width: 1px;
1111
height: 16px;
12-
background-color: #e0e0e0;
12+
background-color: var(--ifm-hr-background-color);
1313
}
1414

1515
.llmButton {
@@ -28,11 +28,30 @@
2828
height: 16px;
2929
margin: 0 !important;
3030
cursor: pointer;
31+
background-size: contain;
32+
background-repeat: no-repeat;
33+
background-position: center;
34+
display: inline-block;
35+
}
36+
37+
.llmButtonIconBackgroundMarkdown {
38+
background-image: url('/img/markdown.svg');
39+
40+
}
41+
42+
.llmButtonIconBackgroundCopy {
43+
background-image: url('/img/copy.svg');
3144
}
3245

3346
/* Dark theme adjustments */
34-
[data-theme='dark'] .llmButton {
35-
background: #2a2a2a;
36-
border-color: #404040;
47+
[data-theme='dark'] .llmButtonIcon {
3748
color: #e0e0e0;
3849
}
50+
51+
[data-theme='dark'] .llmButtonIconBackgroundMarkdown {
52+
background-image: url('/img/markdown-dark-theme.svg');
53+
}
54+
55+
[data-theme='dark'] .llmButtonIconBackgroundCopy {
56+
background-image: url('/img/copy-dark-theme.svg');
57+
}

src/theme/DocItem/Content/index.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
import { useDoc } from '@docusaurus/plugin-content-docs/client';
1+
import { useDoc } from '@docusaurus/plugin-content-docs/client';
22
import { ThemeClassNames } from '@docusaurus/theme-common';
3+
import { useLocation } from '@docusaurus/router';
34
import Heading from '@theme/Heading';
45
import MDXContent from '@theme/MDXContent';
56
import clsx from 'clsx';
@@ -20,12 +21,14 @@ function useSyntheticTitle() {
2021

2122
export default function DocItemContent({ children }) {
2223
const syntheticTitle = useSyntheticTitle();
24+
const location = useLocation();
25+
const shouldShowLLMButtons = !location.pathname.startsWith('/legal');
2326

2427
return (
2528
<div className={clsx(ThemeClassNames.docs.docMarkdown, 'markdown')}>
2629
<header>
2730
<Heading as="h1">{syntheticTitle}</Heading>
28-
<LLMButtons />
31+
{shouldShowLLMButtons && <LLMButtons />}
2932
<MDXContent>{children}</MDXContent>
3033
</header>
3134
</div>

static/img/copy-dark-theme.svg

Lines changed: 4 additions & 0 deletions
Loading

static/img/markdown-dark-theme.svg

Lines changed: 5 additions & 0 deletions
Loading

0 commit comments

Comments
 (0)