Skip to content

feat(markdown): 新增响应式图片画廊网格#504

Merged
matsuzaka-yuki merged 3 commits into
LyraVoid:masterfrom
Dawn6666666:feat/markdown-image-grid
Jul 13, 2026
Merged

feat(markdown): 新增响应式图片画廊网格#504
matsuzaka-yuki merged 3 commits into
LyraVoid:masterfrom
Dawn6666666:feat/markdown-image-grid

Conversation

@Dawn6666666

@Dawn6666666 Dawn6666666 commented Jul 13, 2026

Copy link
Copy Markdown
Contributor

变更类型

  • Bug 修复(修复问题的非破坏性变更)
  • 新功能(新增功能的非破坏性变更)
  • 破坏性变更(会导致既有功能无法按预期工作的修复或功能)
  • 其他(请说明):

检查清单

  • 我已阅读 贡献指南
  • 我已确认此 Pull Request 不包含个人化改动。
  • 我已完成代码自检。
  • 本次改动未产生新的警告。

关联 Issue

Closes #503

改动内容

在 Mizuki 已有 Markdown 指令、rehype-components、Markdown 样式和 Fancybox 初始化流程的基础上,新增 :::grid 图片画廊指令:

:::grid{columns="3" aspect="16/9" fit="cover"}
![图片一](https://example.com/one.webp "可选图注")
![图片二](https://example.com/two.webp "可选图注")
![图片三](https://example.com/three.webp "可选图注")
:::
  • 支持 columns(1–6 列)、aspect(如 1/13/416/9)和 fitcover / contain)属性,并为非法值提供安全回退。
  • 新增 ImageGridComponent:将指令中的 Markdown 图片渲染成包含链接、图片与图注的语义化网格结构。
  • 在现有 Markdown 样式中增加响应式网格规则:小于 768px 时最多两列,小于 480px 时为单列;cover 模式统一填满展示框,contain 模式完整保留画面。
  • 新增网格专用 Fancybox 选择器和分组逻辑:每个网格独立轮播,不与正文普通图片或其他网格混合;普通文章图片原有行为保持不变。
  • 在网格作用域内隔离默认文章图片的外边距、圆角、尺寸和 object-fit 规则,避免留白、双重圆角或填充规则被覆盖。
  • 增加数字比例文本兼容处理,避免 remark-directive 将正文或 alt 文本中的 3:416:91:1 误判为文本指令;行内代码和围栏代码不受影响。
  • 新增完整演示文章与自动化测试。

测试方式

已执行并通过:

node --test tests/image-grid.test.mjs tests/remark-escape-numeric-colons.test.mjs
pnpm check
pnpm exec astro build

本地查看演示文章:

$env:ENABLE_CONTENT_SYNC = "false"
pnpm dev

然后访问:

http://localhost:4321/posts/image-grid-demo/

截图 / 在线演示

在线演示:https://mizuki-red-three.vercel.app/posts/image-grid-demo/

演示文章覆盖 1–6 列、横图、竖图、方图、极端宽高比、透明图,以及 covercontain 两种模式。

截图效果展示

以下截图来自在线演示,展示了图片画廊在实际主题中的布局、统一裁切与图注对齐效果;完整的交互和全部测试组合可在上方在线演示中查看。

展开查看页面效果截图(4 张)

图片画廊网格效果展示(一)

图片画廊网格效果展示(二)

图片画廊网格效果展示(三)

图片画廊网格效果展示(四)

其他说明

本 PR 仅包含图片画廊网格实现、对应测试和演示文章;未包含工作区中与此功能无关的本地改动。

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

为 Mizuki 的 Markdown 渲染链路新增 :::grid 容器指令,用于将一组 Markdown 图片渲染为响应式画廊网格,并与 Fancybox 灯箱分组逻辑集成,同时补齐 remark-directive 对数字比例(如 3:4)的误判兼容、测试与演示文章。

Changes:

  • 新增 ImageGridComponent:::grid → 语义化网格结构),支持 columns / aspect / fit 与非法值回退
  • 增加网格专用样式与 Fancybox 选择器/绑定逻辑,确保每个网格独立分组且不与正文普通图片混合
  • 增加数字比例冒号转义的 remark 插件、对应自动化测试与完整演示文章

Reviewed changes

Copilot reviewed 9 out of 9 changed files in this pull request and generated 7 comments.

Show a summary per file
File Description
tests/remark-escape-numeric-colons.test.mjs 覆盖数字比例冒号转义的行为测试(含代码场景)
tests/image-grid.test.mjs 覆盖网格渲染、分组与非法参数回退的单元测试
src/styles/markdown.css .image-grid 增加响应式网格、裁切/contain 规则与图注布局
src/scripts/handlers/fancybox-handler.ts Fancybox 初始化流程中新增网格选择器绑定
src/scripts/core/swup-config.ts 调整 Fancybox 选择器:排除网格图片并新增网格专用选择器
src/plugins/remark-escape-numeric-colons.mjs 在解析前转义 \d:\d,避免被 remark-directive 误判为指令
src/plugins/rehype-component-image-grid.mjs 新增 :::grid 组件渲染器:抽取图片并生成带 caption/分组的网格结构
src/content/posts/image-grid-demo.md 新增演示文章,覆盖 1–6 列、不同宽高比与 cover/contain 行为
astro.config.mjs 注册新 remark/rehype 组件与插件,并包含额外的字体 fallback 配置改动

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +10 to +14
function parseColumns(value) {
const columns = Number.parseInt(String(value ?? DEFAULT_COLUMNS), 10);
return Number.isInteger(columns) && columns >= 1 && columns <= 6
? columns
: DEFAULT_COLUMNS;
Comment thread tests/image-grid.test.mjs
Comment on lines +61 to +63
const firstGroup = firstGrid.children[0].children[0].properties.dataFancybox;
const secondGroup =
secondGrid.children[0].children[0].properties.dataFancybox;
Comment thread tests/image-grid.test.mjs
Comment on lines +67 to +70
assert.equal(
firstGrid.children[1].children[0].properties.dataFancybox,
firstGroup,
);
*/
export function escapeNumericColons(source) {
return source
.split(/(`{3,}[\s\S]*?`{3,}|~{3,}[\s\S]*?~{3,}|`+[^`\n]*`+)/g)
Comment on lines +15 to +16
test("does not alter inline or fenced code", () => {
const source = "`3:4`\n\n```text\n16:9\n```";
Comment thread astro.config.mjs
Comment on lines +60 to +64
// These variables are composed into --font-sans below. Keep their
// fallback lists empty; otherwise a system fallback after this Latin
// font prevents the following CJK font from ever being considered.
fallbacks: [],
optimizedFallbacks: false,
Comment thread astro.config.mjs
Comment on lines +79 to +82
// The final system fallback belongs to --font-sans, not this partial
// CJK font stack.
fallbacks: [],
optimizedFallbacks: false,
@Dawn6666666

Dawn6666666 commented Jul 13, 2026

Copy link
Copy Markdown
Contributor Author

补充说明:此分支最初从提交 1847785 fix(font): preserve composed CJK fallback 切出,因此该字体回退相关提交也被带入了本 PR。它不属于本次图片画廊网格功能的实现范围,也并非针对 #489 的修复。

该提交本身是一个独立的字体配置改动;若维护者认为需要保持本 PR 只聚焦图片画廊,我可以在后续按建议拆分或移除。

@matsuzaka-yuki matsuzaka-yuki merged commit 0326609 into LyraVoid:master Jul 13, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature]: 新增响应式 Markdown 图片画廊网格

3 participants