Skip to content

Commit

Permalink
Remove headings if same as codeblock headings (#1523)
Browse files Browse the repository at this point in the history
  • Loading branch information
louisachu committed Jun 28, 2023
1 parent 413cd15 commit 0c9ef54
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
3 changes: 2 additions & 1 deletion packages/gatsby-theme-aio/src/components/CodeBlock/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ const CodeBlock = (props) => {
key={index}
ref={ref}
selected={true}
id={'code-block-' + props[block.heading].props.children}
tabIndex={index === selectedIndex.tab ? "0":"-1"}
onKeyDown={(e) => {
if (e.key === 'ArrowRight' || e.key === 'R' || e.key === 'r') {
Expand Down Expand Up @@ -141,7 +142,7 @@ const CodeBlock = (props) => {
`}>
{codeBlocks.map(
(block, i) =>
selectedIndex.tab === i && codeBlocks[i].languages && (
selectedIndex.tab === i && codeBlocks[i].languages.length > 1 && (
<Picker
key={i}
isQuiet
Expand Down
5 changes: 5 additions & 0 deletions packages/gatsby-theme-aio/src/components/OnThisPage/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,11 @@ const OnThisPage = ({ tableOfContents }) => {
readTableOfContents(headings, setTableOfContentsItems);
}
}
const codeBlockHeadings = document.querySelectorAll('[id*="code-block-"]');
let codeHeadings = [];
codeBlockHeadings && codeBlockHeadings.forEach(codeBlockHeading => { codeHeadings.push(codeBlockHeading.children[0].textContent)});
let ignoreCodeBlockHeadings = tableOfContentsItems?.filter(item => codeHeadings && !codeHeadings?.includes(item.title));
setTableOfContentsItems(ignoreCodeBlockHeadings);
}, []);

// Highlights the visible sections on the page based on scrolling
Expand Down

0 comments on commit 0c9ef54

Please sign in to comment.