Skip to content

Commit

Permalink
Merge pull request #426 from vtexdocs/feat/add-codehike
Browse files Browse the repository at this point in the history
feat(codehike): install codehike
  • Loading branch information
carolinamenezes authored Nov 1, 2023
2 parents 4cd8bcc + 601341b commit f7a4604
Show file tree
Hide file tree
Showing 11 changed files with 756 additions and 12 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
"cypress": "cypress open"
},
"dependencies": {
"@code-hike/mdx": "^0.9.0",
"@highlightjs/cdn-assets": "^11.7.0",
"@lit-labs/nextjs": "^0.1.1",
"@openreplay/tracker": "^5.0.1",
Expand Down
2 changes: 2 additions & 0 deletions src/components/code-block/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import { Box, Text } from '@vtex/brand-ui'
import styles from './styles'
import { childrenToString } from 'utils/string-utils'

//CODE HIKE IS BEING USED INSTEAD OF THIS COMPONENT

type Component = {
node: object
// eslint-disable-next-line @typescript-eslint/no-explicit-any
Expand Down
5 changes: 3 additions & 2 deletions src/components/markdown-renderer/components.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { childrenToString, slugify } from 'utils/string-utils'
import OverviewCard from 'components/overview-card'
import WhatsNextCard from 'components/whats-next-card'
import YoutubeFrame from 'components/youtube-frame'
import CodeBlock from 'components/code-block'
import { CH } from '@code-hike/mdx/components'
import Steps from 'components/steps'

import styles from './styles.module.css'
Expand Down Expand Up @@ -144,6 +144,7 @@ const MermaidDiagram = ({ node, ...props }: Component) => {
}

export default {
CH,
OverviewCard,
WhatsNextCard,
YoutubeFrame,
Expand Down Expand Up @@ -213,7 +214,7 @@ export default {
if (props.className && props.className === 'mermaid')
return <MermaidDiagram {...props} />

return <CodeBlock {...props} />
return <pre className={styles.pre} {...props} />
},
h2: ({ node, ...props }: Component) => {
const { activeItem, setActiveItem, goToPreviousItem } =
Expand Down
2 changes: 1 addition & 1 deletion src/pages/_app.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { AppProps } from 'next/app'
import type { Page } from 'utils/typings/types'

import '@code-hike/mdx/dist/index.css'
import Head from 'next/head'
import { SessionProvider } from 'next-auth/react'

Expand Down
13 changes: 13 additions & 0 deletions src/pages/docs/apps/[slug]/[child].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import Head from 'next/head'
import SeeAlsoSection from 'components/see-also-section'
import { ParsedUrlQuery } from 'querystring'
import { flattenJSON, getKeyByValue, getParents } from 'utils/navigation-utils'
import { remarkCodeHike } from '@code-hike/mdx'

interface IParams extends ParsedUrlQuery {
slug: string
Expand Down Expand Up @@ -191,6 +192,17 @@ export const getStaticProps: GetStaticProps = async ({ params }) => {
parseFrontmatter: true,
mdxOptions: {
remarkPlugins: [
[
remarkCodeHike,
{
autoImport: false,
showCopyButton: true,
lineNumbers: true,
skipLanguages: ['mermaid'],
staticMediaQuery: 'not screen, (max-width: 850px)',
theme: 'poimandres',
},
],
remarkGFM,
remarkImages,
[getHeadings, { headingList }],
Expand All @@ -199,6 +211,7 @@ export const getStaticProps: GetStaticProps = async ({ params }) => {
rehypePlugins: [
[rehypeHighlight, { languages: { hljsCurl }, ignoreMissing: true }],
],
useDynamicImport: true,
format,
},
})
Expand Down
13 changes: 13 additions & 0 deletions src/pages/docs/apps/[slug]/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import Head from 'next/head'
import SeeAlsoSection from 'components/see-also-section'
import { ParsedUrlQuery } from 'querystring'
import { flattenJSON, getKeyByValue, getParents } from 'utils/navigation-utils'
import { remarkCodeHike } from '@code-hike/mdx'

interface IParams extends ParsedUrlQuery {
slug: string
Expand Down Expand Up @@ -234,6 +235,17 @@ export const getStaticProps: GetStaticProps = async ({ params }) => {
parseFrontmatter: true,
mdxOptions: {
remarkPlugins: [
[
remarkCodeHike,
{
autoImport: false,
showCopyButton: true,
lineNumbers: true,
skipLanguages: ['mermaid'],
staticMediaQuery: 'not screen, (max-width: 850px)',
theme: 'poimandres',
},
],
remarkGFM,
remarkImages,
[getHeadings, { headingList }],
Expand All @@ -242,6 +254,7 @@ export const getStaticProps: GetStaticProps = async ({ params }) => {
rehypePlugins: [
[rehypeHighlight, { languages: { hljsCurl }, ignoreMissing: true }],
],
useDynamicImport: true,
format,
},
})
Expand Down
29 changes: 24 additions & 5 deletions src/pages/docs/guides/[slug].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import rehypeHighlight from 'rehype-highlight'
import hljsCurl from 'highlightjs-curl'
import remarkBlockquote from 'utils/remark_plugins/rehypeBlockquote'
import remarkMermaid from 'utils/remark_plugins/mermaid'

import { remarkCodeHike } from '@code-hike/mdx'
import remarkImages from 'utils/remark_plugins/plaiceholder'

import { Box, Flex, Text } from '@vtex/brand-ui'
Expand Down Expand Up @@ -68,6 +68,7 @@ interface Props {
}
isListed: boolean
branch: string
hideTOC: boolean
}

const DocumentationPage: NextPage<Props> = ({
Expand All @@ -84,6 +85,7 @@ const DocumentationPage: NextPage<Props> = ({
breadcumbList,
branch,
sectionSelected,
hideTOC,
}) => {
const headings: Item[] = headingList
const hidden =
Expand Down Expand Up @@ -151,10 +153,12 @@ const DocumentationPage: NextPage<Props> = ({
<SeeAlsoSection docs={seeAlsoData} />
)}
</Box>
<Box sx={styles.rightContainer}>
<Contributors contributors={contributors} />
<TableOfContents />
</Box>
{!hideTOC && (
<Box sx={styles.rightContainer}>
<Contributors contributors={contributors} />
<TableOfContents />
</Box>
)}
<OnThisPage />
</Flex>
</APIGuideContextProvider>
Expand Down Expand Up @@ -231,6 +235,17 @@ export const getStaticProps: GetStaticProps = async ({
parseFrontmatter: true,
mdxOptions: {
remarkPlugins: [
[
remarkCodeHike,
{
autoImport: false,
showCopyButton: true,
lineNumbers: true,
skipLanguages: ['mermaid'],
staticMediaQuery: 'not screen, (max-width: 850px)',
theme: 'poimandres',
},
],
remarkGFM,
remarkImages,
[getHeadings, { headingList }],
Expand All @@ -240,6 +255,7 @@ export const getStaticProps: GetStaticProps = async ({
rehypePlugins: [
[rehypeHighlight, { languages: { hljsCurl }, ignoreMissing: true }],
],
useDynamicImport: true,
format,
},
})
Expand Down Expand Up @@ -290,6 +306,8 @@ export const getStaticProps: GetStaticProps = async ({
})
)

const hideTOC = serialized.frontmatter?.hideTOC === true

const docsListSlug = jp.query(
sidebarfallback,
`$..[?(@.type=='markdown')]..slug`
Expand Down Expand Up @@ -362,6 +380,7 @@ export const getStaticProps: GetStaticProps = async ({
isListed,
breadcumbList,
branch,
hideTOC,
},
}
} catch (error) {
Expand Down
19 changes: 18 additions & 1 deletion src/pages/updates/release-notes/[slug].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ import { ActionType, getAction } from 'components/last-updates-card/functions'

import styles from 'styles/documentation-page'
import { PreviewContext } from 'utils/contexts/preview'
import { remarkCodeHike } from '@code-hike/mdx'

const docsPathsGLOBAL = await getDocsPaths()

Expand Down Expand Up @@ -179,10 +180,26 @@ export const getStaticProps: GetStaticProps = async ({
let serialized = await serialize(documentationContent, {
parseFrontmatter: true,
mdxOptions: {
remarkPlugins: [remarkGFM, remarkImages, remarkBlockquote],
remarkPlugins: [
[
remarkCodeHike,
{
autoImport: false,
showCopyButton: true,
lineNumbers: true,
skipLanguages: ['mermaid'],
staticMediaQuery: 'not screen, (max-width: 850px)',
theme: 'poimandres',
},
],
remarkGFM,
remarkImages,
remarkBlockquote,
],
rehypePlugins: [
[rehypeHighlight, { languages: { hljsCurl }, ignoreMissing: true }],
],
useDynamicImport: true,
format: 'mdx',
},
})
Expand Down
Loading

0 comments on commit f7a4604

Please sign in to comment.