anchor
This commit is contained in:
parent
a1fb68764a
commit
c088f1d7c2
2 changed files with 23 additions and 5 deletions
|
|
@ -1,14 +1,32 @@
|
||||||
'use client'
|
'use client'
|
||||||
import { useHeaderTheme } from '@/providers/HeaderTheme'
|
import { useHeaderTheme } from '@/providers/HeaderTheme'
|
||||||
import React, { useEffect } from 'react'
|
import React, { useEffect } from 'react'
|
||||||
|
import { usePathname } from 'next/navigation'
|
||||||
|
|
||||||
const PageClient: React.FC = () => {
|
const PageClient: React.FC = () => {
|
||||||
/* Force the header to be dark mode while we have an image behind it */
|
|
||||||
const { setHeaderTheme } = useHeaderTheme()
|
const { setHeaderTheme } = useHeaderTheme()
|
||||||
|
const pathname = usePathname()
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
setHeaderTheme('light')
|
setHeaderTheme('light')
|
||||||
}, [setHeaderTheme])
|
}, [setHeaderTheme])
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
const hash = window.location.hash
|
||||||
|
if (!hash) return
|
||||||
|
|
||||||
|
const tryScroll = (attempts = 0) => {
|
||||||
|
const el = document.querySelector(hash)
|
||||||
|
if (el) {
|
||||||
|
el.scrollIntoView({ behavior: 'smooth' })
|
||||||
|
} else if (attempts < 10) {
|
||||||
|
setTimeout(() => tryScroll(attempts + 1), 100)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
tryScroll()
|
||||||
|
}, [pathname])
|
||||||
|
|
||||||
return <React.Fragment />
|
return <React.Fragment />
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -12,6 +12,7 @@ import { RenderHero } from '@/heros/RenderHero'
|
||||||
import { generateMeta } from '@/utilities/generateMeta'
|
import { generateMeta } from '@/utilities/generateMeta'
|
||||||
import PageClient from './page.client'
|
import PageClient from './page.client'
|
||||||
import { LivePreviewListener } from '@/components/LivePreviewListener'
|
import { LivePreviewListener } from '@/components/LivePreviewListener'
|
||||||
|
import ScrollToTop from '@/components/ScrollToTop'
|
||||||
|
|
||||||
import HeroBackground from '@/components/HeroBackground'
|
import HeroBackground from '@/components/HeroBackground'
|
||||||
import HeroPage from '@/components/HeroPage'
|
import HeroPage from '@/components/HeroPage'
|
||||||
|
|
@ -28,7 +29,6 @@ type Args = {
|
||||||
}>
|
}>
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add any slugs here that should use the landing page layout
|
|
||||||
const LANDING_PAGE_SLUGS = ['home']
|
const LANDING_PAGE_SLUGS = ['home']
|
||||||
|
|
||||||
export default async function Page({ params: paramsPromise }: Args) {
|
export default async function Page({ params: paramsPromise }: Args) {
|
||||||
|
|
@ -51,16 +51,15 @@ export default async function Page({ params: paramsPromise }: Args) {
|
||||||
|
|
||||||
const { hero, layout } = page
|
const { hero, layout } = page
|
||||||
|
|
||||||
// Landing page layout — canvas + hero section with border lines
|
|
||||||
if (LANDING_PAGE_SLUGS.includes(decodedSlug)) {
|
if (LANDING_PAGE_SLUGS.includes(decodedSlug)) {
|
||||||
return (
|
return (
|
||||||
<HeroPage richText={hero.richText} links={hero.links}>
|
<HeroPage richText={hero.richText} links={hero.links}>
|
||||||
<RenderBlocks blocks={layout} />
|
<RenderBlocks blocks={layout} />
|
||||||
|
<ScrollToTop />
|
||||||
</HeroPage>
|
</HeroPage>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
// All other pages — canvas background + standard content
|
|
||||||
return (
|
return (
|
||||||
<div style={{ position: 'relative', minHeight: '100vh' }}>
|
<div style={{ position: 'relative', minHeight: '100vh' }}>
|
||||||
<div style={{ position: 'fixed', inset: 0, zIndex: 0 }}>
|
<div style={{ position: 'fixed', inset: 0, zIndex: 0 }}>
|
||||||
|
|
@ -73,6 +72,7 @@ export default async function Page({ params: paramsPromise }: Args) {
|
||||||
<RenderHero {...hero} />
|
<RenderHero {...hero} />
|
||||||
<RenderBlocks blocks={layout} />
|
<RenderBlocks blocks={layout} />
|
||||||
</article>
|
</article>
|
||||||
|
<ScrollToTop />
|
||||||
</div>
|
</div>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
@ -104,4 +104,4 @@ const queryPageBySlug = cache(async ({ slug }: { slug: string }) => {
|
||||||
})
|
})
|
||||||
|
|
||||||
return result.docs?.[0] || null
|
return result.docs?.[0] || null
|
||||||
})
|
})
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue