Skip to content
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

feat/get-docs #18

Merged
merged 18 commits into from
Jan 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions netlify.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
[functions]
external_node_modules = ["sharp"]
included_files = ["node_modules/sharp/**/*", "./github.pem"]

[[plugins]]
package = "@netlify/plugin-nextjs"
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@
"devDependencies": {
"@commitlint/cli": "^16.2.1",
"@commitlint/config-conventional": "^16.2.1",
"@netlify/plugin-nextjs": "^4.41.3",
"@types/jsonpath": "^0.2.0",
"@types/node": "17.0.21",
"@types/react": "17.0.39",
Expand Down
12 changes: 4 additions & 8 deletions src/components/article-pagination/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,27 +4,25 @@ interface Props {
pagination: {
previousDoc: {
slug: string | null
name: { en: string; pt: string; es: string } | null
name: string | null
}
nextDoc: {
slug: string | null
name: { en: string; pt: string; es: string } | null
name: string | null
}
}
hidePaginationPrevious: boolean
hidePaginationNext: boolean
}

import styles from './styles'
import { useIntl } from 'react-intl'

const ArticlePagination = ({
pagination,
hidePaginationNext,
hidePaginationPrevious,
}: Props) => {
const router = useRouter()
const locale = useIntl().locale as 'en' | 'pt' | 'es'

const handleClick = (e: { preventDefault: () => void }, slug: string) => {
e.preventDefault()
Expand All @@ -43,7 +41,7 @@ const ArticlePagination = ({
>
<Box sx={styles.paginationBox}>
<Text sx={styles.paginationText}>
{pagination.previousDoc.name?.[locale]}
{pagination.previousDoc.name}
</Text>
<Text sx={styles.subTitle}>« Previous</Text>
</Box>
Expand All @@ -58,9 +56,7 @@ const ArticlePagination = ({
}}
>
<Box sx={styles.paginationBox}>
<Text sx={styles.paginationText}>
{pagination.nextDoc.name?.[locale]}
</Text>
<Text sx={styles.paginationText}>{pagination.nextDoc.name}</Text>
<Text sx={styles.subTitle}>Next »</Text>
</Box>
</Link>
Expand Down
36 changes: 36 additions & 0 deletions src/components/error-boundary/index.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import { useRouter } from 'next/router'
import { Component } from 'react'
import FiveHundredPage from 'pages/500'

import { getLogger } from 'utils/logging/log-util'

export class ErrorBoundary extends Component {
constructor(props) {
super(props)
this.state = { hasError: false }
}

static getDerivedStateFromError() {
return { hasError: true }
}

componentDidCatch(error, errorInfo) {
console.log(error, errorInfo)
}

render() {
if (this.state.hasError) {
return <FiveHundredPage branch="main" />
}

return this.props.children
}
}

export const SuspenseFallback = (branch) => {
const { asPath } = useRouter()
const logger = getLogger('Suspense Fallback')
logger.error(`Error while processing ${asPath}`)

return <FiveHundredPage branch={branch} />
}
4 changes: 2 additions & 2 deletions src/pages/500.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ interface Props {
branch: string
}

const fiveHundredPage: Page<Props> = ({ branch }) => {
const FiveHundredPage: Page<Props> = ({ branch }) => {
const { setBranchPreview } = useContext(PreviewContext)
setBranchPreview(branch)

Expand Down Expand Up @@ -73,4 +73,4 @@ export const getStaticProps: GetStaticProps = async ({
}
}

export default fiveHundredPage
export default FiveHundredPage
10 changes: 9 additions & 1 deletion src/pages/_app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ import Layout from 'components/layout'
type Props = AppProps & {
Component: Page
}
import { ErrorBoundary, SuspenseFallback } from 'components/error-boundary'
import { Suspense } from 'react'

import TrackerProvider from 'utils/contexts/trackerContext'
import PreviewContextProvider from 'utils/contexts/preview'
Expand All @@ -40,7 +42,13 @@ function MyApp({ Component, pageProps }: Props) {
sectionSelected={pageProps.sectionSelected}
parentsArray={pageProps.parentsArray}
>
<Component {...pageProps} />
<ErrorBoundary>
<Suspense
fallback={<SuspenseFallback branch={pageProps.branch} />}
>
<Component {...pageProps} />
</Suspense>
</ErrorBoundary>
</Layout>
</PreviewContextProvider>
</IntlProvider>
Expand Down
4 changes: 2 additions & 2 deletions src/pages/api/docs.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import getDocsPaths from 'utils/getDocsPaths'
import { getAllDocsPaths } from 'utils/getDocsPaths'
//eslint-disable-next-line @typescript-eslint/no-explicit-any
export default async function handler(req: any, res: any) {
req = req
res.status(200).json(await getDocsPaths())
res.status(200).json(await getAllDocsPaths())
}
15 changes: 15 additions & 0 deletions src/pages/api/revalidate.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// eslint-disable-next-line @typescript-eslint/no-explicit-any
export default async function handler(req: any, res: any) {
if (req.query.secret !== process.env.REVALIDATE_SECRET) {
return res.status(401).json({ message: 'Invalid token' })
}

try {
if (req.query.url) {
await res.revalidate(req.query.url)
return res.json({ revalidated: true })
}
} catch (err) {
return res.status(500).send('Error revalidating')
}
}
Loading
Loading