Skip to content

Commit

Permalink
Hide how-to-doc for Nextra v3 (#233)
Browse files Browse the repository at this point in the history
  • Loading branch information
DariuszDepta authored Jan 20, 2025
2 parents c84260c + 6242f34 commit eb31ec4
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 25 deletions.
27 changes: 27 additions & 0 deletions src/components/DocTitle.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { useEffect, useRef } from "react";

export default function DocTitle() {
const titleRef = useRef(null);

useEffect(() => {
if (!titleRef.current) {
return;
}

const isDocRoute = window.location.pathname.startsWith("/how-to-doc");
const parent = titleRef.current.parentNode;
const grandparent = parent.parentNode;

// Hide sidebar menu option
if (!isDocRoute && parent.tagName === "A" && grandparent.tagName === "LI") {
grandparent.classList.add("hidden");
}

// Hide nextLink on the page before "How to doc"
if (!isDocRoute && parent.tagName === "A" && grandparent.tagName === "DIV") {
parent.classList.add("hidden");
}
}, []);

return <span ref={titleRef}>How to doc</span>;
}
9 changes: 5 additions & 4 deletions src/pages/_meta.js → src/pages/_meta.jsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import DocTitle from "@/components/DocTitle";

export default {
index: "Welcome",
core: "CosmWasm Core",
Expand All @@ -7,9 +9,8 @@ export default {
storey: "Storey",
"cw-storage-plus": "StoragePlus",
"cw-multi-test": "MultiTest",
"how-to-doc": "How to doc",
tags: {
display: "hidden",
},
tutorial: "Tutorial",
// NOTE - Leave these 2 items at the bottom 🙏
"how-to-doc": { title: <DocTitle /> },
tags: { display: "hidden" },
};
7 changes: 0 additions & 7 deletions src/pages/global.css
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,3 @@
@apply bg-background text-foreground;
}
}

/* Hide How to Doc directory on the sidebar */
li:has(a > .how-to-doc-dir),
/* Hide links to How to Doc index, except the prevLink on the page after that */
a[href="/how-to-doc"]:not(:has(div))[class~="ltr:nx-ml-auto"] {
display: none;
}
14 changes: 0 additions & 14 deletions src/theme.config.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -55,20 +55,6 @@ export default {
sidebar: {
autoCollapse: true,
defaultMenuCollapseLevel: 1,
// NOTE this property no longer exists
/* titleComponent: ({ title, route }) => {
const [isDocRoute, setIsDocRoute] = useState(false);
useEffect(() => {
setIsDocRoute(window.location.pathname.startsWith("/how-to-doc"));
}, []);
return (
<div className={cn("group", !isDocRoute && title === "How to doc" ? "how-to-doc-dir" : "")}>
<span>{title}</span> <TagDots route={route} />
</div>
);
}, */
},
head: function useHead() {
const config = useConfig();
Expand Down

0 comments on commit eb31ec4

Please sign in to comment.