feat(search.html): update to disable and show loading state w/load more button; improve fuzzy search + debounce

This commit is contained in:
Cory Dransfeldt 2025-05-29 10:03:35 -07:00
parent 63db0cf32a
commit 8a6e84cb35
No known key found for this signature in database
35 changed files with 119 additions and 395 deletions

View file

@ -3,11 +3,12 @@
namespace App\Classes; namespace App\Classes;
require __DIR__ . "/BaseHandler.php"; require __DIR__ . "/BaseHandler.php";
require __DIR__ . '/../../server/utils/init.php';
abstract class ApiHandler extends BaseHandler abstract class ApiHandler extends BaseHandler
{ {
protected function ensureCliAccess(): void protected function ensureCliAccess(): void
{ {
if (php_sapi_name() !== 'cli' && $_SERVER['REQUEST_METHOD'] !== 'POST') $this->sendErrorResponse("Not Found", 404); if (php_sapi_name() !== 'cli' && $_SERVER['REQUEST_METHOD'] !== 'POST') redirectTo404();
} }
} }

View file

@ -8,10 +8,7 @@
$isValidId = is_string($id) && preg_match('/^[a-f0-9\-]{36}$/', $id); $isValidId = is_string($id) && preg_match('/^[a-f0-9\-]{36}$/', $id);
$isValidClass = is_string($class) && preg_match('/^w\d{2,4}$/', $class); $isValidClass = is_string($class) && preg_match('/^w\d{2,4}$/', $class);
if (!$isValidId || !$isValidClass) { if (!$isValidId || !$isValidClass) redirectTo404();
header("Location: /404", true, 302);
exit;
}
$cdnUrl = "https://cdn.coryd.dev/$id.$extension?class=$class"; $cdnUrl = "https://cdn.coryd.dev/$id.$extension?class=$class";
$ch = curl_init($cdnUrl); $ch = curl_init($cdnUrl);

View file

