Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/deploy-pages.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ on:
branches:
- main
paths:
- "README.md"
- "book/**"
- "site/**"
- "scripts/prepare_book.py"
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ DeepSeek Harness(简称 dsh)是一套由插件组装而成的 Agent Harness

| [短剧画面](https://dshbook.penguin.ooo/chapter8/) | [活动海报](https://dshbook.penguin.ooo/chapter7/) | [自进化概念图](https://dshbook.penguin.ooo/chapter13/) |
| --- | --- | --- |
| [![dsh 生成短剧关键帧](book/assets/chapter8/8-2-07-frame-hook.png)](https://dshbook.penguin.ooo/chapter8/) | [![dsh 生成社区读书会海报](book/assets/chapter7/7-4-01-poster-final-export.png)](https://dshbook.penguin.ooo/chapter7/) | [![dsh 复用演化后的 Skill 生成概念图](book/assets/chapter13/13-2-07-skill-reuse.png)](https://dshbook.penguin.ooo/chapter13/) |
| ![dsh 生成短剧关键帧](book/assets/chapter8/8-2-07-frame-hook.png) | ![dsh 生成社区读书会海报](book/assets/chapter7/7-4-01-poster-final-export.png) | ![dsh 复用演化后的 Skill 生成概念图](book/assets/chapter13/13-2-07-skill-reuse.png) |

## 📚 内容导航

Expand Down
1 change: 1 addition & 0 deletions mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ extra_css:
extra_javascript:
- javascripts/sidebar-toggle.js
- javascripts/drawer-scroll-lock.js
- javascripts/image-zoom.js
- javascripts/mathjax.js
- https://unpkg.com/mathjax@3/es5/tex-mml-chtml.js

Expand Down
112 changes: 112 additions & 0 deletions site/javascripts/image-zoom.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
(() => {
const imageSelector =
".md-typeset img.book-figure-image, .md-typeset .readme-page table img";

let dialog = null;
let previewImg = null;
let captionEl = null;
let activeSourceImg = null;

const getCaptionText = (img) => {
const itemNote = img
.closest(".book-figure-item")
?.querySelector(".book-figure-note")
?.textContent?.trim();
const figCaption = img
.closest("figure")
?.querySelector("figcaption")
?.textContent?.trim();
if (itemNote && figCaption && !figCaption.includes(itemNote)) {
return `${figCaption}(${itemNote})`;
}
if (figCaption) return figCaption;
if (itemNote) return itemNote;
return img.getAttribute("alt")?.trim() ?? "";
};

const updatePreviewSize = (sourceImg) => {
if (!previewImg || !sourceImg) return;
const rect = sourceImg.getBoundingClientRect();
const naturalWidth = sourceImg.naturalWidth || rect.width || 800;
const naturalHeight = sourceImg.naturalHeight || rect.height || 600;
const aspect = naturalWidth / Math.max(naturalHeight, 1);

const maxWidth = Math.min(window.innerWidth * 0.92, 1280);
const maxHeight = window.innerHeight * 0.82;
const src = sourceImg.currentSrc || sourceImg.src || "";
const isSvg = /\.svg($|[?#])/i.test(src);

const desiredWidth = isSvg
? maxWidth
: Math.max(naturalWidth, Math.round(rect.width * 1.75), 760);
const desiredHeight = desiredWidth / aspect;
const scale = Math.min(1, maxWidth / desiredWidth, maxHeight / desiredHeight);
const finalWidth = Math.max(1, Math.round(desiredWidth * scale));

previewImg.style.width = `${finalWidth}px`;
};

const ensureDialog = () => {
if (dialog) return dialog;

dialog = document.createElement("dialog");
dialog.className = "book-image-lightbox";
dialog.setAttribute("aria-label", "图片放大预览");

const figure = document.createElement("figure");
figure.className = "book-image-lightbox__figure";

previewImg = document.createElement("img");
previewImg.className = "book-image-lightbox__image";
previewImg.alt = "";

captionEl = document.createElement("figcaption");
captionEl.className = "book-image-lightbox__caption";

figure.append(previewImg, captionEl);
dialog.append(figure);
document.body.append(dialog);

dialog.addEventListener("click", () => {
dialog.close();
});

dialog.addEventListener("close", () => {
document.documentElement.classList.remove("book-lightbox-open");
activeSourceImg = null;
});

window.addEventListener("resize", () => {
if (dialog?.open && activeSourceImg) {
updatePreviewSize(activeSourceImg);
}
});

return dialog;
};

document.addEventListener("click", (event) => {
const target = event.target;
if (!(target instanceof HTMLImageElement)) return;
if (!target.matches(imageSelector)) return;
if (target.closest("a")) return;

const modal = ensureDialog();
const src = target.currentSrc || target.src;
if (!src) return;

activeSourceImg = target;
previewImg.src = src;
previewImg.alt = target.alt || "";
updatePreviewSize(target);

const caption = getCaptionText(target);
captionEl.textContent = caption;
captionEl.hidden = !caption;

document.documentElement.classList.add("book-lightbox-open");
if (!modal.open) {
modal.showModal();
}
});
})();
62 changes: 62 additions & 0 deletions site/stylesheets/extra.css
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,68 @@ input {
padding: clamp(0.25rem, 0.7vw, 0.55rem);
}

.md-typeset img.book-figure-image,
.md-typeset .readme-page table img {
cursor: zoom-in;
}

html.book-lightbox-open,
html.book-lightbox-open body {
overflow: hidden;
}

.book-image-lightbox {
align-items: center;
background: transparent;
border: 0;
box-sizing: border-box;
cursor: zoom-out;
display: none;
height: 100vh;
justify-content: center;
margin: 0;
max-height: none;
max-width: none;
padding: 1.5rem;
width: 100vw;
}

.book-image-lightbox[open] {
display: flex;
}

.book-image-lightbox::backdrop {
background: rgb(15 23 42 / 78%);
backdrop-filter: blur(2px);
}

.book-image-lightbox__figure {
align-items: center;
display: flex;
flex-direction: column;
margin: 0;
max-height: 100%;
max-width: 100%;
}

.book-image-lightbox__image {
box-shadow: 0 20px 50px rgb(0 0 0 / 45%);
display: block;
height: auto;
max-height: 82vh;
max-width: min(92vw, 80rem);
object-fit: contain;
}

.book-image-lightbox__caption {
color: rgba(248, 250, 252, 0.92);
font-size: 0.78rem;
line-height: 1.55;
margin-top: 0.75rem;
max-width: min(88vw, 60rem);
text-align: center;
}

/* 表格块居中;表头和短标签列居中,说明文字继续左对齐。 */
.md-typeset__scrollwrap:has(> .md-typeset__table) {
margin-left: auto;
Expand Down
7 changes: 7 additions & 0 deletions tests/test_prepare_site.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,13 @@ def test_prepares_readme_as_web_homepage(self) -> None:
rendered,
)

def test_readme_case_images_are_not_wrapped_in_links(self) -> None:
readme_text = (ROOT / "README.md").read_text(encoding="utf-8")
rendered = transform_readme(readme_text, "https://github.com/example/book")
self.assertIn("| [短剧画面](chapter8.md) | [活动海报](chapter7.md) | [自进化概念图](chapter13.md) |", rendered)
self.assertIn("| ![dsh 生成短剧关键帧](assets/chapter8/8-2-07-frame-hook.png) |", rendered)
self.assertNotIn("[![dsh 生成短剧关键帧]", rendered)

def test_adds_visible_caption_to_standalone_markdown_image(self) -> None:
source = (
"正文。\n\n"
Expand Down
Loading