diff --git a/.contentlayer/.cache/v0.3.0/compiled-contentlayer-config-AAEZAM7W.mjs b/.contentlayer/.cache/v0.3.0/compiled-contentlayer-config-AAEZAM7W.mjs index 12aed14..88ebb53 100644 --- a/.contentlayer/.cache/v0.3.0/compiled-contentlayer-config-AAEZAM7W.mjs +++ b/.contentlayer/.cache/v0.3.0/compiled-contentlayer-config-AAEZAM7W.mjs @@ -5,93 +5,97 @@ import rehypePrettyCode from "rehype-pretty-code"; import rehypeSlug from "rehype-slug"; import rehypeAutolinkHeadings from "rehype-autolink-headings"; var computedFields = { - path: { - type: "string", - resolve: (doc) => `/${doc._raw.flattenedPath}`, - }, - slug: { - type: "string", - resolve: (doc) => doc._raw.flattenedPath.split("/").slice(1).join("/"), - }, + path: { + type: "string", + resolve: (doc) => `/${doc._raw.flattenedPath}` + }, + slug: { + type: "string", + resolve: (doc) => doc._raw.flattenedPath.split("/").slice(1).join("/") + } }; var Project = defineDocumentType(() => ({ - name: "Project", - filePathPattern: "./projects/**/*.mdx", - contentType: "mdx", - fields: { - published: { - type: "boolean", - }, - title: { - type: "string", - required: true, - }, - description: { - type: "string", - required: true, - }, - date: { - type: "date", - }, - url: { - type: "string", - }, - repository: { - type: "string", - }, - }, - computedFields, + name: "Project", + filePathPattern: "./projects/**/*.mdx", + contentType: "mdx", + fields: { + published: { + type: "boolean" + }, + title: { + type: "string", + required: true + }, + description: { + type: "string", + required: true + }, + date: { + type: "date" + }, + url: { + type: "string" + }, + repository: { + type: "string" + } + }, + computedFields })); var Page = defineDocumentType(() => ({ - name: "Page", - filePathPattern: "pages/**/*.mdx", - contentType: "mdx", - fields: { - title: { - type: "string", - required: true, - }, - description: { - type: "string", - }, - }, - computedFields, + name: "Page", + filePathPattern: "pages/**/*.mdx", + contentType: "mdx", + fields: { + title: { + type: "string", + required: true + }, + description: { + type: "string" + } + }, + computedFields })); var contentlayer_config_default = makeSource({ - contentDirPath: "./content", - documentTypes: [Page, Project], - mdx: { - remarkPlugins: [remarkGfm], - rehypePlugins: [ - rehypeSlug, - [ - rehypePrettyCode, - { - theme: "github-dark", - onVisitLine(node) { - if (node.children.length === 0) { - node.children = [{ type: "text", value: " " }]; - } - }, - onVisitHighlightedLine(node) { - node.properties.className.push("line--highlighted"); - }, - onVisitHighlightedWord(node) { - node.properties.className = ["word--highlighted"]; - }, - }, - ], - [ - rehypeAutolinkHeadings, - { - properties: { - className: ["subheading-anchor"], - ariaLabel: "Link to section", - }, - }, - ], - ], - }, + contentDirPath: "./content", + documentTypes: [Page, Project], + mdx: { + remarkPlugins: [remarkGfm], + rehypePlugins: [ + rehypeSlug, + [ + rehypePrettyCode, + { + theme: "github-dark", + onVisitLine(node) { + if (node.children.length === 0) { + node.children = [{ type: "text", value: " " }]; + } + }, + onVisitHighlightedLine(node) { + node.properties.className.push("line--highlighted"); + }, + onVisitHighlightedWord(node) { + node.properties.className = ["word--highlighted"]; + } + } + ], + [ + rehypeAutolinkHeadings, + { + properties: { + className: ["subheading-anchor"], + ariaLabel: "Link to section" + } + } + ] + ] + } }); -export { Page, Project, contentlayer_config_default as default }; +export { + Page, + Project, + contentlayer_config_default as default +}; //# sourceMappingURL=compiled-contentlayer-config-AAEZAM7W.mjs.map diff --git a/.contentlayer/generated/Page/_index.mjs b/.contentlayer/generated/Page/_index.mjs index 666b015..10fe12c 100644 --- a/.contentlayer/generated/Page/_index.mjs +++ b/.contentlayer/generated/Page/_index.mjs @@ -1,3 +1,5 @@ // NOTE This file is auto-generated by Contentlayer -export const allPages = []; + + +export const allPages = [] diff --git a/.contentlayer/generated/Project/_index.mjs b/.contentlayer/generated/Project/_index.mjs index 6ffbf81..2cca3fe 100644 --- a/.contentlayer/generated/Project/_index.mjs +++ b/.contentlayer/generated/Project/_index.mjs @@ -1,65 +1,19 @@ // NOTE This file is auto-generated by Contentlayer -import projects__accessMdx from "./projects__access.mdx.json" assert { - type: "json", -}; -import projects__envshareMdx from "./projects__envshare.mdx.json" assert { - type: "json", -}; -import projects__planetfallMdx from "./projects__planetfall.mdx.json" assert { - type: "json", -}; -import projects__qstashMdx from "./projects__qstash.mdx.json" assert { - type: "json", -}; -import projects__terraformProviderVercelMdx from "./projects__terraform-provider-vercel.mdx.json" assert { - type: "json", -}; -import projects__upstashAuthAnalyticsMdx from "./projects__upstash-auth-analytics.mdx.json" assert { - type: "json", -}; -import projects__upstashCliMdx from "./projects__upstash-cli.mdx.json" assert { - type: "json", -}; -import projects__upstashCoreAnalyticsMdx from "./projects__upstash-core-analytics.mdx.json" assert { - type: "json", -}; -import projects__upstashEdgeFlagsMdx from "./projects__upstash-edge-flags.mdx.json" assert { - type: "json", -}; -import projects__upstashKafkaMdx from "./projects__upstash-kafka.mdx.json" assert { - type: "json", -}; -import projects__upstashQstashSdkMdx from "./projects__upstash-qstash-sdk.mdx.json" assert { - type: "json", -}; -import projects__upstashRatelimitMdx from "./projects__upstash-ratelimit.mdx.json" assert { - type: "json", -}; -import projects__upstashReactUiMdx from "./projects__upstash-react-ui.mdx.json" assert { - type: "json", -}; -import projects__upstashRedisMdx from "./projects__upstash-redis.mdx.json" assert { - type: "json", -}; -import projects__upstashWebAnalyticsMdx from "./projects__upstash-web-analytics.mdx.json" assert { - type: "json", -}; +import projects__accessMdx from './projects__access.mdx.json' assert { type: 'json' } +import projects__envshareMdx from './projects__envshare.mdx.json' assert { type: 'json' } +import projects__planetfallMdx from './projects__planetfall.mdx.json' assert { type: 'json' } +import projects__qstashMdx from './projects__qstash.mdx.json' assert { type: 'json' } +import projects__terraformProviderVercelMdx from './projects__terraform-provider-vercel.mdx.json' assert { type: 'json' } +import projects__upstashAuthAnalyticsMdx from './projects__upstash-auth-analytics.mdx.json' assert { type: 'json' } +import projects__upstashCliMdx from './projects__upstash-cli.mdx.json' assert { type: 'json' } +import projects__upstashCoreAnalyticsMdx from './projects__upstash-core-analytics.mdx.json' assert { type: 'json' } +import projects__upstashEdgeFlagsMdx from './projects__upstash-edge-flags.mdx.json' assert { type: 'json' } +import projects__upstashKafkaMdx from './projects__upstash-kafka.mdx.json' assert { type: 'json' } +import projects__upstashQstashSdkMdx from './projects__upstash-qstash-sdk.mdx.json' assert { type: 'json' } +import projects__upstashRatelimitMdx from './projects__upstash-ratelimit.mdx.json' assert { type: 'json' } +import projects__upstashReactUiMdx from './projects__upstash-react-ui.mdx.json' assert { type: 'json' } +import projects__upstashRedisMdx from './projects__upstash-redis.mdx.json' assert { type: 'json' } +import projects__upstashWebAnalyticsMdx from './projects__upstash-web-analytics.mdx.json' assert { type: 'json' } -export const allProjects = [ - projects__accessMdx, - projects__envshareMdx, - projects__planetfallMdx, - projects__qstashMdx, - projects__terraformProviderVercelMdx, - projects__upstashAuthAnalyticsMdx, - projects__upstashCliMdx, - projects__upstashCoreAnalyticsMdx, - projects__upstashEdgeFlagsMdx, - projects__upstashKafkaMdx, - projects__upstashQstashSdkMdx, - projects__upstashRatelimitMdx, - projects__upstashReactUiMdx, - projects__upstashRedisMdx, - projects__upstashWebAnalyticsMdx, -]; +export const allProjects = [projects__accessMdx, projects__envshareMdx, projects__planetfallMdx, projects__qstashMdx, projects__terraformProviderVercelMdx, projects__upstashAuthAnalyticsMdx, projects__upstashCliMdx, projects__upstashCoreAnalyticsMdx, projects__upstashEdgeFlagsMdx, projects__upstashKafkaMdx, projects__upstashQstashSdkMdx, projects__upstashRatelimitMdx, projects__upstashReactUiMdx, projects__upstashRedisMdx, projects__upstashWebAnalyticsMdx] diff --git a/.contentlayer/generated/index.d.ts b/.contentlayer/generated/index.d.ts index 5b3de12..5759d7b 100644 --- a/.contentlayer/generated/index.d.ts +++ b/.contentlayer/generated/index.d.ts @@ -1,10 +1,11 @@ // NOTE This file is auto-generated by Contentlayer -import { Page, Project, DocumentTypes } from "./types"; +import { Page, Project, DocumentTypes } from './types' -export * from "./types"; +export * from './types' -export declare const allPages: Page[]; -export declare const allProjects: Project[]; +export declare const allPages: Page[] +export declare const allProjects: Project[] + +export declare const allDocuments: DocumentTypes[] -export declare const allDocuments: DocumentTypes[]; diff --git a/.contentlayer/generated/index.mjs b/.contentlayer/generated/index.mjs index 301efc4..d181467 100644 --- a/.contentlayer/generated/index.mjs +++ b/.contentlayer/generated/index.mjs @@ -1,12 +1,12 @@ // NOTE This file is auto-generated by Contentlayer -export { isType } from "contentlayer/client"; +export { isType } from 'contentlayer/client' // NOTE During development Contentlayer imports from `.mjs` files to improve HMR speeds. // During (production) builds Contentlayer it imports from `.json` files to improve build performance. -import allPages from "./Page/_index.json" assert { type: "json" }; -import allProjects from "./Project/_index.json" assert { type: "json" }; +import { allPages } from './Page/_index.mjs' +import { allProjects } from './Project/_index.mjs' -export { allPages, allProjects }; +export { allPages, allProjects } -export const allDocuments = [...allPages, ...allProjects]; +export const allDocuments = [...allPages, ...allProjects] diff --git a/.contentlayer/generated/types.d.ts b/.contentlayer/generated/types.d.ts index e718afa..787e9fd 100644 --- a/.contentlayer/generated/types.d.ts +++ b/.contentlayer/generated/types.d.ts @@ -1,78 +1,79 @@ // NOTE This file is auto-generated by Contentlayer -import type { - Markdown, - MDX, - ImageFieldData, - IsoDateTimeString, -} from "contentlayer/core"; -import * as Local from "contentlayer/source-files"; +import type { Markdown, MDX, ImageFieldData, IsoDateTimeString } from 'contentlayer/core' +import * as Local from 'contentlayer/source-files' -export { isType } from "contentlayer/client"; +export { isType } from 'contentlayer/client' -export type { Markdown, MDX, ImageFieldData, IsoDateTimeString }; +export type { Markdown, MDX, ImageFieldData, IsoDateTimeString } /** Document types */ export type Page = { - /** File path relative to `contentDirPath` */ - _id: string; - _raw: Local.RawDocumentData; - type: "Page"; - title: string; - description?: string | undefined; - /** MDX file body */ - body: MDX; - path: string; - slug: string; -}; + /** File path relative to `contentDirPath` */ + _id: string + _raw: Local.RawDocumentData + type: 'Page' + title: string + description?: string | undefined + /** MDX file body */ + body: MDX + path: string + slug: string +} export type Project = { - /** File path relative to `contentDirPath` */ - _id: string; - _raw: Local.RawDocumentData; - type: "Project"; - published?: boolean | undefined; - title: string; - description: string; - date?: IsoDateTimeString | undefined; - url?: string | undefined; - repository?: string | undefined; - /** MDX file body */ - body: MDX; - path: string; - slug: string; -}; + /** File path relative to `contentDirPath` */ + _id: string + _raw: Local.RawDocumentData + type: 'Project' + published?: boolean | undefined + title: string + description: string + date?: IsoDateTimeString | undefined + url?: string | undefined + repository?: string | undefined + /** MDX file body */ + body: MDX + path: string + slug: string +} /** Nested types */ + /** Helper types */ -export type AllTypes = DocumentTypes | NestedTypes; -export type AllTypeNames = DocumentTypeNames | NestedTypeNames; +export type AllTypes = DocumentTypes | NestedTypes +export type AllTypeNames = DocumentTypeNames | NestedTypeNames -export type DocumentTypes = Page | Project; -export type DocumentTypeNames = "Page" | "Project"; +export type DocumentTypes = Page | Project +export type DocumentTypeNames = 'Page' | 'Project' + +export type NestedTypes = never +export type NestedTypeNames = never -export type NestedTypes = never; -export type NestedTypeNames = never; export interface ContentlayerGenTypes { - documentTypes: DocumentTypes; - documentTypeMap: DocumentTypeMap; - documentTypeNames: DocumentTypeNames; - nestedTypes: NestedTypes; - nestedTypeMap: NestedTypeMap; - nestedTypeNames: NestedTypeNames; - allTypeNames: AllTypeNames; + documentTypes: DocumentTypes + documentTypeMap: DocumentTypeMap + documentTypeNames: DocumentTypeNames + nestedTypes: NestedTypes + nestedTypeMap: NestedTypeMap + nestedTypeNames: NestedTypeNames + allTypeNames: AllTypeNames } declare global { - interface ContentlayerGen extends ContentlayerGenTypes {} + interface ContentlayerGen extends ContentlayerGenTypes {} } export type DocumentTypeMap = { - Page: Page; - Project: Project; -}; + Page: Page + Project: Project +} -export type NestedTypeMap = {}; +export type NestedTypeMap = { + +} + + \ No newline at end of file diff --git a/app/components/card.tsx b/app/components/card.tsx index 6d6565f..07adfc7 100644 --- a/app/components/card.tsx +++ b/app/components/card.tsx @@ -9,8 +9,8 @@ import { import { MouseEventHandler, PropsWithChildren } from "react"; export const Card: React.FC = ({ children }) => { - const mouseX = useSpring(0, { stiffness: 200, damping: 100 }); - const mouseY = useSpring(0, { stiffness: 200, damping: 100 }); + const mouseX = useSpring(0, { stiffness: 500, damping: 100 }); + const mouseY = useSpring(0, { stiffness: 500, damping: 100 }); function onMouseMove({ currentTarget, clientX, clientY }: any) { const { left, top } = currentTarget.getBoundingClientRect(); @@ -23,7 +23,7 @@ export const Card: React.FC = ({ children }) => { return (
diff --git a/app/favicon.ico b/app/favicon.ico deleted file mode 100644 index 718d6fe..0000000 Binary files a/app/favicon.ico and /dev/null differ diff --git a/app/layout.tsx b/app/layout.tsx index 156a319..d44b028 100644 --- a/app/layout.tsx +++ b/app/layout.tsx @@ -7,10 +7,11 @@ export const metadata: Metadata = { default: "chronark.com", template: "%s | chronark.com", }, - description: "software engineer at Upstash and founder of planetfall.io", + description: "Software engineer at upstash.com and founder of planetfall.io", openGraph: { title: "chronark.com", - description: "software engineer at Upstash and founder of planetfall.io", + description: + "Software engineer at upstash.com and founder of planetfall.io", url: "https://chronark.com", siteName: "chronark.com", images: [ diff --git a/app/projects/[slug]/page.tsx b/app/projects/[slug]/page.tsx index 6459833..f571ef8 100644 --- a/app/projects/[slug]/page.tsx +++ b/app/projects/[slug]/page.tsx @@ -3,6 +3,7 @@ import { allProjects } from "contentlayer/generated"; import { Mdx } from "@/app/components/mdx"; import { Header } from "./header"; import "./mdx.css"; +import { ReportView } from "./view"; type Props = { params: { @@ -29,6 +30,7 @@ export default async function PostPage({ params }: Props) { return (
+
diff --git a/app/projects/[slug]/view.tsx b/app/projects/[slug]/view.tsx new file mode 100644 index 0000000..8b74e14 --- /dev/null +++ b/app/projects/[slug]/view.tsx @@ -0,0 +1,17 @@ +"use client"; + +import { useEffect } from "react"; + +export const ReportView: React.FC<{ slug: string }> = ({ slug }) => { + useEffect(() => { + fetch("/api/incr", { + method: "POST", + headers: { + "Content-Type": "application/json", + }, + body: JSON.stringify({ slug }), + }); + }, [slug]); + + return null; +}; diff --git a/app/projects/page.tsx b/app/projects/page.tsx index ee25dab..ad2ec0b 100644 --- a/app/projects/page.tsx +++ b/app/projects/page.tsx @@ -75,7 +75,7 @@ export default function ProjectsPage() { -
+
{[top2, top3].map((project) => (
@@ -85,7 +85,7 @@ export default function ProjectsPage() {
-
+
{sorted .filter((_, i) => i % 3 === 0) diff --git a/middleware.ts b/middleware.ts deleted file mode 100644 index 8583a11..0000000 --- a/middleware.ts +++ /dev/null @@ -1,41 +0,0 @@ -import { Redis } from "@upstash/redis"; -import { NextRequest, NextResponse, NextFetchEvent } from "next/server"; - -const redis = Redis.fromEnv(); -export const config = { - runtime: "experimental-edge", - matcher: "/projects/:slug*", -}; - -export default async function middleware( - req: NextRequest, - evt: NextFetchEvent, -): Promise { - const path = new URL(req.url).pathname; - console.log({ path }); - - evt.waitUntil(incrementPageView(req.ip, path)); - - return NextResponse.next(); -} - -async function incrementPageView( - identifier: string | undefined, - pathname: string, -): Promise { - if (identifier) { - // deduplicate the ip for each slug - const isNew = await redis.set( - ["deduplicate", identifier, pathname].join(":"), - true, - { - nx: true, - ex: 24 * 60 * 60, - }, - ); - if (!isNew) { - return; - } - } - await redis.incr(["pageviews", pathname].join(":")); -} diff --git a/pages/api/incr.ts b/pages/api/incr.ts new file mode 100644 index 0000000..87f2c05 --- /dev/null +++ b/pages/api/incr.ts @@ -0,0 +1,43 @@ +import { Redis } from "@upstash/redis"; +import { NextRequest, NextResponse } from "next/server"; + +const redis = Redis.fromEnv(); +export const config = { + runtime: "edge", +}; + +export default async function incr(req: NextRequest): Promise { + if (req.method !== "POST") { + return new NextResponse("use POST", { status: 405 }); + } + if (req.headers.get("Content-Type") !== "application/json") { + return new NextResponse("must be json", { status: 400 }); + } + + const body = await req.json(); + let slug: string | undefined = undefined; + if ("slug" in body) { + slug = body.slug; + } + + if (!slug) { + return new NextResponse("Slug not found", { status: 400 }); + } + const identifier = req.ip; + if (identifier) { + // deduplicate the ip for each slug + const isNew = await redis.set( + ["deduplicate", identifier, slug].join(":"), + true, + { + nx: true, + ex: 24 * 60 * 60, + }, + ); + if (!isNew) { + new NextResponse(null, { status: 202 }); + } + } + await redis.incr(["pageviews", slug].join(":")); + return new NextResponse(null, { status: 202 }); +}