Skip to content

Commit

Permalink
feat: add Incremental Static Regeneration
Browse files Browse the repository at this point in the history
  • Loading branch information
RobsonOlv committed Jan 9, 2024
1 parent 4471a4c commit b344dd8
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 50 deletions.
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')
}
}
35 changes: 18 additions & 17 deletions src/pages/docs/tracks/[slug].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ import {
localeType,
} from 'utils/navigation-utils'
import { MarkdownRenderer } from '@vtexdocs/components'
import { ParsedUrlQuery } from 'querystring'
// import { ParsedUrlQuery } from 'querystring'

const docsPathsGLOBAL = await getTracksPaths('tracks')

Expand Down Expand Up @@ -166,23 +166,23 @@ const TrackPage: NextPage<Props> = ({
}

export const getStaticPaths: GetStaticPaths = async () => {
const slugs: { [slug: string]: { locale: string; path: string }[] } =
await getTracksPaths('tracks')

const paths: (
| string
| {
params: ParsedUrlQuery
locale?: string | undefined
}
)[] = []
Object.entries(slugs).forEach(([slug, locales]) => {
locales.forEach(({ locale }) => {
paths.push({ params: { slug }, locale })
})
})
// const slugs: { [slug: string]: { locale: string; path: string }[] } =
// await getTracksPaths('tracks')

// const paths: (
// | string
// | {
// params: ParsedUrlQuery
// locale?: string | undefined
// }
// )[] = []
// Object.entries(slugs).forEach(([slug, locales]) => {
// locales.forEach(({ locale }) => {
// paths.push({ params: { slug }, locale })
// })
// })
return {
paths,
paths: [],
fallback: 'blocking',
}
}
Expand Down Expand Up @@ -439,6 +439,7 @@ export const getStaticProps: GetStaticProps = async ({
breadcrumbList,
branch,
},
revalidate: 600,
}
} catch (error) {
logger.error(`Error while processing ${path}\n${error}`)
Expand Down
33 changes: 17 additions & 16 deletions src/pages/docs/tutorial/[slug].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ import {
getParents,
localeType,
} from 'utils/navigation-utils'
import { ParsedUrlQuery } from 'querystring'
// import { ParsedUrlQuery } from 'querystring'

const docsPathsGLOBAL = await getTutorialsPaths('tutorials')

Expand Down Expand Up @@ -166,23 +166,23 @@ const TutorialPage: NextPage<Props> = ({
}

export const getStaticPaths: GetStaticPaths = async () => {
const slugs: { [slug: string]: { locale: string; path: string }[] } =
await getTutorialsPaths('tutorials')
// const slugs: { [slug: string]: { locale: string; path: string }[] } =
// await getTutorialsPaths('tutorials')

const paths: (
| string
| {
params: ParsedUrlQuery
locale?: string | undefined
}
)[] = []
Object.entries(slugs).forEach(([slug, locales]) => {
locales.forEach(({ locale }) => {
paths.push({ params: { slug }, locale })
})
})
// const paths: (
// | string
// | {
// params: ParsedUrlQuery
// locale?: string | undefined
// }
// )[] = []
// Object.entries(slugs).forEach(([slug, locales]) => {
// locales.forEach(({ locale }) => {
// paths.push({ params: { slug }, locale })
// })
// })
return {
paths,
paths: [],
fallback: 'blocking',
}
}
Expand Down Expand Up @@ -436,6 +436,7 @@ export const getStaticProps: GetStaticProps = async ({
breadcrumbList,
branch,
},
revalidate: 600,
}
} catch (error) {
logger.error(`Error while processing ${path}\n${error}`)
Expand Down
34 changes: 17 additions & 17 deletions src/pages/updates/announcements/[slug].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ import { ActionType, getAction } from 'components/announcement-card/functions'

import styles from 'styles/documentation-page'
import { PreviewContext } from 'utils/contexts/preview'
import { ParsedUrlQuery } from 'querystring'
// import { ParsedUrlQuery } from 'querystring'

const docsPathsGLOBAL = await getNewsPaths('announcements')

Expand Down Expand Up @@ -126,24 +126,24 @@ const NewsPage: NextPage<Props> = ({ serialized, branch }) => {
}

export const getStaticPaths: GetStaticPaths = async () => {
const slugs: { [slug: string]: { locale: string; path: string }[] } =
await getNewsPaths('announcements')

const paths: (
| string
| {
params: ParsedUrlQuery
locale?: string | undefined
}
)[] = []
Object.entries(slugs).forEach(([slug, locales]) => {
locales.forEach(({ locale }) => {
paths.push({ params: { slug }, locale })
})
})
// const slugs: { [slug: string]: { locale: string; path: string }[] } =
// await getNewsPaths('announcements')

// const paths: (
// | string
// | {
// params: ParsedUrlQuery
// locale?: string | undefined
// }
// )[] = []
// Object.entries(slugs).forEach(([slug, locales]) => {
// locales.forEach(({ locale }) => {
// paths.push({ params: { slug }, locale })
// })
// })

return {
paths,
paths: [],
fallback: 'blocking',
}
}
Expand Down

0 comments on commit b344dd8

Please sign in to comment.