-
Notifications
You must be signed in to change notification settings - Fork 38
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Markdown for landing pages #341
Open
pettinarip
wants to merge
9
commits into
master
Choose a base branch
from
markdown
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
dcb7ae3
initial setup for markdown pages
pettinarip 184755b
refactor
pettinarip b02b388
refactor2
pettinarip ca9dcec
add md sidebar
pettinarip f9e732b
create new hook to get current path including the dynamic generated o…
pettinarip 01f6804
add error handling to getContentPaths
pettinarip 841aeb4
Merge branch 'master' into markdown
pettinarip 644fecb
fix after merge
pettinarip 3ae6ac2
Merge branch 'master' into markdown
pettinarip File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import { Link, LinkProps } from '@chakra-ui/react'; | ||
|
||
export const MdLink = (props: LinkProps) => { | ||
return <Link fontWeight={700} color='brand.orange.100' isExternal {...props} />; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import { Box, Flex, Link } from '@chakra-ui/react'; | ||
import { FC, useMemo } from 'react'; | ||
import NextLink from 'next/link'; | ||
|
||
import { PageText } from '..'; | ||
|
||
import { SidebarLink } from '../../../types'; | ||
import { useActiveHash } from '../../../hooks/useActiveHash'; | ||
|
||
interface Props { | ||
sidebarLinks: SidebarLink[]; | ||
} | ||
|
||
export const MdSidebar: FC<Props> = ({ sidebarLinks }) => { | ||
const hrefs = useMemo(() => sidebarLinks.map(({ href }) => href), [sidebarLinks]); | ||
const activeHash = useActiveHash(hrefs, '0px'); | ||
|
||
return ( | ||
<Flex | ||
display={{ base: 'none', lg: 'block' }} | ||
bgGradient='linear(to-b, brand.sidebar.bgGradient.start 30%, brand.sidebar.bgGradient.end 100%)' | ||
w='306px' | ||
pt={12} | ||
pl={14} | ||
mt={-12} | ||
top={0} | ||
position='sticky' | ||
alignSelf='flex-start' | ||
h='45vh' | ||
> | ||
{sidebarLinks.map(({ text, href }, idx) => ( | ||
<Flex key={text} alignItems='center' mb={1}> | ||
<Box | ||
borderLeft='5px solid' | ||
borderLeftColor={activeHash === href ? 'brand.accent' : 'transparent'} | ||
h='18px' | ||
/> | ||
|
||
<Box pl={3}> | ||
<Link as={NextLink} href={href} _hover={{ textDecoration: 'none' }}> | ||
<PageText fontWeight={400} lineHeight='28px' color='brand.orange.100'> | ||
{text} | ||
</PageText> | ||
</Link> | ||
</Box> | ||
</Flex> | ||
))} | ||
</Flex> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import { ReactNode } from 'react'; | ||
import { Box, Flex, Stack } from '@chakra-ui/react'; | ||
|
||
import { PageMetadata } from '../UI'; | ||
import { MdSidebar } from '../UI/md/MdSidebar'; | ||
|
||
import type { Frontmatter, ToCNodeEntry, TocNodeType } from '../../types'; | ||
|
||
type LayoutProps = { | ||
children: ReactNode; | ||
frontmatter: Frontmatter; | ||
tocNodeItems: TocNodeType[]; | ||
}; | ||
|
||
export const MdLayout = ({ children, frontmatter, tocNodeItems }: LayoutProps) => { | ||
const { metaTitle, metaDescription, metaImage } = frontmatter; | ||
|
||
return ( | ||
<Stack> | ||
<PageMetadata title={metaTitle} description={metaDescription} image={metaImage} /> | ||
|
||
<Box mx={{ md: 12 }} bg='white' position='relative' zIndex={1} mt={{ xl: 12 }}> | ||
<Stack spacing={10} mb={8} px={{ base: 5, md: 0 }} py={{ base: 3, md: 12 }}> | ||
<Flex> | ||
<MdSidebar | ||
sidebarLinks={tocNodeItems | ||
.filter((item): item is ToCNodeEntry => !('items' in item)) | ||
.map(item => ({ text: item.title || '', href: item.url || '' }))} | ||
/> | ||
|
||
<Box w={{ lg: '70%' }} px={{ md: 20 }} pr={{ lg: 12 }}> | ||
<Flex gap={6} direction='column'> | ||
{children} | ||
</Flex> | ||
</Box> | ||
</Flex> | ||
</Stack> | ||
</Box> | ||
</Stack> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import { useEffect, useState } from 'react'; | ||
|
||
/** | ||
* A hook to determine which section of the page is currently in the viewport. | ||
* @param {*} itemIds Array of document ids to observe | ||
* @param {*} rootMargin | ||
* @returns id of the element currently in viewport | ||
*/ | ||
export const useActiveHash = (itemIds: Array<string>, rootMargin = `0% 0% -80% 0%`): string => { | ||
const [hashes, setHashes] = useState<Record<string, boolean>>(() => | ||
itemIds.reduce((acc, id, index) => ({ [id]: index === 0, ...acc }), {}) | ||
); | ||
|
||
useEffect(() => { | ||
const observer = new IntersectionObserver( | ||
entries => { | ||
entries.forEach(entry => { | ||
const hash = `#${entry.target.id}`; | ||
setHashes(hashes => ({ ...hashes, [hash]: entry.isIntersecting })); | ||
}); | ||
}, | ||
{ rootMargin } | ||
); | ||
|
||
itemIds?.forEach(id => { | ||
// Remove # from id. EX: #element-id -> element-id | ||
const element = document.getElementById(id.replace('#', '')); | ||
if (element !== null) { | ||
observer.observe(element); | ||
} | ||
}); | ||
|
||
return () => { | ||
itemIds?.forEach(id => { | ||
const element = document.getElementById(id); | ||
if (element !== null) { | ||
observer.unobserve(element); | ||
} | ||
}); | ||
}; | ||
}, [itemIds, rootMargin]); | ||
|
||
const firstActiveHash = itemIds.find(id => hashes[id]); | ||
|
||
return firstActiveHash || itemIds[0]; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import { useRouter } from 'next/router'; | ||
|
||
// Gets the current path from the slug param (if this is a dynamic route) or the | ||
// router pathname (if this is a static route) | ||
export const useCurrentPath = () => { | ||
const { query, pathname } = useRouter(); | ||
|
||
return query.slug ? query.slug.toString() : pathname; | ||
}; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think there may be a bug in this file. Noticing when I scroll past the
Frequently asked questions
header it jumps the sidenav active hash to the top oneScreen.Recording.2024-03-16.at.12.19.11.PM.mov
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah good catch, will take a look!