From 1eba58bb92033a074710bc50d222ee6ae936925e Mon Sep 17 00:00:00 2001 From: Ad-closeNN <1709301095@qq.com> Date: Mon, 20 Apr 2026 10:08:44 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E7=BC=96=E8=AF=91=E5=9B=BE=E7=89=87?= =?UTF-8?q?=E6=97=B6=E5=8F=AF=E4=BB=A5=E6=8A=8A=E5=BC=80=E5=A4=B4=20/publi?= =?UTF-8?q?c=20=E5=AD=97=E6=AE=B5=E5=88=A0=E9=99=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 2. feat(component): 查看照片新增打开原图更改 3. fix(component): 修复查看图片时放大图片按钮失效的问题 --- .gitignore | 4 +- astro.config.mjs | 2 + src/components/misc/ImageWrapper.astro | 7 ++- src/global.d.ts | 6 +++ src/layouts/Layout.astro | 63 +++++++++++++++++++++-- src/plugins/remark-public-image-paths.mjs | 25 +++++++++ src/styles/photoswipe.css | 29 ++++++++++- 7 files changed, 126 insertions(+), 10 deletions(-) create mode 100644 src/plugins/remark-public-image-paths.mjs diff --git a/.gitignore b/.gitignore index 72c5b32..a96d723 100644 --- a/.gitignore +++ b/.gitignore @@ -30,4 +30,6 @@ src/content/.obsidian .playwright-mcp .serena -.claude \ No newline at end of file +.claude + +.obsidian \ No newline at end of file diff --git a/astro.config.mjs b/astro.config.mjs index c85f423..7cba635 100644 --- a/astro.config.mjs +++ b/astro.config.mjs @@ -21,6 +21,7 @@ import { AdmonitionComponent } from "./src/plugins/rehype-component-admonition.m import { GithubCardComponent } from "./src/plugins/rehype-component-github-card.mjs"; import { parseDirectiveNode } from "./src/plugins/remark-directive-rehype.js"; import { remarkExcerpt } from "./src/plugins/remark-excerpt.js"; +import { remarkPublicImagePaths } from "./src/plugins/remark-public-image-paths.mjs"; import { remarkReadingTime } from "./src/plugins/remark-reading-time.mjs"; import { pluginCustomCopyButton } from "./src/plugins/expressive-code/custom-copy-button.js"; import rehypeExternalLinks from 'rehype-external-links'; @@ -108,6 +109,7 @@ export default defineConfig({ remarkMath, remarkReadingTime, remarkExcerpt, + remarkPublicImagePaths, remarkGithubAdmonitionsToDirectives, remarkDirective, remarkSectionize, diff --git a/src/components/misc/ImageWrapper.astro b/src/components/misc/ImageWrapper.astro index 1d3487b..5c7edd6 100644 --- a/src/components/misc/ImageWrapper.astro +++ b/src/components/misc/ImageWrapper.astro @@ -46,9 +46,12 @@ if (isLocal) { const imageClass = "w-full h-full object-cover"; const imageStyle = `object-position: ${position}`; +const originalSrc = isLocal && img ? img.src : isPublic ? url(src) : src; +const originalWidth = isLocal && img ? img.width : undefined; +const originalHeight = isLocal && img ? img.height : undefined; ---
- {isLocal && img && {alt} - {!isLocal && {alt} + {isLocal && img && {alt} + {!isLocal && {alt}
diff --git a/src/global.d.ts b/src/global.d.ts index f6c8201..99b531f 100644 --- a/src/global.d.ts +++ b/src/global.d.ts @@ -11,6 +11,12 @@ type SwupLike = { type BlogPhotoSwipeState = { lightbox: { destroy: () => void; + on: (eventName: string, handler: (...args: unknown[]) => void) => void; + pswp?: { + ui?: { + registerElement: (options: Record) => void; + }; + }; } | null; hookRegistered: boolean; pageLoadRegistered: boolean; diff --git a/src/layouts/Layout.astro b/src/layouts/Layout.astro index 50f5b67..8d02524 100644 --- a/src/layouts/Layout.astro +++ b/src/layouts/Layout.astro @@ -634,6 +634,7 @@ window.onresize = () => {