-
-
Notifications
You must be signed in to change notification settings - Fork 154
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
Showing
6 changed files
with
171 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import { revalidatePath } from "next/cache" | ||
|
||
export async function POST(request: Request) { | ||
try { | ||
const text = await request.text() | ||
console.log("[GitHub] Webhook received", text) | ||
|
||
revalidatePath("/test") | ||
} catch (error: any) { | ||
return new Response(`Webhook error: ${error.message}`, { | ||
status: 400, | ||
}) | ||
} | ||
|
||
return new Response("Success!", { | ||
status: 200, | ||
}) | ||
} |
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
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 |
---|---|---|
@@ -0,0 +1,45 @@ | ||
"use client" | ||
|
||
export function TimeAgo({ date }: { date: string }) { | ||
const time = new Date(date) | ||
return ( | ||
<time dateTime={time.toString()} title={time.toString()}> | ||
{getTimeAgo(time)} | ||
</time> | ||
) | ||
} | ||
|
||
const MINUTE = 60 | ||
const HOUR = MINUTE * 60 | ||
const DAY = HOUR * 24 | ||
const WEEK = DAY * 7 | ||
const MONTH = DAY * 30 | ||
const YEAR = DAY * 365 | ||
|
||
function getTimeAgo(date: Date) { | ||
const secondsAgo = Math.round((Date.now() - Number(date)) / 1000) | ||
|
||
if (secondsAgo < MINUTE) { | ||
return secondsAgo + ` second${secondsAgo !== 1 ? "s" : ""} ago` | ||
} | ||
|
||
let divisor | ||
let unit = "" | ||
|
||
if (secondsAgo < HOUR) { | ||
;[divisor, unit] = [MINUTE, "minute"] | ||
} else if (secondsAgo < DAY) { | ||
;[divisor, unit] = [HOUR, "hour"] | ||
} else if (secondsAgo < WEEK) { | ||
;[divisor, unit] = [DAY, "day"] | ||
} else if (secondsAgo < MONTH) { | ||
;[divisor, unit] = [WEEK, "week"] | ||
} else if (secondsAgo < YEAR) { | ||
;[divisor, unit] = [MONTH, "month"] | ||
} else { | ||
;[divisor, unit] = [YEAR, "year"] | ||
} | ||
|
||
const count = Math.floor(secondsAgo / divisor) | ||
return `${count} ${unit}${count > 1 ? "s" : ""} ago` | ||
} |
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