Skip to content

Commit 5abb360

Browse files
committed
damn, had to change add hhmm into YYMMDD redir FAST
1 parent e4be531 commit 5abb360

2 files changed

Lines changed: 10 additions & 10 deletions

File tree

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,9 +89,9 @@ There are two types of shortlinks:
8989
- You can configure these in [`data/ShortLinks.js`](./data/ShortLinks.js) and they'll be handled by the catch-all route in [`pages/[...slug].js`](./pages/[...slug].js).
9090
- Alternatively, you can add them directly in the redirects array of [`next.config.js`](./next.config.js), but it can get messy fast in the long run.
9191
- A **"permanent" shortlink** (aka a [permashortlink](https://indieweb.org/permashortlink)) is a redirect configured in the Next.js middleware ([`proxy.js`](./proxy.js)). It formats links to point to my blog based on 4 URL patterns, in the following order:
92-
- `/b/YYMMDD`: Checks for a 6-digit number in the format of year-month-day, and redirects to `https://jarema.me/blog/20YY/MM/DD/`.
92+
- `/b/YYMMDDHHMM`: Checks for a 10-digit number in the format of year-month-day-hour-minute, and redirects to `https://jarema.me/blog/20YY/MM/DD/hh/mm/`.
9393
- `/b/AAATTT`: This is an algorithmic shortlink with 6 alphanumeric characters, encoded in [Base36](https://en.wikipedia.org/wiki/Base36) to point to a blog datetime.
94-
- `AAA` = Base36 days since 2000-01-01, covers dates from 2000 to end of 2099. This contains one letter parsing check to avoid colliding with `/b/YYMMDD`.
94+
- `AAA` = Base36 days since 2000-01-01, covers dates from 2000 to end of 2099.
9595
- `TTT` = Base36 minutes since midnight, range 0-1439.
9696
- **Example**: [`https://jar.tf/b/7eb0nr`](https://jar.tf/b/7eb0nr) decodes to `https://jarema.me/blog/2026/04/01/14/15/` (case-insensitive). Try it out, I've hyperlinked that one shortlink :3
9797
- `/b/YYMM/slug`: Extracts the date and slug, and redirects to `https://jarema.me/blog/20YY/MM/slug/`.

proxy.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
// Handles /b/* blog permashortlinks
22
// Formats:
3-
// /b/YYMMDD -> https://jarema.me/blog/20YY/MM/DD/
4-
// /b/AAATTT -> https://jarema.me/blog/20YY/MM/DD/hh/mm/
5-
// /b/YYMM/slug -> https://jarema.me/blog/20YY/MM/slug/
6-
// /b/slug -> https://jarema.me/blog/slug/
3+
// /b/YYMMDDHHMM -> https://jarema.me/blog/20YY/MM/DD/hh/mm/
4+
// /b/AAATTT -> https://jarema.me/blog/20YY/MM/DD/hh/mm/
5+
// /b/YYMM/slug -> https://jarema.me/blog/20YY/MM/slug/
6+
// /b/slug -> https://jarema.me/blog/slug/
77
//
88
// Algorithmic permashortlink (base36, case-insensitive):
99
// AAA = base36 dAys since 2000-01-01, covers 2000-2099
@@ -20,10 +20,10 @@ export function proxy(request) {
2020
let dest;
2121
let match;
2222

23-
// /b/YYMMDD
24-
if ((match = /^(\d{2})(\d{2})(\d{2})$/.exec(p))) {
25-
if (+match[2] < 1 || +match[2] > 12 || +match[3] < 1 || +match[3] > 31) return NextResponse.next();
26-
dest = `https://jarema.me/blog/20${match[1]}/${match[2]}/${match[3]}/`;
23+
// /b/YYMMDDhhmm
24+
if ((match = /^(\d{2})(\d{2})(\d{2})(\d{2})(\d{2})$/.exec(p))) {
25+
if (+match[2] < 1 || +match[2] > 12 || +match[3] < 1 || +match[3] > 31 || +match[4] > 23 || +match[5] > 59) return NextResponse.next();
26+
dest = `https://jarema.me/blog/20${match[1]}/${match[2]}/${match[3]}/${match[4]}/${match[5]}/`;
2727

2828
// /b/AAATTT
2929
} else if ((match = /^([0-9a-z]{3})([0-9a-z]{3})$/i.exec(p))) {

0 commit comments

Comments
 (0)