mirror of
https://github.com/jackyzha0/quartz.git
synced 2025-12-19 10:54:06 -06:00
Merge 8999a23af8 into bacd19c4ea
This commit is contained in:
commit
2762d726d3
@ -72,6 +72,7 @@ const config: QuartzConfig = {
|
||||
Plugin.CrawlLinks({ markdownLinkResolution: "shortest" }),
|
||||
Plugin.Description(),
|
||||
Plugin.Latex({ renderEngine: "katex" }),
|
||||
Plugin.ViewImage(),
|
||||
],
|
||||
filters: [Plugin.RemoveDrafts()],
|
||||
emitters: [
|
||||
|
||||
@ -11,3 +11,4 @@ export { SyntaxHighlighting } from "./syntax"
|
||||
export { TableOfContents } from "./toc"
|
||||
export { HardLineBreaks } from "./linebreaks"
|
||||
export { RoamFlavoredMarkdown } from "./roam"
|
||||
export { ViewImage } from "./viewImage"
|
||||
|
||||
102
quartz/plugins/transformers/viewImage.ts
Normal file
102
quartz/plugins/transformers/viewImage.ts
Normal file
@ -0,0 +1,102 @@
|
||||
import { QuartzTransformerPlugin } from "../types"
|
||||
|
||||
export const ViewImage: QuartzTransformerPlugin = () => {
|
||||
return {
|
||||
name: "ViewImage",
|
||||
externalResources() {
|
||||
return {
|
||||
css: [
|
||||
{
|
||||
content: `
|
||||
img {
|
||||
cursor: zoom-in !important;
|
||||
border: 2px dashed #284b63 !important;
|
||||
transition: border-color 0.2s ease !important;
|
||||
}
|
||||
img:hover {
|
||||
border-color: #1a365d !important;
|
||||
}
|
||||
`,
|
||||
inline: true,
|
||||
},
|
||||
],
|
||||
js: [
|
||||
{
|
||||
src: "https://cdn.jsdelivr.net/gh/Tokinx/ViewImage/view-image.min.js",
|
||||
loadTime: "afterDOMReady",
|
||||
contentType: "external",
|
||||
},
|
||||
{
|
||||
script: `
|
||||
function initViewImage() {
|
||||
if (window.ViewImage) {
|
||||
const existingImages = document.querySelectorAll('img[data-viewimage]');
|
||||
existingImages.forEach(img => {
|
||||
img.removeAttribute('data-viewimage');
|
||||
const newImg = img.cloneNode(true);
|
||||
img.parentNode.replaceChild(newImg, img);
|
||||
});
|
||||
|
||||
ViewImage.init('img');
|
||||
console.log('ViewImage灯箱插件已初始化,处理了', document.querySelectorAll('img').length, '张图片');
|
||||
} else {
|
||||
console.error('ViewImage库未加载成功');
|
||||
}
|
||||
}
|
||||
|
||||
function setupViewImageObserver() {
|
||||
const observer = new MutationObserver(function(mutations) {
|
||||
let shouldReinit = false;
|
||||
mutations.forEach(function(mutation) {
|
||||
if (mutation.type === 'childList') {
|
||||
mutation.addedNodes.forEach(function(node) {
|
||||
if (node.nodeType === Node.ELEMENT_NODE) {
|
||||
const element = node;
|
||||
if (element.tagName === 'IMG' || element.querySelector('img')) {
|
||||
shouldReinit = true;
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
if (shouldReinit) {
|
||||
console.log('检测到页面内容变化,重新初始化 ViewImage');
|
||||
setTimeout(initViewImage, 50);
|
||||
}
|
||||
});
|
||||
|
||||
observer.observe(document.body, {
|
||||
childList: true,
|
||||
subtree: true
|
||||
});
|
||||
|
||||
return observer;
|
||||
}
|
||||
|
||||
document.addEventListener('DOMContentLoaded', function() {
|
||||
initViewImage();
|
||||
setupViewImageObserver();
|
||||
});
|
||||
|
||||
document.addEventListener('nav', function() {
|
||||
console.log('SPA 导航事件触发,准备重新初始化 ViewImage');
|
||||
setTimeout(function() {
|
||||
initViewImage();
|
||||
}, 200);
|
||||
});
|
||||
`,
|
||||
loadTime: "afterDOMReady",
|
||||
contentType: "inline",
|
||||
},
|
||||
],
|
||||
}
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
declare module "vfile" {
|
||||
interface DataMap {
|
||||
viewImage?: boolean
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user