-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#35 - Sets up infra for reading files from the repo - Adds components for rendering mdx pages - `MdxContent`: Root component for rendering the mdx page - `MdxPageTitle`: For showing the title of the page as well as when it was last updated - `MdxAccordion`: For rendering an accordion on the page, used by the FAQ page - Adds initial faq page + test content
- Loading branch information
1 parent
5199c14
commit 6a7b5e3
Showing
14 changed files
with
670 additions
and
108 deletions.
There are no files selected for viewing
42 changes: 42 additions & 0 deletions
42
frontend/packages/data-portal/app/components/MDX/MdxAccodion.module.css
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,42 @@ | ||
.accordion { | ||
h2 { | ||
@apply text-sds-header-xs leading-sds-header-xs font-semibold; | ||
@apply mt-sds-l mb-sds-xxs; | ||
} | ||
|
||
h3 { | ||
@apply text-sds-header-xxs leading-sds-header-xxs font-semibold; | ||
@apply mt-sds-m mb-sds-xxxs; | ||
} | ||
|
||
p { | ||
@apply mb-sds-m; | ||
} | ||
|
||
section { | ||
&:has(> h2) { | ||
@apply text-sds-body-xs leading-sds-body-xs; | ||
} | ||
|
||
&:has(> h3) { | ||
@apply text-sds-body-xxs leading-sds-body-xxs; | ||
} | ||
} | ||
|
||
ul, | ||
ol { | ||
@apply space-y-sds-xs ml-4; | ||
} | ||
|
||
ul { | ||
@apply list-disc; | ||
} | ||
|
||
ol { | ||
@apply list-decimal; | ||
} | ||
|
||
li ol { | ||
@apply ml-sds-l mt-sds-xs; | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
frontend/packages/data-portal/app/components/MDX/MdxAccordion.tsx
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,28 @@ | ||
import { | ||
Accordion, | ||
AccordionDetails, | ||
AccordionHeader, | ||
} from '@czi-sds/components' | ||
import { ReactNode } from 'react' | ||
|
||
import styles from './MdxAccodion.module.css' | ||
|
||
export function MdxAccordion({ | ||
children, | ||
title, | ||
}: { | ||
children: ReactNode | ||
title: string | ||
}) { | ||
return ( | ||
<Accordion | ||
className={styles.accordion} | ||
id={`accordion-${title}`} | ||
title={title} | ||
useDivider | ||
> | ||
<AccordionHeader>{title}</AccordionHeader> | ||
<AccordionDetails>{children}</AccordionDetails> | ||
</Accordion> | ||
) | ||
} |
24 changes: 24 additions & 0 deletions
24
frontend/packages/data-portal/app/components/MDX/MdxContent.tsx
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,24 @@ | ||
import { MDXRemote } from 'next-mdx-remote' | ||
|
||
import { useMdxFile } from 'app/hooks/useMdxFile' | ||
|
||
import { MdxAccordion } from './MdxAccordion' | ||
import { MdxPageTitle } from './MdxPageTitle' | ||
|
||
export function MdxContent() { | ||
const { content } = useMdxFile() | ||
|
||
return ( | ||
<div className="py-sds-xxl px-sds-xl flex flex-auto justify-center"> | ||
<div className="w-full max-w-mdx-content"> | ||
<MDXRemote | ||
{...content} | ||
components={{ | ||
Accordion: MdxAccordion, | ||
PageTitle: MdxPageTitle, | ||
}} | ||
/> | ||
</div> | ||
</div> | ||
) | ||
} |
24 changes: 24 additions & 0 deletions
24
frontend/packages/data-portal/app/components/MDX/MdxPageTitle.tsx
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,24 @@ | ||
import dayjs from 'dayjs' | ||
import { ReactNode } from 'react' | ||
|
||
import { useI18n } from 'app/hooks/useI18n' | ||
import { useMdxFile } from 'app/hooks/useMdxFile' | ||
|
||
export function MdxPageTitle({ children }: { children: ReactNode }) { | ||
const { t } = useI18n() | ||
const { lastModified } = useMdxFile() | ||
|
||
return ( | ||
<div className="flex flex-col gap-sds-xs mb-sds-xxl"> | ||
<h1 className="text-sds-header-xxl leading-sds-header-xxl font-semibold"> | ||
{children} | ||
</h1> | ||
|
||
{lastModified && ( | ||
<p className="text-sds-body-xxs leading-sds-body-xxs text-sds-gray-600"> | ||
{t('lastUpdated')}: {dayjs(lastModified).format('MMMM DD, YYYY')} | ||
</p> | ||
)} | ||
</div> | ||
) | ||
} |
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 @@ | ||
export * from './MdxContent' |
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 { MDXRemoteSerializeResult } from 'next-mdx-remote' | ||
import { useTypedLoaderData } from 'remix-typedjson' | ||
|
||
export function useMdxFile() { | ||
return useTypedLoaderData<{ | ||
content: MDXRemoteSerializeResult | ||
lastModified: Date | null | ||
}>() | ||
} |
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 |
---|---|---|
@@ -1,5 +1,10 @@ | ||
import { Demo } from 'app/components/Demo' | ||
import { MdxContent } from 'app/components/MDX' | ||
import { getRepoFileContentResponse } from 'app/utils/repo.server' | ||
|
||
export async function loader() { | ||
return getRepoFileContentResponse('website-docs/faq.mdx') | ||
} | ||
|
||
export default function FaqPage() { | ||
return <Demo>FAQ Page</Demo> | ||
return <MdxContent /> | ||
} |
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,47 @@ | ||
import { AxiosResponse } from 'axios' | ||
import { serialize } from 'next-mdx-remote/serialize' | ||
import { Octokit } from 'octokit' | ||
import sectionize from 'remark-sectionize' | ||
import { typedjson } from 'remix-typedjson' | ||
|
||
import { axios } from 'app/axios' | ||
|
||
const octokit = new Octokit() | ||
|
||
export interface RepoFile { | ||
content: string | ||
lastModified: Date | null | ||
} | ||
|
||
export async function getRepoFileContent(path: string): Promise<RepoFile> { | ||
// eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion | ||
const response = (await axios.get( | ||
`https://raw.githubusercontent.com/chanzuckerberg/cryoet-data-portal/main/${path}`, | ||
)) as AxiosResponse | ||
|
||
const data = await octokit.rest.repos.listCommits({ | ||
owner: 'chanzuckerberg', | ||
repo: 'cryoet-data-portal', | ||
per_page: 1, | ||
}) | ||
|
||
const date = data.data[0].commit.committer?.date | ||
|
||
return { | ||
content: response.data as string, | ||
lastModified: date ? new Date(date) : null, | ||
} | ||
} | ||
|
||
export async function getRepoFileContentResponse(path: string) { | ||
const { content, lastModified } = await getRepoFileContent(path) | ||
|
||
return typedjson({ | ||
lastModified, | ||
content: await serialize(content, { | ||
mdxOptions: { | ||
remarkPlugins: [sectionize], | ||
}, | ||
}), | ||
}) | ||
} |
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
Oops, something went wrong.