Skip to content

Commit 1265890

Browse files
committed
create and implement MainArticle component
contains default props including id, tabIndex and as="article"; to be used once per page for the main article which will bear the #main-content ID
1 parent e0e51c8 commit 1265890

File tree

6 files changed

+27
-27
lines changed

6 files changed

+27
-27
lines changed

src/components/MainArticle.tsx

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import { Box, type BoxProps } from "@chakra-ui/react"
2+
3+
import { MAIN_CONTENT_ID } from "@/lib/constants"
4+
5+
const MainArticle = (props: BoxProps) => (
6+
<Box as="article" id={MAIN_CONTENT_ID} tabIndex={-1} {...props} />
7+
)
8+
9+
export default MainArticle

src/components/MdComponents.tsx

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,15 +32,14 @@ import OldHeading from "@/components/OldHeading"
3232
import { mdxTableComponents } from "@/components/Table"
3333
import YouTube from "@/components/YouTube"
3434

35-
import { MAIN_CONTENT_ID } from "@/lib/constants"
36-
3735
import GlossaryTooltip from "./Glossary/GlossaryTooltip"
3836
import { StandaloneQuizWidget } from "./Quiz/QuizWidget"
3937
import Card from "./Card"
4038
import DocLink from "./DocLink"
4139
import Emoji from "./Emoji"
4240
import ExpandableCard from "./ExpandableCard"
4341
import InfoBanner from "./InfoBanner"
42+
import MainArticle from "./MainArticle"
4443

