Skip to content

Commit

Permalink
chore: bring back vercel middleware
Browse files Browse the repository at this point in the history
Signed-off-by: Aaron Pham <contact@aarnphm.xyz>
  • Loading branch information
aarnphm committed Jan 25, 2025
1 parent 1ff3d24 commit 8d8070c
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 3 deletions.
15 changes: 15 additions & 0 deletions middleware.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { rewrite, next } from "@vercel/edge"
export const config = {
matcher: ["/:path*"],
}
export default function middleware(request: Request) {
const url = new URL(request.url)
// Only apply logic for notes.aarnphm.xyz
if (url.hostname !== "notes.aarnphm.xyz" || url.pathname !== "/") {
return next()
}
const slug = "notes"
const newUrl = new URL(`/${slug}`, request.url)
newUrl.searchParams.set("stackedNotes", btoa(slug.toString()).replace(/=+$/, ""))
return rewrite(newUrl)
}
8 changes: 8 additions & 0 deletions package-lock.json

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

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@
"@types/unist": "^3.0.3",
"@types/ws": "^8.5.14",
"@types/yargs": "^17.0.33",
"@vercel/edge": "^1.2.1",
"esbuild": "^0.24.2",
"mermaid": "^11.4.1",
"prettier": "^3.4.2",
Expand Down
10 changes: 8 additions & 2 deletions quartz/components/scripts/matuschak.inline.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,12 @@ document.addEventListener("nav", async (ev) => {

if (copyStacked) {
function onClick() {
navigator.clipboard.writeText(`https://aarnphm.xyz/notes?${window.stacked.getChain()}`).then(
const stackedNotes = window.stacked.getChain()
let source = stackedNotes
if (window.location.hostname.startsWith("notes.aarnphm.xyz"))
source = `https://notes.aarnphm.xyz/?${stackedNotes}`

navigator.clipboard.writeText(source).then(
() => {
copyStacked.blur()
const use = copyStacked?.querySelector("svg") as SVGElement
Expand All @@ -63,7 +68,8 @@ document.addEventListener("nav", async (ev) => {
window.addCleanup(() => copyStacked.removeEventListener("click", onClick))
}

if (getFullSlug(window) === "notes") return
if (window.location.hostname.startsWith("notes.aarnphm.xyz") || getFullSlug(window) === "notes")
return

button.addEventListener("click", switchCheckState)
window.addCleanup(() => {
Expand Down
2 changes: 1 addition & 1 deletion quartz/components/scripts/spa.inline.ts
Original file line number Diff line number Diff line change
Expand Up @@ -794,7 +794,7 @@ function pruneNotesElement() {
}

createRouter()
if (getFullSlug(window) !== "notes") notifyNav(getFullSlug(window))
notifyNav(getFullSlug(window))

if (!customElements.get("route-announcer")) {
const attrs = {
Expand Down

0 comments on commit 8d8070c

Please sign in to comment.