fix current site highlighting in nav for rendered html
This commit is contained in:
parent
1650f188af
commit
92b1e1c822
|
@ -3,9 +3,9 @@ import Nav from "../components/nav"
|
||||||
import Footer from "../components/footer"
|
import Footer from "../components/footer"
|
||||||
import layoutStyles from "./layout.module.css"
|
import layoutStyles from "./layout.module.css"
|
||||||
|
|
||||||
export default ({ editLink, children }) => (
|
export default ({ path, editLink, children }) => (
|
||||||
<>
|
<>
|
||||||
<Nav />
|
<Nav path={path} />
|
||||||
<div className={layoutStyles.layout}>{children}</div>
|
<div className={layoutStyles.layout}>{children}</div>
|
||||||
<Footer editLink={editLink} />
|
<Footer editLink={editLink} />
|
||||||
</>
|
</>
|
||||||
|
|
|
@ -4,13 +4,19 @@ import { Link } from "gatsby"
|
||||||
|
|
||||||
let pages = [
|
let pages = [
|
||||||
["home", ""],
|
["home", ""],
|
||||||
["zeiten & location", "treff/"],
|
["zeiten & location", "treff"],
|
||||||
["events", "events/"],
|
["events", "events"],
|
||||||
["kontakt", "kontakt/"],
|
["kontakt", "kontakt"],
|
||||||
["verein", "verein/"],
|
["verein", "verein"],
|
||||||
]
|
]
|
||||||
|
|
||||||
export default () => (
|
export default ({ path }) => {
|
||||||
|
// nav items should always be active in the staticly generated html
|
||||||
|
const isSSR = typeof window === "undefined"
|
||||||
|
const activeClasses = link =>
|
||||||
|
isSSR && path === "/" + link ? " " + navStyles.navItemActive : ""
|
||||||
|
|
||||||
|
return (
|
||||||
<>
|
<>
|
||||||
<div className={navStyles.header}>
|
<div className={navStyles.header}>
|
||||||
<div className={navStyles.headerContent}>
|
<div className={navStyles.headerContent}>
|
||||||
|
@ -22,7 +28,7 @@ export default () => (
|
||||||
{pages.map(([title, link]) => (
|
{pages.map(([title, link]) => (
|
||||||
<Link
|
<Link
|
||||||
key={title}
|
key={title}
|
||||||
className={navStyles.navItem}
|
className={navStyles.navItem + activeClasses(link)}
|
||||||
activeClassName={navStyles.navItemActive}
|
activeClassName={navStyles.navItemActive}
|
||||||
activeStyle={{ textDecoration: `solid underline white 0.2em` }}
|
activeStyle={{ textDecoration: `solid underline white 0.2em` }}
|
||||||
to={`/${link}`}
|
to={`/${link}`}
|
||||||
|
@ -33,4 +39,5 @@ export default () => (
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</>
|
</>
|
||||||
)
|
)
|
||||||
|
}
|
||||||
|
|
|
@ -22,17 +22,19 @@ const components = {
|
||||||
export default function Template({
|
export default function Template({
|
||||||
data, // this prop will be injected by the GraphQL query below.
|
data, // this prop will be injected by the GraphQL query below.
|
||||||
}) {
|
}) {
|
||||||
const { mdx } = data // data.markdownRemark holds your post data
|
const {
|
||||||
const { frontmatter, body } = mdx
|
frontmatter: { title, edit, path },
|
||||||
|
body,
|
||||||
|
} = data.mdx
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
document.title = `ctdo - ${frontmatter.title.toLowerCase()}`
|
document.title = `ctdo - ${title.toLowerCase()}`
|
||||||
}, [frontmatter.title])
|
}, [title])
|
||||||
|
|
||||||
const editLink = frontmatter.edit ? ide + frontmatter.edit.relativePath : null
|
const editLink = edit ? ide + edit : null
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Layout editLink={editLink}>
|
<Layout path={path} editLink={editLink}>
|
||||||
<MDXProvider components={components}>
|
<MDXProvider components={components}>
|
||||||
<MDXRenderer>{body}</MDXRenderer>
|
<MDXRenderer>{body}</MDXRenderer>
|
||||||
</MDXProvider>
|
</MDXProvider>
|
||||||
|
@ -47,6 +49,7 @@ export const pageQuery = graphql`
|
||||||
frontmatter {
|
frontmatter {
|
||||||
title
|
title
|
||||||
edit
|
edit
|
||||||
|
path
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue