Skip to content

Commit

Permalink
fix: remove bad skeleton
Browse files Browse the repository at this point in the history
  • Loading branch information
jktrn committed Nov 1, 2023
1 parent ceb42d3 commit 10a7f71
Show file tree
Hide file tree
Showing 9 changed files with 100 additions and 110 deletions.
28 changes: 2 additions & 26 deletions .env.example
Original file line number Diff line number Diff line change
@@ -1,27 +1,3 @@
# visit https://giscus.app to get your Giscus ids
NEXT_PUBLIC_GISCUS_REPO=
NEXT_PUBLIC_GISCUS_REPOSITORY_ID=
NEXT_PUBLIC_GISCUS_CATEGORY=
NEXT_PUBLIC_GISCUS_CATEGORY_ID=
NEXT_PUBLIC_UTTERANCES_REPO=
NEXT_PUBLIC_DISQUS_SHORTNAME=

NEXT_PUBLIC_LANYARD_KV_KEY=

MAILCHIMP_API_KEY=
MAILCHIMP_API_SERVER=
MAILCHIMP_AUDIENCE_ID=

BUTTONDOWN_API_KEY=

CONVERTKIT_API_KEY=
# curl https://api.convertkit.com/v3/forms?api_key=<your_public_api_key> to get your form ID
CONVERTKIT_FORM_ID=

KLAVIYO_API_KEY=
KLAVIYO_LIST_ID=

REVUE_API_KEY=

EMAILOCTOPUS_API_KEY=
EMAILOCTOPUS_LIST_ID=
UPSTASH_REDIS_REST_URL=
UPSTASH_REDIS_REST_TOKEN=
94 changes: 47 additions & 47 deletions LICENSE.content.md

Large diffs are not rendered by default.

3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ All such code in this repository is licensed under the **Apache License 2.0**:
> you may not use this file except in compliance with the License.
> You may obtain a copy of the License at
>
> http://www.apache.org/licenses/LICENSE-2.0
> http://www.apache.org/licenses/LICENSE-2.0
>
> Unless required by applicable law or agreed to in writing, software
> distributed under the License is distributed on an "AS IS" BASIS,
Expand All @@ -71,4 +71,3 @@ Any content not defined above as code, which includes but is not limited to MDX
[Next.js]: https://img.shields.io/github/package-json/dependency-version/jktrn/enscribe.dev/next?color=463f37&logo=next.js&logoColor=fff&style=for-the-badge
[License]: https://img.shields.io/github/license/jktrn/enscribe.dev?color=5d5449&logo=github&logoColor=fff&style=for-the-badge
[Non-Code License]: https://img.shields.io/badge/non--code%20license-CC%20BY--NC--ND%204.0-756a5b?style=for-the-badge&logo=creativecommons&logoColor=fff

43 changes: 20 additions & 23 deletions app/api/incr/route.ts
Original file line number Diff line number Diff line change
@@ -1,42 +1,39 @@
import { Redis } from "@upstash/redis";
import { NextRequest, NextResponse } from "next/server";
import { Redis } from '@upstash/redis'
import { NextRequest, NextResponse } from 'next/server'

const redis = Redis.fromEnv();
export const runtime = "edge";
const redis = Redis.fromEnv()
export const runtime = 'edge'

export async function POST(req: NextRequest): Promise<NextResponse> {
if (req.headers.get("Content-Type") !== "application/json") {
return new NextResponse("content type must be json", { status: 400 });
if (req.headers.get('Content-Type') !== 'application/json') {
return new NextResponse('content type must be json', { status: 400 })
}

const body = await req.json();
let slug: string | undefined = undefined;
const body = await req.json()
let slug: string | undefined = undefined

if ("slug" in body) slug = body.slug;
if ('slug' in body) slug = body.slug

if (!slug) return new NextResponse("slug not found", { status: 400 });
if (!slug) return new NextResponse('slug not found', { status: 400 })

const ip = req.ip;
const ip = req.ip

if (ip) {
const buf = await crypto.subtle.digest(
"SHA-256",
new TextEncoder().encode(ip),
);
const buf = await crypto.subtle.digest('SHA-256', new TextEncoder().encode(ip))
const hash = Array.from(new Uint8Array(buf))
.map((b) => b.toString(16).padStart(2, "0"))
.join("");
.map((b) => b.toString(16).padStart(2, '0'))
.join('')

const isNew = await redis.set(["deduplicate", hash, slug].join(":"), true, {
const isNew = await redis.set(['deduplicate', hash, slug].join(':'), true, {
nx: true,
ex: 24 * 60 * 60,
});
})

if (!isNew) {
new NextResponse(null, { status: 202 });
new NextResponse(null, { status: 202 })
}
}

await redis.incr(["pageviews", "projects", slug].join(":"));
return new NextResponse(null, { status: 202 });
}
await redis.incr(['pageviews', 'projects', slug].join(':'))
return new NextResponse(null, { status: 202 })
}
2 changes: 1 addition & 1 deletion app/blog/[...slug]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import 'katex/dist/katex.css'
import { Metadata } from 'next'
import { MDXLayoutRenderer } from 'pliny/mdx-components'
import { allCoreContent, coreContent, sortPosts } from 'pliny/utils/contentlayer'
import { ReportView } from "./view";
import { ReportView } from './view'

const defaultLayout = 'PostLayout'
const layouts = {
Expand Down
18 changes: 9 additions & 9 deletions app/blog/[...slug]/view.tsx
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
"use client";
'use client'

import { useEffect } from "react";
import { useEffect } from 'react'

export const ReportView: React.FC<{ slug: string }> = ({ slug }) => {
useEffect(() => {
fetch("/api/incr", {
method: "POST",
fetch('/api/incr', {
method: 'POST',
headers: {
"Content-Type": "application/json",
'Content-Type': 'application/json',
},
body: JSON.stringify({ slug }),
});
}, [slug]);
})
}, [slug])

return null;
};
return null
}
4 changes: 4 additions & 0 deletions app/globals.css
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,10 @@ article[style*='--react-activity-calendar-level-0:#ebebeb'] {
@apply hidden;
}

svg[width="1372"] {
@apply hidden;
}

/* <Box> styling */
.my-6.rounded-lg.p-4.bg-secondary.text-center ul {
@apply m-0;
Expand Down
2 changes: 1 addition & 1 deletion data/redirects.js
Original file line number Diff line number Diff line change
Expand Up @@ -139,4 +139,4 @@ module.exports = [
destination: '/blog/wolvctf-2023/wannaflag-series/',
permanent: true,
},
]
]
16 changes: 15 additions & 1 deletion layouts/PostSimple.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import NextImage from 'next/image'
import { CoreContent } from 'pliny/utils/contentlayer'
import { formatDate } from 'pliny/utils/formatDate'
import { ReactNode, useState } from 'react'
import { Redis } from "@upstash/redis"

interface LayoutProps {
content: CoreContent<Blog>
Expand All @@ -22,8 +23,13 @@ interface LayoutProps {
prev?: { path: string; title: string }
}

export default function PostLayout({ content, authorDetails, next, prev, children }: LayoutProps) {
const redis = Redis.fromEnv()

export const revalidate = 60

export default async function PostLayout({ content, authorDetails, next, prev, children }: LayoutProps) {
const { path, slug, tags, date, title, thumbnail } = content
const views = (await redis.get<number>(["pageviews", "projects", slug].join(":"))) ?? 0;
const displayThumbnail = thumbnail ? thumbnail : '/static/images/twitter-card.png'
const [isLoading, setIsLoading] = useState(true)

Expand Down Expand Up @@ -61,6 +67,14 @@ export default function PostLayout({ content, authorDetails, next, prev, childre
<time dateTime={date}>
{formatDate(date, siteMetadata.locale)}
</time>
{views > 0 && (
<span className="ml-2">
<span className="text-primary">
{views.toLocaleString()}
</span>{" "}
views
</span>
)}
</dd>
</div>
</dl>
Expand Down

0 comments on commit 10a7f71

Please sign in to comment.