@ -7,8 +7,7 @@
"guzzlehttp/guzzle": "^7.9", "guzzlehttp/guzzle": "^7.9",
"kaoken/markdown-it-php": "^14.1", "kaoken/markdown-it-php": "^14.1",
"sokil/php-isocodes": "^4.2", "sokil/php-isocodes": "^4.2",
"sokil/php-isocodes-db-only": "^4.0", "sokil/php-isocodes-db-only": "^4.0"
"voku/html-min": "^4.5"
}, },
"scripts": { "scripts": {
"start": [ "start": [

215
composer.lock generated
View file

@ -4,7 +4,7 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically" "This file is @generated automatically"
], ],
"content-hash": "9998c1c4f0bcc7d5e58abc25de979750", "content-hash": "6f62ebb63bb51c04310e829e19beeab5",
"packages": [ "packages": [
{ {
"name": "guzzlehttp/guzzle", "name": "guzzlehttp/guzzle",
@ -686,71 +686,6 @@
}, },
"time": "2024-02-02T08:24:43+00:00" "time": "2024-02-02T08:24:43+00:00"
}, },
{
"name": "symfony/css-selector",
"version": "v7.3.0",
"source": {
"type": "git",
"url": "https://github.com/symfony/css-selector.git",
"reference": "601a5ce9aaad7bf10797e3663faefce9e26c24e2"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/symfony/css-selector/zipball/601a5ce9aaad7bf10797e3663faefce9e26c24e2",
"reference": "601a5ce9aaad7bf10797e3663faefce9e26c24e2",
"shasum": ""
},
"require": {
"php": ">=8.2"
},
"type": "library",
"autoload": {
"psr-4": {
"Symfony\\Component\\CssSelector\\": ""
},
"exclude-from-classmap": [
"/Tests/"
]
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Fabien Potencier",
"email": "fabien@symfony.com"
},
{
"name": "Jean-François Simon",
"email": "jeanfrancois.simon@sensiolabs.com"
},
{
"name": "Symfony Community",
"homepage": "https://symfony.com/contributors"
}
],
"description": "Converts CSS selectors to XPath expressions",
"homepage": "https://symfony.com",
"support": {
"source": "https://github.com/symfony/css-selector/tree/v7.3.0"
},
"funding": [
{
"url": "https://symfony.com/sponsor",
"type": "custom"
},
{
"url": "https://github.com/fabpot",
"type": "github"
},
{
"url": "https://tidelift.com/funding/github/packagist/symfony/symfony",
"type": "tidelift"
}
],
"time": "2024-09-25T14:21:43+00:00"
},
{ {
"name": "symfony/deprecation-contracts", "name": "symfony/deprecation-contracts",
"version": "v3.6.0", "version": "v3.6.0",
@ -817,154 +752,6 @@
} }
], ],
"time": "2024-09-25T14:21:43+00:00" "time": "2024-09-25T14:21:43+00:00"
},
{
"name": "voku/html-min",
"version": "4.5.1",
"source": {
"type": "git",
"url": "https://github.com/voku/HtmlMin.git",
"reference": "872dac444652d30791ca5d0c23fbe1e6b9cab5bc"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/voku/HtmlMin/zipball/872dac444652d30791ca5d0c23fbe1e6b9cab5bc",
"reference": "872dac444652d30791ca5d0c23fbe1e6b9cab5bc",
"shasum": ""
},
"require": {
"ext-dom": "*",
"php": ">=7.0.0",
"voku/simple_html_dom": "~4.8.5"
},
"require-dev": {
"phpunit/phpunit": "~6.0 || ~7.0 || ~9.0"
},
"type": "library",
"autoload": {
"psr-4": {
"voku\\": "src/voku/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Lars Moelleken",
"homepage": "https://www.moelleken.org/"
}
],
"description": "HTML Compressor and Minifier",
"homepage": "https://github.com/voku/HtmlMin",
"keywords": [
"compress",
"compression",
"compressor",
"html",
"minifier"
],
"support": {
"issues": "https://github.com/voku/HtmlMin/issues",
"source": "https://github.com/voku/HtmlMin/tree/4.5.1"
},
"funding": [
{
"url": "https://www.paypal.me/moelleken",
"type": "custom"
},
{
"url": "https://github.com/voku",
"type": "github"
},
{
"url": "https://www.patreon.com/voku",
"type": "patreon"
}
],
"time": "2024-05-25T08:01:45+00:00"
},
{
"name": "voku/simple_html_dom",
"version": "4.8.10",
"source": {
"type": "git",
"url": "https://github.com/voku/simple_html_dom.git",
"reference": "716822ed52ed3a1881542be07a786270de390e99"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/voku/simple_html_dom/zipball/716822ed52ed3a1881542be07a786270de390e99",
"reference": "716822ed52ed3a1881542be07a786270de390e99",
"shasum": ""
},
"require": {
"ext-dom": "*",
"ext-libxml": "*",
"ext-simplexml": "*",
"php": ">=7.0.0",
"symfony/css-selector": "~3.0 || ~4.0 || ~5.0 || ~6.0 || ~7.0"
},
"require-dev": {
"phpunit/phpunit": "~6.0 || ~7.0 || ~9.0"
},
"suggest": {
"voku/portable-utf8": "If you need e.g. UTF-8 fixed output."
},
"type": "library",
"autoload": {
"psr-4": {
"voku\\helper\\": "src/voku/helper/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "dimabdc",
"email": "support@titor.ru",
"homepage": "https://github.com/dimabdc",
"role": "Developer"
},
{
"name": "Lars Moelleken",
"homepage": "https://www.moelleken.org/",
"role": "Fork-Maintainer"
}
],
"description": "Simple HTML DOM package.",
"homepage": "https://github.com/voku/simple_html_dom",
"keywords": [
"HTML Parser",
"dom",
"php dom"
],
"support": {
"issues": "https://github.com/voku/simple_html_dom/issues",
"source": "https://github.com/voku/simple_html_dom/tree/4.8.10"
},
"funding": [
{
"url": "https://www.paypal.me/moelleken",
"type": "custom"
},
{
"url": "https://github.com/voku",
"type": "github"
},
{
"url": "https://www.patreon.com/voku",
"type": "patreon"
},
{
"url": "https://tidelift.com/funding/github/packagist/voku/simple_html_dom",
"type": "tidelift"
}
],
"time": "2024-07-03T16:05:14+00:00"
} }
], ],
"packages-dev": [], "packages-dev": [],

View file

@ -38,4 +38,5 @@ export default {
return `${string}s${trailing ? `${trailing}` : ''}`; return `${string}s${trailing ? `${trailing}` : ''}`;
}, },
jsonEscape: (string) => JSON.stringify(string), jsonEscape: (string) => JSON.stringify(string),
regexEscape: (string) => string.replace(/[.*+?^${}()[]\\]/g, '\\$&')
}; };

4
package-lock.json generated
View file

