From 5fe5535b4f19e5f8c1356b9ddf180a7fea9ccda0 Mon Sep 17 00:00:00 2001 From: Cory Dransfeldt Date: Fri, 16 May 2025 11:35:12 -0700 Subject: [PATCH] fix(*.php.liquid): correct routing conflicts for dynamic and static pages --- package-lock.json | 4 +-- package.json | 2 +- src/includes/fetchers/book.php.liquid | 37 ++------------------------- src/meta/htaccess.liquid | 14 +++++----- src/pages/dynamic/artist.php.liquid | 2 +- src/pages/dynamic/book.php.liquid | 2 +- src/pages/dynamic/genre.php.liquid | 2 +- src/pages/dynamic/movie.php.liquid | 2 +- src/pages/dynamic/show.php.liquid | 2 +- src/pages/dynamic/tags.php.liquid | 2 +- 10 files changed, 17 insertions(+), 52 deletions(-) diff --git a/package-lock.json b/package-lock.json index 3f75eae..ae4f3d1 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "coryd.dev", - "version": "5.1.6", + "version": "5.2.0", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "coryd.dev", - "version": "5.1.6", + "version": "5.2.0", "license": "MIT", "dependencies": { "html-minifier-terser": "7.2.0", diff --git a/package.json b/package.json index 580dae9..820dffb 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "coryd.dev", - "version": "5.1.6", + "version": "5.2.0", "description": "The source for my personal site. Built using 11ty (and other tools).", "type": "module", "engines": { diff --git a/src/includes/fetchers/book.php.liquid b/src/includes/fetchers/book.php.liquid index 93995f2..aa7780e 100644 --- a/src/includes/fetchers/book.php.liquid +++ b/src/includes/fetchers/book.php.liquid @@ -9,39 +9,8 @@ $requestUri = $_SERVER["REQUEST_URI"]; $url = trim(parse_url($requestUri, PHP_URL_PATH), "/"); - if (preg_match('/^books\/years\/(\d{4})$/', $url, $matches)) { - $year = $matches[1]; - $filePath = __DIR__ . "/years/{$year}.html"; - - if (file_exists($filePath)) { - readfile($filePath); - } else { - http_response_code(404); - header("Content-Type: text/html; charset=utf-8"); - readfile(__DIR__ . "/../404/index.html"); - exit(); - } - exit(); - } - - if ($url === "books") { - http_response_code(200); - header("Content-Type: text/html; charset=utf-8"); - readfile(__DIR__ . "/index.html"); - exit(); - } - - if ($url === "books/years") { - http_response_code(404); - header("Content-Type: text/html; charset=utf-8"); - readfile(__DIR__ . "/../404/index.html"); - exit(); - } - if (!preg_match('/^books\/[\w-]+$/', $url)) { - http_response_code(404); - header("Content-Type: text/html; charset=utf-8"); - readfile(__DIR__ . "/../404/index.html"); + header("Location: /404/", true, 302); exit(); } @@ -49,9 +18,7 @@ $book = $fetcher->fetch($url); if (!$book) { - http_response_code(404); - header("Content-Type: text/html; charset=utf-8"); - readfile(__DIR__ . "/../404/index.html"); + header("Location: /404/", true, 302); exit(); } diff --git a/src/meta/htaccess.liquid b/src/meta/htaccess.liquid index 3ede2c5..52cd9c9 100644 --- a/src/meta/htaccess.liquid +++ b/src/meta/htaccess.liquid @@ -28,24 +28,22 @@ ErrorDocument 500 /500/index.html # dynamic page routing ## artists -RewriteRule ^music/artists/([^/]+)/?$ music/artists/index.php [L] +RewriteRule ^music/artists/([^/]+)/?$ music/artists/dynamic.php [L] ## books -RewriteRule ^books/([^/]+)/?$ books/index.php [L] -RewriteRule ^books/years/(\d{4})/?$ books/years/index.html [L] -RewriteRule ^books/?$ books/books.html [L] +RewriteRule ^books/([^/]+)/?$ books/dynamic.php [L] ## movies -RewriteRule ^watching/movies/([^/]+)/?$ watching/movies/index.php [L] +RewriteRule ^watching/movies/([^/]+)/?$ watching/movies/dynamic.php [L] ## shows -RewriteRule ^watching/shows/([^/]+)/?$ watching/shows/index.php [L] +RewriteRule ^watching/shows/([^/]+)/?$ watching/shows/dynamic.php [L] ## genres -RewriteRule ^music/genres/([^/]+)/?$ music/genres/index.php [L] +RewriteRule ^music/genres/([^/]+)/?$ music/genres/dynamic.php [L] ## tags -RewriteRule ^tags/([^/]+)(?:/([0-9]+))?/?$ tags/index.php [L] +RewriteRule ^tags/([^/]+)(?:/([0-9]+))?/?$ tags/dynamic.php [L] ## open graph assets diff --git a/src/pages/dynamic/artist.php.liquid b/src/pages/dynamic/artist.php.liquid index 8009e59..7fb0f75 100644 --- a/src/pages/dynamic/artist.php.liquid +++ b/src/pages/dynamic/artist.php.liquid @@ -1,5 +1,5 @@ --- -permalink: /music/artists/index.php +permalink: /music/artists/dynamic.php type: dynamic schema: artist --- diff --git a/src/pages/dynamic/book.php.liquid b/src/pages/dynamic/book.php.liquid index 9b36598..9ffa8ad 100644 --- a/src/pages/dynamic/book.php.liquid +++ b/src/pages/dynamic/book.php.liquid @@ -1,5 +1,5 @@ --- -permalink: /books/index.php +permalink: /books/dynamic.php type: dynamic schema: book --- diff --git a/src/pages/dynamic/genre.php.liquid b/src/pages/dynamic/genre.php.liquid index 38859b9..72b68b5 100644 --- a/src/pages/dynamic/genre.php.liquid +++ b/src/pages/dynamic/genre.php.liquid @@ -1,5 +1,5 @@ --- -permalink: /music/genres/index.php +permalink: /music/genres/dynamic.php type: dynamic schema: genre --- diff --git a/src/pages/dynamic/movie.php.liquid b/src/pages/dynamic/movie.php.liquid index a326f7c..1b5005d 100644 --- a/src/pages/dynamic/movie.php.liquid +++ b/src/pages/dynamic/movie.php.liquid @@ -1,5 +1,5 @@ --- -permalink: /watching/movies/index.php +permalink: /watching/movies/dynamic.php type: dynamic schema: movie --- diff --git a/src/pages/dynamic/show.php.liquid b/src/pages/dynamic/show.php.liquid index 9f92195..d0462dc 100644 --- a/src/pages/dynamic/show.php.liquid +++ b/src/pages/dynamic/show.php.liquid @@ -1,5 +1,5 @@ --- -permalink: /watching/shows/index.php +permalink: /watching/shows/dynamic.php type: dynamic schema: show --- diff --git a/src/pages/dynamic/tags.php.liquid b/src/pages/dynamic/tags.php.liquid index d07f743..62c27f9 100644 --- a/src/pages/dynamic/tags.php.liquid +++ b/src/pages/dynamic/tags.php.liquid @@ -1,5 +1,5 @@ --- -permalink: /tags/index.php +permalink: /tags/dynamic.php type: dynamic schema: tags ---