修复首页标题光标单独换行 #18

Merged
enoch merged 1 commits from ChatGPT/laysense.cn:laysite-152-home-cursor into main 2026-11-28 15:05:45 +08:00
4 changed files with 66 additions and 1 deletions
Showing only changes of commit 8a8f6ca0f3 - Show all commits
+40
View File
@@ -0,0 +1,40 @@
<?php
declare(strict_types=1);
use App\Content\Database;
use App\Content\Media;
use App\Content\PageHead;
require dirname(__DIR__) . '/vendor/autoload.php';
$old = '86d3c75c2c280084ec6fcee11c501f45.js';
$new = '6354c518797c1214723222c27051d456.js';
$source = dirname(__DIR__) . '/storage/media/' . $new;
$changed = Database::write(static function (PDO $db) use ($old, $new, $source): bool {
$head = $db->query("SELECT head_html FROM pages WHERE slug = 'home'")->fetchColumn();
if (!is_string($head) || !str_contains($head, '/assets/uploads/' . $old)) {
return false;
}
$head = PageHead::normalize(str_replace('/assets/uploads/' . $old, '/assets/uploads/' . $new, $head));
$contents = file_get_contents($source);
if ($contents === false || substr(hash('sha256', $contents), 0, 32) . '.js' !== $new) {
throw new RuntimeException('首页动效文件缺失或校验失败。');
}
$destination = Media::directory() . '/' . $new;
if (is_file($destination)) {
if (hash_file('sha256', $destination) !== hash('sha256', $contents)) {
throw new RuntimeException('媒体库中同名文件的内容不一致。');
}
} elseif (!copy($source, $destination)) {
throw new RuntimeException('无法写入首页动效文件。');
}
$db->prepare("INSERT OR IGNORE INTO media (name, label, mime, size, created_at)
VALUES (?, 'laysense-home.js', 'text/javascript', ?, ?)")->execute([$new, strlen($contents), gmdate('c')]);
$db->prepare("UPDATE pages SET head_html = ?, version = version + 1 WHERE slug = 'home'")->execute([$head]);
return true;
});
echo $changed ? "首页光标已修复。\n" : "首页无需更新。\n";
+3 -1
View File
@@ -3,11 +3,13 @@
const homeHero = document.querySelector('#main-content > .hero-home'); const homeHero = document.querySelector('#main-content > .hero-home');
const homeTitle = homeHero?.querySelector('.hero-copy h1'); const homeTitle = homeHero?.querySelector('.hero-copy h1');
if (homeTitle) { if (homeTitle) {
const lastLine = homeTitle.querySelector('.hero-accent') || homeTitle.querySelector('.hero-heading-primary') || homeTitle;
const cursor = document.createElement('span'); const cursor = document.createElement('span');
cursor.className = 'home-cursor'; cursor.className = 'home-cursor';
cursor.setAttribute('aria-hidden', 'true'); cursor.setAttribute('aria-hidden', 'true');
cursor.textContent = '_'; cursor.textContent = '_';
homeTitle.append(cursor); // A word joiner prevents a narrow line from wrapping just the cursor.
lastLine.append('\u2060', cursor);
} }
const homeImage = homeHero?.querySelector('.hero-visual > img'); const homeImage = homeHero?.querySelector('.hero-visual > img');
Binary file not shown.
@@ -0,0 +1,23 @@
(() => {
'use strict';
const homeHero = document.querySelector('#main-content > .hero-home');
const homeTitle = homeHero?.querySelector('.hero-copy h1');
if (homeTitle) {
const lastLine = homeTitle.querySelector('.hero-accent') || homeTitle.querySelector('.hero-heading-primary') || homeTitle;
const cursor = document.createElement('span');
cursor.className = 'home-cursor';
cursor.setAttribute('aria-hidden', 'true');
cursor.textContent = '_';
// A word joiner prevents a narrow line from wrapping just the cursor.
lastLine.append('\u2060', cursor);
}
const homeImage = homeHero?.querySelector('.hero-visual > img');
if (homeImage && new URL(homeImage.src).pathname === "\/assets\/uploads\/a8e01ecf1e3d8932fc1f5a76297d3722.webp") {
homeImage.insertAdjacentHTML('afterend', "<svg class=\"home-pipe-flow\" viewBox=\"0 0 640 480\" aria-hidden=\"true\" focusable=\"false\">\n <defs>\n <path id=\"hero-pipe-tower\" pathLength=\"100\" d=\"M174 347 241 312 Q246 310 246 305 L246 299 Q246 295 252 293 L273 282\"\/>\n <path id=\"hero-pipe-disk\" pathLength=\"100\" d=\"M409 282 428 293 Q433 296 433 300 L433 304 Q433 307 438 309 L500 337\"\/>\n <path id=\"hero-pipe-node\" pathLength=\"100\" d=\"M119 201 125 205 Q129 207 129 212 L129 214 Q130 217 134 219 L190 243\"\/>\n <path id=\"hero-pipe-chart\" pathLength=\"100\" d=\"M443 226 471 213 Q478 208 483 209 L488 207 Q492 205 492 200 L492 182\"\/>\n <\/defs>\n <g class=\"home-pipe-route\"><use href=\"#hero-pipe-tower\"\/><use href=\"#hero-pipe-tower\"\/><\/g>\n <g class=\"home-pipe-route\"><use href=\"#hero-pipe-disk\"\/><use href=\"#hero-pipe-disk\"\/><\/g>\n <g class=\"home-pipe-route\"><use href=\"#hero-pipe-node\"\/><use href=\"#hero-pipe-node\"\/><\/g>\n <g class=\"home-pipe-route\"><use href=\"#hero-pipe-chart\"\/><use href=\"#hero-pipe-chart\"\/><\/g>\n<\/svg>\n");
}
document.querySelector('#main-content > .hero-home ~ #about')?.setAttribute('data-moment', 'iris-opens');
})();