Skip to content

Commit 696fd49

Browse files
Add llm buttons only if we render html - v3
1 parent c143d17 commit 696fd49

File tree

3 files changed

+18
-8
lines changed

3 files changed

+18
-8
lines changed

apify-docs-theme/src/theme/Layout/index.jsx

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,19 @@ export default function LayoutWrapper(props) {
1010
const { options: { subNavbar } } = usePluginData('@apify/docs-theme');
1111
const baseUrl = useBaseUrl('/');
1212
const currentPath = useLocation().pathname.replace(new RegExp(`^${baseUrl}`), '');
13+
const isMarkdownView = currentPath.endsWith('.md');
14+
15+
// Add data attribute to HTML element when on markdown view
16+
React.useEffect(() => {
17+
if (typeof document !== 'undefined') {
18+
const htmlElement = document.documentElement;
19+
if (isMarkdownView) {
20+
htmlElement.setAttribute('data-markdown-view', 'true');
21+
} else {
22+
htmlElement.removeAttribute('data-markdown-view');
23+
}
24+
}
25+
}, [isMarkdownView]);
1326

1427
return (
1528
<>

src/components/LLMButtons/index.tsx

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,10 @@
1-
import { useLocation } from '@docusaurus/router';
21
import React from 'react';
32

43
import CopyForLLM from './CopyForLLM';
54
import styles from './styles.module.css';
65
import ViewAsMarkdown from './ViewAsMarkdown';
76

87
export default function LLMButtons() {
9-
const location = useLocation();
10-
11-
// Don't render LLMButtons if we're on a markdown view
12-
if (location.pathname.endsWith('.md')) {
13-
return null;
14-
}
15-
168
return (
179
<div className={styles.llmButtonsContainer}>
1810
<ViewAsMarkdown />

src/components/LLMButtons/styles.module.css

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,11 @@
66
margin-bottom: calc(var(--ifm-h1-vertical-rhythm-bottom) * var(--ifm-leading));
77
}
88

9+
/* Hide LLMButtons on markdown pages (URLs ending with .md) */
10+
html[data-markdown-view="true"] .llmButtonsContainer {
11+
display: none !important;
12+
}
13+
914
.llmButtonsSeparator {
1015
width: 1px;
1116
height: 16px;

0 commit comments

Comments
 (0)