4544
/**
4645
* Base HTML elements
@@ -188,8 +187,7 @@ export const ContentContainer = (props: Pick<BoxProps, "id" | "children">) => {
188187

189188
return (
190189
<Box
191-
as="article"
192-
id={MAIN_CONTENT_ID}
190+
as={MainArticle}
193191
flex={`1 1 ${lgBp}`}
194192
position="relative"
195193
px={8}

src/layouts/Docs.tsx

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ import GitHubContributors from "@/components/GitHubContributors"
3131
import GlossaryTooltip from "@/components/Glossary/GlossaryTooltip"
3232
import InfoBanner from "@/components/InfoBanner"
3333
import Link from "@/components/Link"
34+
import MainArticle from "@/components/MainArticle"
3435
import {
3536
Heading1 as MdHeading1,
3637
Heading2 as MdHeading2,
@@ -48,11 +49,7 @@ import Translation from "@/components/Translation"
4849
import YouTube from "@/components/YouTube"
4950

5051
// Utils
51-
import {
52-
DEFAULT_LOCALE,
53-
EDIT_CONTENT_URL,
54-
MAIN_CONTENT_ID,
55-
} from "@/lib/constants"
52+
import { DEFAULT_LOCALE, EDIT_CONTENT_URL } from "@/lib/constants"
5653

5754
import { useClientSideGitHubLastEdit } from "@/hooks/useClientSideGitHubLastEdit"
5855

@@ -91,6 +88,7 @@ const baseHeadingStyle: HeadingProps = {
9188
fontFamily: "mono",
9289
textTransform: "uppercase",
9390
fontWeight: "bold",
91+
scrollMarginTop: 40,
9492
}
9593

9694
const H1 = (props: HeadingProps) => (
@@ -141,12 +139,12 @@ const ListItem = (props: ListItemProps) => (
141139
)
142140

143141
// Apply styles for classes within markdown here
144-
const Content = (props: Pick<FlexProps, "children" | "id">) => {
142+
const Content = (props: ChildOnlyProp) => {
145143
const mdBreakpoint = useToken("breakpoints", "md")
146144

147145
return (
148146
<Box
149-
as="article"
147+
as={MainArticle}
150148
flex={`1 1 ${mdBreakpoint}`}
151149
maxW={{ base: "full", lg: mdBreakpoint }}
152150
pt={{ base: 32, md: 12 }}
@@ -250,7 +248,7 @@ export const DocsLayout = ({
250248
)}
251249
<ContentContainer>
252250
<SideNav path={relativePath} />
253-
<Content id={MAIN_CONTENT_ID}>
251+
<Content>
254252
<H1 id="top">{frontmatter.title}</H1>
255253
{useGitHubContributors ? (
256254
<GitHubContributors

src/layouts/Static.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import GlossaryDefinition from "@/components/Glossary/GlossaryDefinition"
1313
import NetworkUpgradeSummary from "@/components/History/NetworkUpgradeSummary"
1414
import Link from "@/components/Link"
1515
import Logo from "@/components/Logo"
16+
import MainArticle from "@/components/MainArticle"
1617
import MatomoOptOut from "@/components/MatomoOptOut"
1718
import {
1819
Heading1 as MdHeading1,
@@ -30,7 +31,7 @@ import UpcomingEventsList from "@/components/UpcomingEventsList"
3031

3132
import { getLocaleTimestamp } from "@/lib/utils/time"
3233

33-
import { CONTENT_DIR, MAIN_CONTENT_ID } from "@/lib/constants"
34+
import { CONTENT_DIR } from "@/lib/constants"
3435

3536
const Heading1 = (props: HeadingProps) => (
3637
<MdHeading1 fontSize={{ base: "2.5rem", md: "5xl" }} {...props} />
@@ -102,8 +103,7 @@ export const StaticLayout: React.FC<IProps> = ({
102103
pt={{ base: 8, lg: 16 }}
103104
>
104105
<Box
105-
as="article"
106-
id={MAIN_CONTENT_ID}
106+
as={MainArticle}
107107
maxW="container.md"
108108
w="full"
109109
sx={{

src/layouts/Tutorial.tsx

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import { useRouter } from "next/router"
22
import {
33
Badge,
44
Box,
5-
type BoxProps,
65
chakra,
76
Divider,
87
Flex,
@@ -28,6 +27,7 @@ import FeedbackCard from "@/components/FeedbackCard"
2827
import GitHubContributors from "@/components/GitHubContributors"
2928
import GlossaryTooltip from "@/components/Glossary/GlossaryTooltip"
3029
import InfoBanner from "@/components/InfoBanner"
30+
import MainArticle from "@/components/MainArticle"
3131
import {
3232
Heading1 as MdHeading1,
3333
Heading2 as MdHeading2,
@@ -41,21 +41,17 @@ import TableOfContents from "@/components/TableOfContents"
4141
import TutorialMetadata from "@/components/TutorialMetadata"
4242
import YouTube from "@/components/YouTube"
4343

44-
import {
45-
DEFAULT_LOCALE,
46-
EDIT_CONTENT_URL,
47-
MAIN_CONTENT_ID,
48-
} from "@/lib/constants"
44+
import { DEFAULT_LOCALE, EDIT_CONTENT_URL } from "@/lib/constants"
4945

5046
import { useClientSideGitHubLastEdit } from "@/hooks/useClientSideGitHubLastEdit"
5147

52-
const ContentContainer = (props: Pick<BoxProps, "id" | "children">) => {
48+
const ContentContainer = (props: ChildOnlyProp) => {
5349
const boxShadow = useToken("colors", "tableBoxShadow")
5450
const borderColor = useToken("colors", "primary.base")
5551

5652
return (
5753
<Box
58-
as="article"
54+
as={MainArticle}
5955
maxW="1000px"
6056
minW={0}
6157
background="background.base"
@@ -218,7 +214,7 @@ export const TutorialLayout = ({
218214
description={frontmatter.description}
219215
canonicalUrl={frontmatter.sourceUrl}
220216
/>
221-
<ContentContainer id={MAIN_CONTENT_ID}>
217+
<ContentContainer>
222218
<Heading1>{frontmatter.title}</Heading1>
223219
<TutorialMetadata frontmatter={frontmatter} timeToRead={timeToRead} />
224220
<TableOfContents

src/lib/utils/url.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { DISCORD_PATH } from "@/lib/constants"
1+
import { DISCORD_PATH, MAIN_CONTENT_ID } from "@/lib/constants"
22

33
export const isDiscordInvite = (href: string): boolean =>
44
href.includes(DISCORD_PATH) && !href.includes("http")
@@ -17,8 +17,7 @@ export const isPdf = (href: string): boolean => href.endsWith(".pdf")
1717
export const sanitizeHitUrl = (url: string): string =>
1818
url
1919
.replace(/^https?:\/\/[^\/]+(?=\/)/, "")
20-
.replace("#gatsby-focus-wrapper", "")
21-
.replace("#main-content", "")
20+
.replace(MAIN_CONTENT_ID, "")
2221
.replace("#content", "")
2322
.replace("#top", "")
2423

0 commit comments

Comments
 (0)