From 8a8f6ca0f3dbc98374b957376732d220caad2511 Mon Sep 17 00:00:00 2001 From: Ziqi Shen Date: Sat, 28 Nov 2026 15:04:47 +0800 Subject: [PATCH] Keep the home title cursor on its last line --- site/fix-home-cursor.php | 40 ++++++++++++++++++ site/home.js | 4 +- storage/laysite.sqlite | Bin 323584 -> 323584 bytes .../media/6354c518797c1214723222c27051d456.js | 23 ++++++++++ 4 files changed, 66 insertions(+), 1 deletion(-) create mode 100644 site/fix-home-cursor.php create mode 100644 storage/media/6354c518797c1214723222c27051d456.js diff --git a/site/fix-home-cursor.php b/site/fix-home-cursor.php new file mode 100644 index 0000000..dc67bf7 --- /dev/null +++ b/site/fix-home-cursor.php @@ -0,0 +1,40 @@ +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"; diff --git a/site/home.js b/site/home.js index 0db06d0..9447197 100644 --- a/site/home.js +++ b/site/home.js @@ -3,11 +3,13 @@ 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 = '_'; - 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'); diff --git a/storage/laysite.sqlite b/storage/laysite.sqlite index 8790b4e978d6d2f47dc9d69d5149e861a88d9865..3d4d325853eb8a8e8130954b34d14d2cc23701cf 100644 GIT binary patch delta 228 zcmZp8Alv{%TNqh3FgvqaOlRM~sLjM`vE66`BMa;FgsqG$DrUx}CdsCT7Uq`b$%aOT zCgw)QMn*=-M&<^lhAAedW_nr0&f9@1mt-+Zv1v|cS70(`V$<9#DDak5GsT%bSXZ0L zo`aAf(|4#bDN8*zGB7gJH8j*UvIsFSw=yucGPck*Ft9Q(Xzy2J+TO3mJgHiNpiz#C Tm=`j#v_D?Ny#4Va7Fk~aa_2k2 delta 82 zcmZp8Alv{%TNqh3Fgvj(OlRM~sJ-1}10xITWCa1O?Fm~Mmt-+Zvh`1AS70*UEGQ7l m*50qiw7p-Ac~bTC8EQ<*(_I!Z&tqh6f4qo!`{P9{vc3RZ@Ebz_ diff --git a/storage/media/6354c518797c1214723222c27051d456.js b/storage/media/6354c518797c1214723222c27051d456.js new file mode 100644 index 0000000..e719be7 --- /dev/null +++ b/storage/media/6354c518797c1214723222c27051d456.js @@ -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', "\n \n \n \n \n \n <\/defs>\n <\/g>\n <\/g>\n <\/g>\n <\/g>\n<\/svg>\n"); +} + +document.querySelector('#main-content > .hero-home ~ #about')?.setAttribute('data-moment', 'iris-opens'); + +})(); -- 2.52.0