style: 优化 UI 组件样式与布局并规范化 Hugo 头部解析

This commit is contained in:
seahi committed 2026-08-07 12:53:43 +08:00
1 parent 879e8e0692
commit e54ef0202d
7 files changed
+1063 -796

No files matched your search

+897 -722
View File
File diff suppressed because it is too large. Load diff
+3 -6
View File
@@ -3,20 +3,17 @@
declare global { declare global {
namespace App { namespace App {
interface Platform { interface Platform {
env: { env: Env;
DB: D1Database;
R2: R2Bucket;
} & Env;
context: ExecutionContext; context: ExecutionContext;
caches: CacheStorage & { default: Cache }; caches: CacheStorage & { default: Cache };
cf?: IncomingRequestCfProperties cf?: IncomingRequestCfProperties;
} }
// interface Error {} // interface Error {}
interface Locals { interface Locals {
user?: { user?: {
email: string; email: string;
} };
} }
// interface PageData {} // interface PageData {}
// interface PageState {} // interface PageState {}
+10 -3
View File
@@ -4,9 +4,16 @@
<meta charset="utf-8" /> <meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" /> <meta name="viewport" content="width=device-width, initial-scale=1" />
<meta name="text-scale" content="scale" /> <meta name="text-scale" content="scale" />
<link href="https://fonts.googleapis.com/css?family=Open+Sans:300,400,700&display=swap" rel="stylesheet"> <link
<link id="stylesheet_noto" href="https://fonts.googleapis.com/css?family=Noto+Serif+SC:300,400,700&display=swap&subset=chinese-simplified" rel="stylesheet"> href="https://fonts.googleapis.com/css?family=Open+Sans:300,400,700&display=swap"
<link href="https://fonts.googleapis.com/css?family=Fira+Code&display=swap" rel="stylesheet"> rel="stylesheet"
/>
<link
id="stylesheet_noto"
href="https://fonts.googleapis.com/css?family=Noto+Serif+SC:300,400,700&display=swap&subset=chinese-simplified"
rel="stylesheet"
/>
<link href="https://fonts.googleapis.com/css?family=Fira+Code&display=swap" rel="stylesheet" />
%sveltekit.head% %sveltekit.head%
</head> </head>
<body data-sveltekit-preload-data="hover"> <body data-sveltekit-preload-data="hover">
+45 -6
View File
@@ -12,26 +12,65 @@
out:fade={{ duration: 200 }} out:fade={{ duration: 200 }}
> >
{#if msg.type === 'success'} {#if msg.type === 'success'}
<svg viewBox="0 0 24 24" width="18" height="18" stroke="currentColor" stroke-width="2" fill="none" stroke-linecap="round" stroke-linejoin="round" class="toast-icon"> <svg
viewBox="0 0 24 24"
width="18"
height="18"
stroke="currentColor"
stroke-width="2"
fill="none"
stroke-linecap="round"
stroke-linejoin="round"
class="toast-icon"
>
<polyline points="20 6 9 17 4 12"></polyline> <polyline points="20 6 9 17 4 12"></polyline>
</svg> </svg>
{:else if msg.type === 'error'} {:else if msg.type === 'error'}
<svg viewBox="0 0 24 24" width="18" height="18" stroke="currentColor" stroke-width="2" fill="none" stroke-linecap="round" stroke-linejoin="round" class="toast-icon"> <svg
viewBox="0 0 24 24"
width="18"
height="18"
stroke="currentColor"
stroke-width="2"
fill="none"
stroke-linecap="round"
stroke-linejoin="round"
class="toast-icon"
>
<circle cx="12" cy="12" r="10"></circle> <circle cx="12" cy="12" r="10"></circle>
<line x1="15" y1="9" x2="9" y2="15"></line> <line x1="15" y1="9" x2="9" y2="15"></line>
<line x1="9" y1="9" x2="15" y2="15"></line> <line x1="9" y1="9" x2="15" y2="15"></line>
</svg> </svg>
{:else} {:else}
<svg viewBox="0 0 24 24" width="18" height="18" stroke="currentColor" stroke-width="2" fill="none" stroke-linecap="round" stroke-linejoin="round" class="toast-icon"> <svg
viewBox="0 0 24 24"
width="18"
height="18"
stroke="currentColor"
stroke-width="2"
fill="none"
stroke-linecap="round"
stroke-linejoin="round"
class="toast-icon"
>
<circle cx="12" cy="12" r="10"></circle> <circle cx="12" cy="12" r="10"></circle>
<line x1="12" y1="16" x2="12" y2="12"></line> <line x1="12" y1="16" x2="12" y2="12"></line>
<line x1="12" y1="8" x2="12.01" y2="8"></line> <line x1="12" y1="8" x2="12.01" y2="8"></line>
</svg> </svg>
{/if} {/if}
<span>{msg.text}</span> <span>{msg.text}</span>
<button class="toast-close" onclick={() => toastState.remove(msg.id)} aria-label="Close"> <button class="toast-close" onclick={() => toastState.remove(msg.id)} aria-label="Close">
<svg viewBox="0 0 24 24" width="14" height="14" stroke="currentColor" stroke-width="2" fill="none" stroke-linecap="round" stroke-linejoin="round"> <svg
viewBox="0 0 24 24"
width="14"
height="14"
stroke="currentColor"
stroke-width="2"
fill="none"
stroke-linecap="round"
stroke-linejoin="round"
>
<line x1="18" y1="6" x2="6" y2="18"></line> <line x1="18" y1="6" x2="6" y2="18"></line>
<line x1="6" y1="6" x2="18" y2="18"></line> <line x1="6" y1="6" x2="18" y2="18"></line>
</svg> </svg>
@@ -81,7 +120,7 @@
border-color: #d9534f; border-color: #d9534f;
color: #d9534f; color: #d9534f;
} }
.toast-msg.type-error .toast-close { .toast-msg.type-error .toast-close {
color: #d9534f; color: #d9534f;
} }
@@ -1,7 +1,8 @@
<script lang="ts"> <script lang="ts">
/* eslint-disable @typescript-eslint/no-explicit-any */
import { resolve } from '$app/paths';
import { addToast } from '$lib/stores/toast.svelte'; import { addToast } from '$lib/stores/toast.svelte';
import { Fancybox } from '@fancyapps/ui/dist/index.js';
import '@fancyapps/ui/dist/fancybox/fancybox.css';
import { onMount } from 'svelte'; import { onMount } from 'svelte';
import Tabs from './Tabs.svelte'; import Tabs from './Tabs.svelte';
@@ -22,14 +23,16 @@
}>(); }>();
let pickerElement = $state<HTMLDivElement>(); let pickerElement = $state<HTMLDivElement>();
let previewHeightRatio = $derived((() => { let previewHeightRatio = $derived(
const [width, height] = aspectRatio.split('/').map(Number); (() => {
return width > 0 && height > 0 ? height / width : 9 / 16; const [width, height] = aspectRatio.split('/').map(Number);
})()); return width > 0 && height > 0 ? height / width : 9 / 16;
})()
);
let activeTab = $state('url'); let activeTab = $state('url');
let isUploading = $state(false); let isUploading = $state(false);
let images = $state<any[]>([]); let images = $state<any[]>([]);
let page = $state(1); let page = $state(1);
let hasMore = $state(true); let hasMore = $state(true);
@@ -40,9 +43,19 @@
const selector = '[data-fancybox="featured-image-preview"]'; const selector = '[data-fancybox="featured-image-preview"]';
const container = pickerElement; const container = pickerElement;
Fancybox.bind(container, selector, {}); let FancyboxInstance: unknown = null;
return () => Fancybox.unbind(container, selector); import('@fancyapps/ui/dist/index.js').then(async ({ Fancybox }) => {
await import('@fancyapps/ui/dist/fancybox/fancybox.css');
FancyboxInstance = Fancybox;
Fancybox.bind(container, selector, {});
});
return () => {
if (FancyboxInstance) {
(FancyboxInstance as any).unbind(container, selector);
}
};
}); });
async function loadLibrary(reset = false) { async function loadLibrary(reset = false) {
@@ -56,7 +69,8 @@
isLoadingLibrary = true; isLoadingLibrary = true;
try { try {
const res = await fetch(`/admin/api/images?page=${page}&limit=12`); const res = await fetch(`/admin/api/images?page=${page}&limit=12`);
const data = await res.json() as any;
const data = (await res.json()) as any;
if (data.success) { if (data.success) {
images = [...images, ...data.images]; images = [...images, ...data.images];
if (page >= data.pagination.totalPages) { if (page >= data.pagination.totalPages) {
@@ -65,7 +79,7 @@
page++; page++;
} }
} }
} catch (err) { } catch (err: any) {
console.error(err); console.error(err);
addToast('加载图库失败', 'error'); addToast('加载图库失败', 'error');
} finally { } finally {
@@ -94,7 +108,8 @@
method: 'POST', method: 'POST',
body: formData body: formData
}); });
const data = await res.json() as any;
const data = (await res.json()) as any;
if (data.success) { if (data.success) {
cover = data.url; cover = data.url;
addToast('特色图上传成功', 'success'); addToast('特色图上传成功', 'success');
@@ -102,7 +117,7 @@
} else { } else {
addToast(data.error || '上传失败', 'error'); addToast(data.error || '上传失败', 'error');
} }
} catch (err) { } catch (err: any) {
console.error(err); console.error(err);
addToast('网络错误,上传失败', 'error'); addToast('网络错误,上传失败', 'error');
} finally { } finally {
@@ -116,7 +131,7 @@
{#if title} {#if title}
<h3>{title}</h3> <h3>{title}</h3>
{/if} {/if}
{#if cover} {#if cover}
<div <div
class="cover-preview" class="cover-preview"
@@ -126,7 +141,7 @@
{#if previewable} {#if previewable}
<a <a
class="cover-preview-link" class="cover-preview-link"
href={cover} href={resolve(cover)}
data-fancybox="featured-image-preview" data-fancybox="featured-image-preview"
data-caption={title || '特色图'} data-caption={title || '特色图'}
aria-label="查看特色图大图" aria-label="查看特色图大图"
@@ -137,17 +152,17 @@
{:else} {:else}
<img src={cover} alt="图片预览" /> <img src={cover} alt="图片预览" />
{/if} {/if}
<button type="button" class="btn-clear" onclick={() => cover = ''}>移除</button> <button type="button" class="btn-clear" onclick={() => (cover = '')}>移除</button>
</div> </div>
{/if} {/if}
<Tabs <Tabs
tabs={[ tabs={[
{ id: 'url', label: '链接' }, { id: 'url', label: '链接' },
{ id: 'upload', label: '直接上传' }, { id: 'upload', label: '直接上传' },
{ id: 'library', label: '图库选择' } { id: 'library', label: '图库选择' }
]} ]}
bind:activeTab bind:activeTab
fullWidth={true} fullWidth={true}
small={true} small={true}
onchange={handleTabChange} onchange={handleTabChange}
@@ -155,26 +170,49 @@
<div class="tab-content"> <div class="tab-content">
{#if activeTab === 'url'} {#if activeTab === 'url'}
<input type="url" placeholder="输入或粘贴图片链接" bind:value={cover} class="full-width-input" /> <input
type="url"
placeholder="输入或粘贴图片链接"
bind:value={cover}
class="full-width-input"
/>
{:else if activeTab === 'upload'} {:else if activeTab === 'upload'}
<div class="upload-area" class:disabled={isUploading}> <div class="upload-area" class:disabled={isUploading}>
<label> <label>
<span>{isUploading ? '正在上传...' : '点击选择图片上传'}</span> <span>{isUploading ? '正在上传...' : '点击选择图片上传'}</span>
<input type="file" accept="image/*" onchange={handleUpload} disabled={isUploading} style="display: none" /> <input
type="file"
accept="image/*"
onchange={handleUpload}
disabled={isUploading}
style="display: none"
/>
</label> </label>
</div> </div>
{:else if activeTab === 'library'} {:else if activeTab === 'library'}
<div class="library-grid"> <div class="library-grid">
{#each images as img} {#each images as img (img.id || img)}
<!-- svelte-ignore a11y_click_events_have_key_events --> <!-- svelte-ignore a11y_click_events_have_key_events -->
<!-- svelte-ignore a11y_no_static_element_interactions --> <!-- svelte-ignore a11y_no_static_element_interactions -->
<div class="library-item" onclick={() => { cover = img.url; activeTab = 'url'; }} title={img.filename}> <div
class="library-item"
onclick={() => {
cover = img.url;
activeTab = 'url';
}}
title={img.filename}
>
<img src={img.url} alt={img.filename} loading="lazy" /> <img src={img.url} alt={img.filename} loading="lazy" />
</div> </div>
{/each} {/each}
</div> </div>
{#if hasMore} {#if hasMore}
<button type="button" class="btn-load-more" onclick={() => loadLibrary()} disabled={isLoadingLibrary}> <button
type="button"
class="btn-load-more"
onclick={() => loadLibrary()}
disabled={isLoadingLibrary}
>
{isLoadingLibrary ? '加载中...' : '加载更多'} {isLoadingLibrary ? '加载中...' : '加载更多'}
</button> </button>
{/if} {/if}
@@ -246,7 +284,7 @@
font-weight: 600; font-weight: 600;
backdrop-filter: blur(4px); backdrop-filter: blur(4px);
} }
.btn-clear:hover { .btn-clear:hover {
background: rgba(217, 83, 79, 1); background: rgba(217, 83, 79, 1);
} }
@@ -259,7 +297,9 @@
font-family: inherit; font-family: inherit;
box-sizing: border-box; box-sizing: border-box;
border-radius: 0; border-radius: 0;
transition: border-color 0.3s ease, box-shadow 0.3s ease; transition:
border-color 0.3s ease,
box-shadow 0.3s ease;
} }
.full-width-input:focus { .full-width-input:focus {
@@ -280,9 +320,9 @@
} }
.upload-area label:hover { .upload-area label:hover {
background: rgba(0,0,0,0.03); background: rgba(0, 0, 0, 0.03);
} }
.upload-area.disabled label { .upload-area.disabled label {
opacity: 0.6; opacity: 0.6;
cursor: not-allowed; cursor: not-allowed;
+15 -15
View File
@@ -1,15 +1,15 @@
<script lang="ts"> <script lang="ts">
type Tab = { id: string; label: string }; type Tab = { id: string; label: string };
let { let {
tabs = [], tabs = [],
activeTab = $bindable(), activeTab = $bindable(),
fullWidth = false, fullWidth = false,
small = false, small = false,
onchange onchange
} = $props<{ } = $props<{
tabs: Tab[]; tabs: Tab[];
activeTab: string; activeTab: string;
fullWidth?: boolean; fullWidth?: boolean;
small?: boolean; small?: boolean;
onchange?: (id: string) => void; onchange?: (id: string) => void;
@@ -21,12 +21,12 @@
} }
</script> </script>
<div class="tabs-header" class:full-width={fullWidth} class:small={small}> <div class="tabs-header" class:full-width={fullWidth} class:small>
{#each tabs as tab} {#each tabs as tab (tab.id || tab)}
<button <button
type="button" type="button"
class="tab-btn" class="tab-btn"
class:active={activeTab === tab.id} class:active={activeTab === tab.id}
onclick={() => select(tab.id)} onclick={() => select(tab.id)}
> >
{tab.label} {tab.label}
@@ -38,7 +38,7 @@
.tabs-header { .tabs-header {
display: flex; display: flex;
gap: 20px; gap: 20px;
border-bottom: 2px solid var(--border-color, rgba(0,0,0,0.1)); border-bottom: 2px solid var(--border-color, rgba(0, 0, 0, 0.1));
margin-bottom: 20px; margin-bottom: 20px;
} }
@@ -67,7 +67,7 @@
font-size: 1rem; font-size: 1rem;
font-family: inherit; font-family: inherit;
font-weight: 600; font-weight: 600;
color: var(--text-muted, rgba(0,0,0,0.5)); color: var(--text-muted, rgba(0, 0, 0, 0.5));
cursor: pointer; cursor: pointer;
border-bottom: 3px solid transparent; border-bottom: 3px solid transparent;
margin-bottom: -2px; margin-bottom: -2px;
+25 -16
View File
@@ -1,3 +1,5 @@
/* eslint-disable @typescript-eslint/no-explicit-any */
/* eslint-disable @typescript-eslint/no-unused-vars */
import { parse as parseToml } from 'smol-toml'; import { parse as parseToml } from 'smol-toml';
import { parse as parseYaml } from 'yaml'; import { parse as parseYaml } from 'yaml';
@@ -25,7 +27,7 @@ function parseOrCurrentDate(val: unknown): string {
return new Date().toISOString(); return new Date().toISOString();
} }
return dateObj.toISOString(); return dateObj.toISOString();
} catch { } catch (err: any) {
return new Date().toISOString(); return new Date().toISOString();
} }
} }
@@ -75,26 +77,30 @@ export function parseHugoMarkdown(rawContent: string, fileName = ''): HugoPostDa
if (endIndex !== -1) { if (endIndex !== -1) {
const frontmatter = text.substring(3, endIndex).trim(); const frontmatter = text.substring(3, endIndex).trim();
bodyContent = text.substring(endIndex + 4).trim(); bodyContent = text.substring(endIndex + 4).trim();
meta = parseToml(frontmatter) as Record<string, unknown>; meta = parseToml(frontmatter) as Record<string, any>;
} }
} }
// 2. 检识常规 YAML (以 --- 开头包络) // 2. 检识常规 YAML (以 --- 开头包络)
else if (text.startsWith('---')) { else if (text.startsWith('---')) {
const endIndex = text.indexOf('\n---', 3); const endIndex = text.indexOf('\n---', 3);
if (endIndex !== -1) { if (endIndex !== -1) {
const frontmatter = text.substring(3, endIndex).trim(); const frontmatter = text.substring(3, endIndex).trim();
bodyContent = text.substring(endIndex + 4).trim(); bodyContent = text.substring(endIndex + 4).trim();
meta = parseYaml(frontmatter) as Record<string, unknown>; meta = parseYaml(frontmatter) as Record<string, any>;
} }
} }
} catch (err) { } catch (err: any) {
console.error('解析 Markdown 头部参数时出现异常,直接回货底稿正文并对时差退回初始系统时刻:', err); console.error(
'解析 Markdown 头部参数时出现异常,直接回货底稿正文并对时差退回初始系统时刻:',
err
);
// 当解析受卡出错,空字典依然不阻挠对下方日期与稿费正文字面的顺利捕拾 // 当解析受卡出错,空字典依然不阻挠对下方日期与稿费正文字面的顺利捕拾
} }
// 取值并完成映射:除以下对应参数处,诸如 draft/twemoji/lightgallery 等全在空载转储里随水蒸丢! // 取值并完成映射:除以下对应参数处,诸如 draft/twemoji/lightgallery 等全在空载转储里随水蒸丢!
const title = typeof meta.title === 'string' && meta.title.trim() !== '' ? meta.title.trim() : defaultName; const title =
typeof meta.title === 'string' && meta.title.trim() !== '' ? meta.title.trim() : defaultName;
let slug = typeof meta.slug === 'string' ? meta.slug.trim() : ''; let slug = typeof meta.slug === 'string' ? meta.slug.trim() : '';
if (!slug) { if (!slug) {
// 没有声明明确的 slug 时,由名目精简转化出基础链接字符串 // 没有声明明确的 slug 时,由名目精简转化出基础链接字符串
@@ -108,17 +114,20 @@ export function parseHugoMarkdown(rawContent: string, fileName = ''): HugoPostDa
} }
// 特色图片字段识别(首挑 featuredImage,也兼备处理 cover/image) // 特色图片字段识别(首挑 featuredImage,也兼备处理 cover/image)
const cover = typeof meta.featuredImage === 'string' const cover =
? meta.featuredImage.trim() typeof meta.featuredImage === 'string'
: typeof meta.cover === 'string' ? meta.featuredImage.trim()
? meta.cover.trim() : typeof meta.cover === 'string'
: typeof meta.image === 'string' ? meta.cover.trim()
? meta.image.trim() : typeof meta.image === 'string'
: ''; ? meta.image.trim()
: '';
// 时间字段转化:严格按需求约定“一旦转换错漏或是全无,采用目前时刻填满” // 时间字段转化:严格按需求约定“一旦转换错漏或是全无,采用目前时刻填满”
const published_at = parseOrCurrentDate(meta.date || meta.published_at); const published_at = parseOrCurrentDate(meta.date || meta.published_at);
const updated_at = parseOrCurrentDate(meta.lastmod || meta.updated_at || meta.date || meta.published_at); const updated_at = parseOrCurrentDate(
meta.lastmod || meta.updated_at || meta.date || meta.published_at
);
return { return {
title: title || '无名小贴', title: title || '无名小贴',