@ -1,12 +1,12 @@
{ {
"name": "coryd.dev", "name": "coryd.dev",
"version": "8.0.4", "version": "8.2.2",
"lockfileVersion": 3, "lockfileVersion": 3,
"requires": true, "requires": true,
"packages": { "packages": {
"": { "": {
"name": "coryd.dev", "name": "coryd.dev",
"version": "8.0.4", "version": "8.2.2",
"license": "MIT", "license": "MIT",
"dependencies": { "dependencies": {
"minisearch": "^7.1.2", "minisearch": "^7.1.2",

View file

@ -1,6 +1,6 @@
{ {
"name": "coryd.dev", "name": "coryd.dev",
"version": "8.0.4", "version": "8.2.2",
"description": "The source for my personal site. Built using 11ty (and other tools).", "description": "The source for my personal site. Built using 11ty (and other tools).",
"type": "module", "type": "module",
"engines": { "engines": {

View file

@ -43,7 +43,7 @@
decoding="async" decoding="async"
width="' . $width . '" width="' . $width . '"
height="' . $height . '" height="' . $height . '"
/>'; >';
echo '</div>'; echo '</div>';
echo $closeLink; echo $closeLink;
} }

View file

@ -7,7 +7,7 @@ function renderTags(array $tags): void {
foreach ($tags as $tag) { foreach ($tags as $tag) {
$slug = strtolower(trim($tag)); $slug = strtolower(trim($tag));
echo '<a href="/tags/' . htmlspecialchars($slug) . '">#' . htmlspecialchars($slug) . '</a>'; echo '<a href="/tags/' . rawurlencode($slug) . '">#' . htmlspecialchars($slug) . '</a>';
} }
echo '</div>'; echo '</div>';

View file

@ -36,7 +36,7 @@ permalink: "{{ feed.permalink }}.xml"
{%- endif -%} {%- endif -%}
<description><![CDATA[ <description><![CDATA[
{%- if feedItem.image -%} {%- if feedItem.image -%}
<img src="{{ feedItem.image | encodeAmp }}?class=w800" alt="Image from {{ feedItem.title }}" /> <img src="{{ feedItem.image | encodeAmp }}?class=w800" alt="Image from {{ feedItem.title }}">
{%- endif -%} {%- endif -%}
{%- if feedItem.content -%} {%- if feedItem.content -%}
{{ feedItem.content | markdown | convertRelativeLinks: globals.url }} {{ feedItem.content | markdown | convertRelativeLinks: globals.url }}

View file

@ -14,4 +14,4 @@
decoding="async" decoding="async"
width="720" width="720"
height="480" height="480"
/> >

View file

@ -1,9 +1,12 @@
{%- for block in blocks -%} {%- for block in blocks -%}
{%- case block.type -%} {%- case block.type -%}
{%- when "youtube_player" -%} {%- when "calendar_banner" -%}
{% render "blocks/youtube-player.liquid", {% render "blocks/banners/calendar.liquid",
url:block.url url:block.url,
text:block.text
%} %}
{%- when "divider" -%}
{{ block.markup | markdown }}
{%- when "forgejo_banner" -%} {%- when "forgejo_banner" -%}
{% render "blocks/banners/forgejo.liquid", {% render "blocks/banners/forgejo.liquid",
url:block.url url:block.url
@ -12,6 +15,14 @@
{% render "blocks/banners/github.liquid", {% render "blocks/banners/github.liquid",
url:block.url url:block.url
%} %}
{%- when "hero" -%}
{% render "blocks/hero.liquid",
globals:globals,
image:block.image,
alt:block.alt
%}
{%- when "markdown" -%}
{{ block.text | markdown }}
{%- when "npm_banner" -%} {%- when "npm_banner" -%}
{% render "blocks/banners/npm.liquid", {% render "blocks/banners/npm.liquid",
url:block.url, url:block.url,
@ -22,15 +33,9 @@
url:block.url, url:block.url,
text:block.text text:block.text
%} %}
{%- when "hero" -%} {%- when "youtube_player" -%}
{% render "blocks/hero.liquid", {% render "blocks/youtube-player.liquid",
globals:globals, url:block.url
image:block.image,
alt:block.alt
%} %}
{%- when "markdown" -%}
{{ block.text | markdown }}
{%- when "divider" -%}
{{ block.markup | markdown }}
{%- endcase -%} {%- endcase -%}
{%- endfor -%} {%- endfor -%}

View file

@ -4,7 +4,6 @@
require __DIR__ . "/../../server/utils/init.php"; require __DIR__ . "/../../server/utils/init.php";
use App\Classes\ArtistFetcher; use App\Classes\ArtistFetcher;
use voku\helper\HtmlMin;
$requestUri = $_SERVER["REQUEST_URI"]; $requestUri = $_SERVER["REQUEST_URI"];
$url = trim(parse_url($requestUri, PHP_URL_PATH), "/"); $url = trim(parse_url($requestUri, PHP_URL_PATH), "/");
@ -21,7 +20,6 @@
$page = $artist; $page = $artist;
extract(setupPageMetadata($page, $requestUri)); extract(setupPageMetadata($page, $requestUri));
ob_start();
header("Cache-Control: public, max-age=3600"); header("Cache-Control: public, max-age=3600");
header("Expires: " . gmdate("D, d M Y H:i:s", time() + 3600) . " GMT"); header("Expires: " . gmdate("D, d M Y H:i:s", time() + 3600) . " GMT");

View file

@ -4,7 +4,6 @@
require __DIR__ . "/../../server/utils/init.php"; require __DIR__ . "/../../server/utils/init.php";
use App\Classes\BookFetcher; use App\Classes\BookFetcher;
use voku\helper\HtmlMin;
$requestUri = $_SERVER["REQUEST_URI"]; $requestUri = $_SERVER["REQUEST_URI"];
$url = trim(parse_url($requestUri, PHP_URL_PATH), "/"); $url = trim(parse_url($requestUri, PHP_URL_PATH), "/");
@ -22,7 +21,6 @@
$globals = $page["globals"]; $globals = $page["globals"];
extract(setupPageMetadata($page, $requestUri)); extract(setupPageMetadata($page, $requestUri));
ob_start();
header("Cache-Control: public, max-age=3600"); header("Cache-Control: public, max-age=3600");
header("Expires: " . gmdate("D, d M Y H:i:s", time() + 3600) . " GMT"); header("Expires: " . gmdate("D, d M Y H:i:s", time() + 3600) . " GMT");

View file

@ -4,7 +4,6 @@
require __DIR__ . "/../../server/utils/init.php"; require __DIR__ . "/../../server/utils/init.php";
use App\Classes\GenreFetcher; use App\Classes\GenreFetcher;
use voku\helper\HtmlMin;
$requestUri = $_SERVER["REQUEST_URI"]; $requestUri = $_SERVER["REQUEST_URI"];
$url = trim(parse_url($requestUri, PHP_URL_PATH), "/"); $url = trim(parse_url($requestUri, PHP_URL_PATH), "/");
@ -21,8 +20,6 @@
$globals = $page["globals"]; $globals = $page["globals"];
extract(setupPageMetadata($page, $requestUri)); extract(setupPageMetadata($page, $requestUri));
ob_start();
header("Cache-Control: public, max-age=3600"); header("Cache-Control: public, max-age=3600");
header("Expires: " . gmdate("D, d M Y H:i:s", time() + 3600) . " GMT"); header("Expires: " . gmdate("D, d M Y H:i:s", time() + 3600) . " GMT");

View file

@ -4,7 +4,6 @@
require __DIR__ . "/../../server/utils/init.php"; require __DIR__ . "/../../server/utils/init.php";
use App\Classes\MovieFetcher; use App\Classes\MovieFetcher;
use voku\helper\HtmlMin;
$requestUri = $_SERVER["REQUEST_URI"]; $requestUri = $_SERVER["REQUEST_URI"];
$url = trim(parse_url($requestUri, PHP_URL_PATH), "/"); $url = trim(parse_url($requestUri, PHP_URL_PATH), "/");
@ -22,7 +21,6 @@
$globals = $page["globals"]; $globals = $page["globals"];
extract(setupPageMetadata($page, $requestUri)); extract(setupPageMetadata($page, $requestUri));
ob_start();
header("Cache-Control: public, max-age=3600"); header("Cache-Control: public, max-age=3600");
header("Expires: " . gmdate("D, d M Y H:i:s", time() + 3600) . " GMT"); header("Expires: " . gmdate("D, d M Y H:i:s", time() + 3600) . " GMT");

View file

@ -4,7 +4,6 @@
require __DIR__ . "/../../server/utils/init.php"; require __DIR__ . "/../../server/utils/init.php";
use App\Classes\ShowFetcher; use App\Classes\ShowFetcher;
use voku\helper\HtmlMin;
$requestUri = $_SERVER["REQUEST_URI"]; $requestUri = $_SERVER["REQUEST_URI"];
$url = trim(parse_url($requestUri, PHP_URL_PATH), "/"); $url = trim(parse_url($requestUri, PHP_URL_PATH), "/");
@ -22,7 +21,6 @@
$globals = $page["globals"]; $globals = $page["globals"];
extract(setupPageMetadata($page, $requestUri)); extract(setupPageMetadata($page, $requestUri));
ob_start();
header("Cache-Control: public, max-age=3600"); header("Cache-Control: public, max-age=3600");
header("Expires: " . gmdate("D, d M Y H:i:s", time() + 3600) . " GMT"); header("Expires: " . gmdate("D, d M Y H:i:s", time() + 3600) . " GMT");

View file

@ -5,7 +5,6 @@
use App\Classes\TagFetcher; use App\Classes\TagFetcher;
use App\Classes\GlobalsFetcher; use App\Classes\GlobalsFetcher;
use voku\helper\HtmlMin;
$requestUri = $_SERVER["REQUEST_URI"]; $requestUri = $_SERVER["REQUEST_URI"];
$url = trim(parse_url($requestUri, PHP_URL_PATH), "/"); $url = trim(parse_url($requestUri, PHP_URL_PATH), "/");
@ -63,7 +62,6 @@
]; ];
extract(setupPageMetadata($page, $requestUri)); extract(setupPageMetadata($page, $requestUri));
ob_start();
header("Cache-Control: public, max-age=3600"); header("Cache-Control: public, max-age=3600");
header("Expires: " . gmdate("D, d M Y H:i:s", time() + 3600) . " GMT"); header("Expires: " . gmdate("D, d M Y H:i:s", time() + 3600) . " GMT");

View file

@ -6,10 +6,10 @@
" "
sizes="(max-width: 450px) 100px, 200px" sizes="(max-width: 450px) 100px, 200px"
class="icon" src="{{ globals.avatar_header }}?class=w100&v={% appVersion %}" class="icon" src="{{ globals.avatar_header }}?class=w100&v={% appVersion %}"
alt="{{ globals.site_name }}" alt="An avatar representing {{ globals.site_name }}"
width="100" width="100"
height="145" height="145"
/> >
<span>Cory</span> <span>Dransfeldt</span> <span>Cory</span> <span>Dransfeldt</span>
{%- endcapture -%} {%- endcapture -%}
<section class="main-title"> <section class="main-title">

View file

@ -37,7 +37,7 @@
decoding="async" decoding="async"
width="{{ width }}" width="{{ width }}"
height="{{ height }}" height="{{ height }}"
/> >
</div> </div>
</a> </a>
{%- endfor -%} {%- endfor -%}

View file

@ -15,7 +15,7 @@
decoding="async" decoding="async"
width="64" width="64"
height="64" height="64"
/> >
</a> </a>
<div class="meta-text"> <div class="meta-text">
<a class="title" href="{{ item.chart.url }}">{{ item.chart.title }}</a> <a class="title" href="{{ item.chart.url }}">{{ item.chart.title }}</a>

View file

@ -83,23 +83,22 @@ Redirect {{ redirect.status_code | default: "301" }} {{ redirect.source_url }} {
</FilesMatch> </FilesMatch>
{% endfor %} {% endfor %}
{%- assign userAgents = "" -%} {%- assign escapedAgents = "" -%}
{% for robot in robots -%} {%- for robot in robots -%}
{%- for userAgent in robot.user_agents -%} {%- for agent in robot.user_agents -%}
{%- if userAgent != "*" and userAgent != "NaN" -%} {%- if agent != "*" and agent != "NaN" -%}
{%- assign userAgents = userAgents | append: userAgent %} {%- assign escaped = agent | regexEscape -%}
{%- unless forloop.last -%} {%- assign escapedAgents = escapedAgents | append: escaped | append: "|" -%}
{%- assign userAgents = userAgents | append: "|" -%}
{%- endunless -%}
{%- endif -%} {%- endif -%}
{%- endfor -%} {%- endfor -%}
{%- endfor %} {%- endfor -%}
{% if userAgents != "" or referers != "" -%} {%- assign userAgentsRegex = escapedAgents | slice: 0, escapedAgents.size | rstrip: "|" -%}
RewriteCond %{HTTP_USER_AGENT} "{{ userAgents }}" [NC] {% if userAgentsRegex != "" %}
RewriteEngine On
RewriteCond %{HTTP_USER_AGENT} "{{ userAgentsRegex }}" [NC]
RewriteCond %{REQUEST_URI} !^/robots\.txt$ [NC] RewriteCond %{REQUEST_URI} !^/robots\.txt$ [NC]
RewriteRule .* /403/index.html [L,R=403] RewriteRule ^.*$ - [F,L]
{%- endif %} {% endif %}
<IfModule mod_deflate.c> <IfModule mod_deflate.c>
AddOutputFilterByType DEFLATE text/html text/plain text/xml text/css text/javascript application/javascript application/json AddOutputFilterByType DEFLATE text/html text/plain text/xml text/css text/javascript application/javascript application/json
</IfModule> </IfModule>

View file

@ -10,7 +10,7 @@ schema: artist
class="media-image" class="media-image"
srcset=" srcset="
<?= htmlspecialchars($artist["image"]) ?>?class=w200&type=webp 200w, <?= htmlspecialchars($artist["image"]) ?>?class=w200&type=webp 200w,
<?= htmlspecialchars($artist["image"]) ?>?class=w600&type=webp 400w, <?= htmlspecialchars($artist["image"]) ?>?class=w400&type=webp 400w,
<?= htmlspecialchars($artist["image"]) ?>?class=w800&type=webp 800w <?= htmlspecialchars($artist["image"]) ?>?class=w800&type=webp 800w
" "
sizes="(max-width: 450px) 200px, sizes="(max-width: 450px) 200px,
@ -21,7 +21,7 @@ schema: artist
decoding="async" decoding="async"
width="200" width="200"
height="200" height="200"
/> >
<div class="media-meta"> <div class="media-meta">
<h2 class="page-title"><?= htmlspecialchars($artist["name"]) ?></h2> <h2 class="page-title"><?= htmlspecialchars($artist["name"]) ?></h2>
<span class="sub-meta country">{% tablericon "map-pin" %} <?= htmlspecialchars( <span class="sub-meta country">{% tablericon "map-pin" %} <?= htmlspecialchars(
@ -111,13 +111,3 @@ schema: artist
<?php renderMediaGrid($artist["albums"]); ?> <?php renderMediaGrid($artist["albums"]); ?>
<?php endif; ?> <?php endif; ?>
</article> </article>
<?php
$html = ob_get_clean();
$htmlMin = new HtmlMin();
$htmlMin->doOptimizeAttributes(true);
$htmlMin->doRemoveComments(true);
$htmlMin->doSumUpWhitespace(true);
$htmlMin->doRemoveWhitespaceAroundTags(true);
$htmlMin->doOptimizeViaHtmlDomParser(false);
echo $htmlMin->minify($html);
?>

View file

@ -22,7 +22,7 @@ schema: book
decoding="async" decoding="async"
width="200" width="200"
height="307" height="307"
/> >
<div class="media-meta"> <div class="media-meta">
<h2 class="page-title"><?= htmlspecialchars($book["title"]) ?></h2> <h2 class="page-title"><?= htmlspecialchars($book["title"]) ?></h2>
<?php if (!empty($book["tags"])): ?> <?php if (!empty($book["tags"])): ?>
@ -67,13 +67,3 @@ schema: book
<?= parseMarkdown($book["description"]) ?> <?= parseMarkdown($book["description"]) ?>
<?php endif; ?> <?php endif; ?>
</article> </article>
<?php
$html = ob_get_clean();
$htmlMin = new HtmlMin();
$htmlMin->doOptimizeAttributes(true);
$htmlMin->doRemoveComments(true);
$htmlMin->doSumUpWhitespace(true);
$htmlMin->doRemoveWhitespaceAroundTags(true);
$htmlMin->doOptimizeViaHtmlDomParser(false);
echo $htmlMin->minify($html);
?>

View file

@ -45,13 +45,3 @@ schema: genre
<button data-toggle-button>Show more</button> <button data-toggle-button>Show more</button>
<?php endif; ?> <?php endif; ?>
</article> </article>
<?php
$html = ob_get_clean();
$htmlMin = new HtmlMin();
$htmlMin->doOptimizeAttributes(true);
$htmlMin->doRemoveComments(true);
$htmlMin->doSumUpWhitespace(true);
$htmlMin->doRemoveWhitespaceAroundTags(true);
$htmlMin->doOptimizeViaHtmlDomParser(false);
echo $htmlMin->minify($html);
?>

View file

@ -20,7 +20,7 @@ schema: movie
decoding="async" decoding="async"
width="256" width="256"
height="180" height="180"
/> >
<div class="media-meta"> <div class="media-meta">
<h2 class="page-title"><?= htmlspecialchars($movie["title"]) ?> (<?= htmlspecialchars($movie["year"]) ?>)</h2> <h2 class="page-title"><?= htmlspecialchars($movie["title"]) ?> (<?= htmlspecialchars($movie["year"]) ?>)</h2>
<?php if (!empty($movie["tags"])): ?> <?php if (!empty($movie["tags"])): ?>
@ -63,13 +63,3 @@ schema: movie
<?= parseMarkdown($movie["description"]) ?> <?= parseMarkdown($movie["description"]) ?>
<?php endif; ?> <?php endif; ?>
</article> </article>
<?php
$html = ob_get_clean();
$htmlMin = new HtmlMin();
$htmlMin->doOptimizeAttributes(true);
$htmlMin->doRemoveComments(true);
$htmlMin->doSumUpWhitespace(true);
$htmlMin->doRemoveWhitespaceAroundTags(true);
$htmlMin->doOptimizeViaHtmlDomParser(false);
echo $htmlMin->minify($html);
?>

View file

@ -20,7 +20,7 @@ schema: show
decoding="async" decoding="async"
width="256" width="256"
height="180" height="180"
/> >
<div class="media-meta"> <div class="media-meta">
<h2 class="page-title"><?= htmlspecialchars($show["title"]) ?> (<?= htmlspecialchars($show["year"]) ?>)</h2> <h2 class="page-title"><?= htmlspecialchars($show["title"]) ?> (<?= htmlspecialchars($show["year"]) ?>)</h2>
<?php if (!empty($show["tags"])): ?> <?php if (!empty($show["tags"])): ?>
@ -60,13 +60,3 @@ schema: show
<?= parseMarkdown($show["description"]) ?> <?= parseMarkdown($show["description"]) ?>
<?php endif; ?> <?php endif; ?>
</article> </article>
<?php
$html = ob_get_clean();
$htmlMin = new HtmlMin();
$htmlMin->doOptimizeAttributes(true);
$htmlMin->doRemoveComments(true);
$htmlMin->doSumUpWhitespace(true);
$htmlMin->doRemoveWhitespaceAroundTags(true);
$htmlMin->doOptimizeViaHtmlDomParser(false);
echo $htmlMin->minify($html);
?>

View file

@ -38,13 +38,3 @@ schema: tags
</article> </article>
<?php endforeach; ?> <?php endforeach; ?>
<?php renderPaginator($pagination, $totalPages); ?> <?php renderPaginator($pagination, $totalPages); ?>
<?php
$html = ob_get_clean();
$htmlMin = new HtmlMin();
$htmlMin->doOptimizeAttributes(true);
$htmlMin->doRemoveComments(true);
$htmlMin->doSumUpWhitespace(true);
$htmlMin->doRemoveWhitespaceAroundTags(true);
$htmlMin->doOptimizeViaHtmlDomParser(false);
echo $htmlMin->minify($html);
?>

View file

@ -37,7 +37,7 @@ updated: "now"
decoding="async" decoding="async"
width="200" width="200"
height="307" height="307"
/> >
</a> </a>
<div class="media-meta"> <div class="media-meta">
<a href="{{ book.url }}"> <a href="{{ book.url }}">

View file

@ -40,7 +40,7 @@ schema: blog
decoding="async" decoding="async"
width="200" width="200"
height="auto" height="auto"
/> >
{%- endif -%} {%- endif -%}
{{ post.content | markdown }} {{ post.content | markdown }}
{% render "blocks/index.liquid", {% render "blocks/index.liquid",

View file

@ -23,7 +23,7 @@ excludeFromSitemap: true
decoding="async" decoding="async"
width="720" width="720"
height="480" height="480"
/> >
</div> </div>
<div> <div>
<h2 style="text-align:center">403</h2> <h2 style="text-align:center">403</h2>

View file

@ -23,7 +23,7 @@ excludeFromSitemap: true
decoding="async" decoding="async"
width="720" width="720"
height="480" height="480"
/> >
</div> </div>
<h2 style="text-align:center">404</h2> <h2 style="text-align:center">404</h2>
<p style="text-align:center">What kind of idiots do you have working here?</p> <p style="text-align:center">What kind of idiots do you have working here?</p>

View file

@ -23,7 +23,7 @@ excludeFromSitemap: true
decoding="async" decoding="async"
width="720" width="720"
height="480" height="480"
/> >
</div> </div>
<div style="text-align:center"> <div style="text-align:center">
<h2>429</h2> <h2>429</h2>

View file

@ -23,7 +23,7 @@ excludeFromSitemap: true
decoding="async" decoding="async"
width="720" width="720"
height="480" height="480"
/> >
</div> </div>
<div style="text-align:center"> <div style="text-align:center">
<h2>500</h2> <h2>500</h2>

View file

@ -84,7 +84,8 @@ description: Search through posts and other content on my site.
searchOptions: { searchOptions: {
fields: ["title", "tags"], fields: ["title", "tags"],
prefix: true, prefix: true,
fuzzy: 0.1, fuzzy: 0.3,
combineWith: "OR",
boost: { title: 5, tags: 2, description: 1 }, boost: { title: 5, tags: 2, description: 1 },
}, },
}); });
@ -94,12 +95,11 @@ description: Search through posts and other content on my site.
const $input = document.querySelector(".search__form--input"); const $input = document.querySelector(".search__form--input");
const $results = document.querySelector(".search__results"); const $results = document.querySelector(".search__results");
const $loadMoreButton = document.querySelector(".search__load-more"); const $loadMoreButton = document.querySelector(".search__load-more");
const $typeCheckboxes = document.querySelectorAll( const $typeCheckboxes = document.querySelectorAll('.search__form--type input[type="checkbox"]');
'.search__form--type input[type="checkbox"]',
);
$form.removeAttribute("action"); $form.removeAttribute("action");
$form.removeAttribute("method"); $form.removeAttribute("method");
if ($fallback) $fallback.remove(); if ($fallback) $fallback.remove();
const PAGE_SIZE = 10; const PAGE_SIZE = 10;
@ -107,7 +107,7 @@ description: Search through posts and other content on my site.
let currentResults = []; let currentResults = [];
let total = 0; let total = 0;
let debounceTimeout; let debounceTimeout;
let isLoading = false;
const parseMarkdown = (markdown) => const parseMarkdown = (markdown) =>
markdown markdown
? markdown ? markdown
@ -117,7 +117,6 @@ description: Search through posts and other content on my site.
.replace(/\n/g, "<br>") .replace(/\n/g, "<br>")
.replace(/[#*_~`]/g, "") .replace(/[#*_~`]/g, "")
: ""; : "";
const truncateDescription = (markdown, maxLength = 225) => { const truncateDescription = (markdown, maxLength = 225) => {
const plainText = const plainText =
new DOMParser().parseFromString(parseMarkdown(markdown), "text/html") new DOMParser().parseFromString(parseMarkdown(markdown), "text/html")
@ -126,12 +125,29 @@ description: Search through posts and other content on my site.
? `${plainText.substring(0, maxLength)}...` ? `${plainText.substring(0, maxLength)}...`
: plainText; : plainText;
}; };
const renderSearchResults = (results) => { const renderSearchResults = (results) => {
const resultHTML = results const resultHTML = results
.map( .map(
({ title, url, description, type, total_plays }) => ` ({ title, url, description, type, total_plays }) => `
<li class="search__results--result"> <li class="search__results--result">
<h3>
<a href="${url}">${title}</a>
${type === "artist" && total_plays > 0 ? ` <mark>${total_plays} plays</mark>` : ""}
</h3>
<p>${truncateDescription(description)}</p>
</li>
`,
)
.join("");
$results.innerHTML = resultHTML || '<li class="search__results--no-results">No results found.</li>';
$results.style.display = "block";
};
const appendSearchResults = (results) => {
const newResultsHTML = results
.map(
({ title, url, description, type, total_plays }) => `
<li class="search__results--result">
<h3> <h3>
<a href="${url}">${title}</a> <a href="${url}">${title}</a>
${ ${
@ -140,45 +156,50 @@ description: Search through posts and other content on my site.
: "" : ""
} }
</h3> </h3>
<p>${truncateDescription(description)}</p> <p>${truncateDescription(description)}</p>
</li> </li>
`, `,
) )
.join(""); .join("");
$results.insertAdjacentHTML("beforeend", newResultsHTML);
$results.innerHTML =
resultHTML ||
'<li class="search__results--no-results">No results found.</li>';
$results.style.display = "block";
}; };
const getSelectedTypes = () => Array.from($typeCheckboxes).filter((cb) => cb.checked).map((cb) => cb.value);
const loadSearchIndex = async (query, types, page) => { const loadSearchIndex = async (query, types, page) => {
isLoading = true;
$loadMoreButton.disabled = true;
$loadMoreButton.textContent = "Loading...";
try { try {
const typeQuery = types.join(","); const typeQuery = types.join(",");
const response = await fetch( const response = await fetch(
`https://www.coryd.dev/api/search.php?q=${query}&type=${typeQuery}&page=${page}&pageSize=${PAGE_SIZE}`, `https://www.coryd.dev/api/search.php?q=${encodeURIComponent(
query,
)}&type=${typeQuery}&page=${page}&pageSize=${PAGE_SIZE}`,
); );
const data = await response.json(); const data = await response.json();
total = data.total || 0; total = data.total || 0;
const formattedResults = (data.results || []).map((item) => ({ const formattedResults = (data.results || []).map((item) => ({
...item, ...item,
id: item.result_id, id: item.result_id,
})); }));
miniSearch.removeAll(); miniSearch.removeAll();
miniSearch.addAll(formattedResults); miniSearch.addAll(formattedResults);
return formattedResults; return formattedResults;
} catch (error) { } catch (error) {
console.error("Error fetching search data:", error); console.error("Error fetching search data:", error);
return []; return [];
} finally {
isLoading = false;
$loadMoreButton.disabled = false;
$loadMoreButton.textContent = "Load More";
} }
}; };
const getSelectedTypes = () =>
Array.from($typeCheckboxes)
.filter((cb) => cb.checked)
.map((cb) => cb.value);
const updateSearchResults = (results) => { const updateSearchResults = (results) => {
if (currentPage === 1) { if (currentPage === 1) {
renderSearchResults(results); renderSearchResults(results);
@ -189,58 +210,45 @@ description: Search through posts and other content on my site.
currentPage * PAGE_SIZE < total ? "block" : "none"; currentPage * PAGE_SIZE < total ? "block" : "none";
}; };
const appendSearchResults = (results) => {
const newResultsHTML = results
.map(
({ title, url, description, type, total_plays }) => `
<li class="search__results--result">
<h3>
<a href="${url}">${title}</a>
${
type === "artist" && total_plays > 0
? ` <mark>${total_plays} plays</mark>`
: ""
}
</h3>
<p>${truncateDescription(description)}</p>
</li>
`,
)
.join("");
$results.insertAdjacentHTML("beforeend", newResultsHTML);
};
const handleSearch = async () => { const handleSearch = async () => {
const query = $input.value.trim(); const query = $input.value.trim();
if (!query) { if (!query) {
renderSearchResults([]); renderSearchResults([]);
$loadMoreButton.style.display = "none"; $loadMoreButton.style.display = "none";
return; return;
} }
$results.innerHTML = '<li class="search__results--loading">Searching...</li>';
$results.style.display = "block";
$loadMoreButton.style.display = "none";
const results = await loadSearchIndex(query, getSelectedTypes(), 1); const results = await loadSearchIndex(query, getSelectedTypes(), 1);
currentResults = results; currentResults = results;
currentPage = 1; currentPage = 1;
updateSearchResults(results); updateSearchResults(results);
}; };
$input.addEventListener("input", () => { $input.addEventListener("input", () => {
clearTimeout(debounceTimeout); clearTimeout(debounceTimeout);
debounceTimeout = setTimeout(handleSearch, 150); debounceTimeout = setTimeout(handleSearch, 300);
}); });
$typeCheckboxes.forEach((cb) => $typeCheckboxes.forEach((cb) => cb.addEventListener("change", handleSearch));
cb.addEventListener("change", handleSearch),
);
$loadMoreButton.addEventListener("click", async () => { $loadMoreButton.addEventListener("click", async () => {
if (isLoading) return;
currentPage++; currentPage++;
const nextResults = await loadSearchIndex(
$input.value.trim(), const nextResults = await loadSearchIndex($input.value.trim(), getSelectedTypes(), currentPage);
getSelectedTypes(),
currentPage,
);
currentResults = [...currentResults, ...nextResults]; currentResults = [...currentResults, ...nextResults];
updateSearchResults(nextResults); updateSearchResults(nextResults);
}); });
})(); })();