generated from theodorusclarence/ts-nextjs-tailwind-starter
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
db09505
commit 46ba0c7
Showing
4 changed files
with
73 additions
and
7 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,19 @@ | ||
import { NextRequest, NextResponse } from 'next/server'; | ||
|
||
import { getUrlBySlug } from '@/lib/notion'; | ||
import { getUrlBySlug, incrementLinkCount } from '@/lib/notion'; | ||
|
||
export default async function middleware(req: NextRequest) { | ||
const path = req.nextUrl.pathname.split('/')[1]; | ||
const whitelist = ['favicons', 'fonts', 'images', 'svg', '']; | ||
|
||
const whitelist = ['favicons', 'fonts', 'images', 'svg', '', 'testing']; | ||
if (whitelist.includes(path)) { | ||
return; | ||
} | ||
|
||
const url = await getUrlBySlug(path); | ||
|
||
if (url.link) { | ||
await incrementLinkCount(url); | ||
return NextResponse.redirect(url.link); | ||
} | ||
} |
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,34 @@ | ||
import { InferGetStaticPropsType } from 'next'; | ||
import * as React from 'react'; | ||
|
||
import { getUrlBySlug, incrementLinkCount } from '@/lib/notion'; | ||
|
||
import Layout from '@/components/layout/Layout'; | ||
import Seo from '@/components/Seo'; | ||
|
||
export default function TestingPage({ | ||
link, | ||
}: InferGetStaticPropsType<typeof getStaticProps>) { | ||
return ( | ||
<Layout> | ||
<Seo templateTitle='Testing' /> | ||
|
||
<main> | ||
<section className=''> | ||
<div className='layout py-20 min-h-screen'> | ||
<pre>{JSON.stringify(link, null, 2)}</pre> | ||
</div> | ||
</section> | ||
</main> | ||
</Layout> | ||
); | ||
} | ||
|
||
export const getStaticProps = async () => { | ||
const link = await getUrlBySlug('clarence'); | ||
await incrementLinkCount(link); | ||
|
||
return { | ||
props: { link }, | ||
}; | ||
}; |
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