Skip to content

Commit

Permalink
Fix build on vercel not working (#42)
Browse files Browse the repository at this point in the history
  • Loading branch information
timomeh committed Mar 10, 2024
1 parent 10a991d commit 9c2f88a
Show file tree
Hide file tree
Showing 15 changed files with 359 additions and 347 deletions.
5 changes: 1 addition & 4 deletions package.json
Expand Up @@ -9,9 +9,8 @@
"lint": "next lint"
},
"dependencies": {
"@octokit/core": "6.0.1",
"@octokit/graphql": "8.0.1",
"@octokit/graphql-schema": "15.2.0",
"@octokit/plugin-paginate-graphql": "4.0.1",
"@octokit/webhooks": "13.0.2",
"@octokit/webhooks-types": "7.3.2",
"@plaiceholder/next": "3.0.0",
Expand All @@ -28,10 +27,8 @@
"next": "14.1.2",
"next-mdx-remote": "4.4.1",
"next-nprogress-bar": "2.3.4",
"nextjs-better-unstable-cache": "1.0.0",
"plaiceholder": "3.0.0",
"postcss-url": "10.1.3",
"prando": "6.0.1",
"react": "18.2.0",
"react-dom": "18.2.0",
"reading-time": "1.5.0",
Expand Down
68 changes: 8 additions & 60 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions src/app/(list)/tag/[tag]/page.tsx
Expand Up @@ -5,6 +5,12 @@ import { getTag } from '@/lib/blog'

import { PostList } from '../../post-list'

export const dynamic = 'force-static'
export const dynamicParams = true
export function generateStaticParams() {
return []
}

type Props = {
params: {
tag: string
Expand Down
6 changes: 6 additions & 0 deletions src/app/(static)/[slug]/page.tsx
Expand Up @@ -5,6 +5,12 @@ import { MDX } from '@/comps/mdx/mdx'

import { getSite } from './getSite'

export const dynamic = 'force-static'
export const dynamicParams = true
export function generateStaticParams() {
return []
}

type Props = {
params: {
slug: string
Expand Down
2 changes: 1 addition & 1 deletion src/app/@nextPost/posts/[slug]/page.tsx
@@ -1,5 +1,5 @@
import { PostPreview } from '@/comps/post-preview'
import { getRelatedPosts } from '@/util/related-posts'
import { getRelatedPosts } from '@/lib/blog'

import { ScrollAway } from './scroll-away'

Expand Down
2 changes: 1 addition & 1 deletion src/app/@prevPost/posts/[slug]/page.tsx
@@ -1,5 +1,5 @@
import { PostPreview } from '@/comps/post-preview'
import { getRelatedPosts } from '@/util/related-posts'
import { getRelatedPosts } from '@/lib/blog'

type Props = {
params: { slug: string }
Expand Down
6 changes: 6 additions & 0 deletions src/app/posts/[slug]/page.tsx
Expand Up @@ -5,6 +5,12 @@ import { MDX } from '@/comps/mdx/mdx'
import { PostHeader } from '@/comps/post-header'
import { getPost } from '@/lib/blog'

export const dynamic = 'force-static'
export const dynamicParams = true
export function generateStaticParams() {
return []
}

type Props = {
params: { slug: string }
}
Expand Down
65 changes: 39 additions & 26 deletions src/app/webhooks/github/route.ts
Expand Up @@ -14,7 +14,7 @@ import {
import { revalidateTag } from 'next/cache'
import { NextRequest, NextResponse } from 'next/server'

import { labelNameToSlug } from '@/lib/blog'
import { cacheTag } from '@/lib/cache-tags'
import { fetchDiscussion, isAllowedCategory, isTag } from '@/lib/github'

export async function POST(request: NextRequest) {
Expand Down Expand Up @@ -94,20 +94,21 @@ async function onLabelEvent(body: string) {
// Only if a discussion gets labeled.
}

if (data.action === 'deleted' && isTag(data.label.name)) {
// When a label-tag was deleted, the list of labels has changed
revalidateTag('github/labels')
if (data.action === 'deleted') {
// Deleting a label has no effect on the blog.
// The label will be removed from the discussion, which is handled in a
// separate event.
}

if (data.action === 'edited') {
if (data.changes?.name?.from && isTag(data.changes.name.from)) {
// When the name of a label-tag changed, the list of labels has changed
revalidateTag('github/labels')
revalidateTags(cacheTag.labels.list())
}

if (isTag(data.label.name)) {
// The label-tag has changed
revalidateTag(`github/label/${labelNameToSlug(data.label.name)}`)
revalidateTags(cacheTag.labels.get(data.label.name))
}
}
}
Expand Down Expand Up @@ -143,13 +144,15 @@ async function onDiscussionEvent(body: string) {
// discussions is affected, as well as the labeled lists.
const discussion = await fetchDiscussion(data.discussion.title)
discussion?.labels?.nodes?.forEach((label) => {
if (label) revalidateTag(`github/discussions/labeled:${label.name}`)
if (label && isTag(label.name)) {
revalidateTags(cacheTag.discussions.list({ label: label.name }))
}
})
revalidateTag('github/discussions/all')
revalidateTag(`github/discussion/${data.discussion.title}`)
revalidateTags(cacheTag.discussions.list())
revalidateTags(cacheTag.discussions.get(data.discussion.title))

// A new/removed post can affect the order of labels
revalidateTag('github/labels')
revalidateTags(cacheTag.labels.list())
}

if (data.action === 'created') {
Expand All @@ -159,12 +162,14 @@ async function onDiscussionEvent(body: string) {
// as well as the labeled lists.
const discussion = await fetchDiscussion(data.discussion.title)
discussion?.labels?.nodes?.forEach((label) => {
if (label) revalidateTag(`github/discussions/labeled:${label.name}`)
if (label && isTag(label.name)) {
revalidateTags(cacheTag.discussions.list({ label: label.name }))
}
})
revalidateTag('github/discussions/all')
revalidateTags(cacheTag.discussions.list())

// A new post can affect the order of labels
revalidateTag('github/labels')
revalidateTags(cacheTag.labels.list())
}

if (data.action === 'deleted') {
Expand All @@ -174,13 +179,15 @@ async function onDiscussionEvent(body: string) {
// as well as the labeled lists.
const discussion = await fetchDiscussion(data.discussion.title)
discussion?.labels?.nodes?.forEach((label) => {
if (label) revalidateTag(`github/discussions/labeled:${label.name}`)
if (label && isTag(label.name)) {
revalidateTags(cacheTag.discussions.list({ label: label.name }))
}
})
revalidateTag('github/discussions/all')
revalidateTag(`github/discussion/${data.discussion.title}`)
revalidateTags(cacheTag.discussions.list())
revalidateTags(cacheTag.discussions.get(data.discussion.title))

// A removed post can affect the order of labels
revalidateTag('github/labels')
revalidateTags(cacheTag.labels.list())
}

if (data.action === 'edited') {
Expand All @@ -191,35 +198,41 @@ async function onDiscussionEvent(body: string) {
// the list of all discussions, as well as the labeled lists.
const discussion = await fetchDiscussion(data.discussion.title)
discussion?.labels?.nodes?.forEach((label) => {
if (label) revalidateTag(`github/discussions/labeled:${label.name}`)
if (label && isTag(label.name)) {
revalidateTags(cacheTag.discussions.list({ label: label.name }))
}
})
revalidateTag('github/discussions/all')
revalidateTags(cacheTag.discussions.list())
}

revalidateTag(`github/discussion/${data.discussion.title}`)
revalidateTags(cacheTag.discussions.get(data.discussion.title))
}

if (data.action === 'labeled') {
if (!isAllowedCategory(data.discussion.category.slug)) return

// When a discussion is labeled, it affects the list labeled list, as well
// as of course the dicussion itself.
revalidateTag(`github/discussions/labeled:${data.label.name}`)
revalidateTag(`github/discussion/${data.discussion.title}`)
revalidateTags(cacheTag.discussions.list({ label: data.label.name }))
revalidateTags(cacheTag.discussions.get(data.discussion.title))

// Adding a label to a post can affect the order of labels
revalidateTag('github/labels')
revalidateTags(cacheTag.labels.list())
}

if (data.action === 'unlabeled') {
if (!isAllowedCategory(data.discussion.category.slug)) return

// When a discussion is unlabeled, it affects the list labeled list, as well
// as of course the dicussion itself.
revalidateTag(`github/discussions/labeled:${data.label.name}`)
revalidateTag(`post/slug:${data.discussion.title}`)
revalidateTags(cacheTag.discussions.list({ label: data.label.name }))
revalidateTags(cacheTag.discussions.get(data.discussion.title))

// Removing a label from a post can affect the order of labels
revalidateTag('github/labels')
revalidateTags(cacheTag.labels.list())
}
}

function revalidateTags(tags: string[]) {
tags.forEach((tag) => revalidateTag(tag))
}

0 comments on commit 9c2f88a

Please sign in to comment.