完美处理图片解析问题

This commit is contained in:
Yeban8090 2025-02-27 01:07:39 +08:00
parent 402cf58b70
commit 26198e1116
10 changed files with 43 additions and 122 deletions

BIN
assets/.DS_Store vendored

Binary file not shown.

Binary file not shown.

Binary file not shown.

Before

Width:  |  Height:  |  Size: 117 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 117 KiB

BIN
assets/qrcode.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.1 MiB

View file

@ -1,5 +1,5 @@
{
"templateId": "minimal",
"fontFamily": "SimSun, \"宋体\", serif",
"fontSize": 13
"templateId": "elegant",
"fontFamily": "Optima-Regular, Optima, PingFangSC-light, PingFangTC-light, \"PingFang SC\", Cambria, Cochin, Georgia, Times, \"Times New Roman\", serif",
"fontSize": 15
}

76
main.js

File diff suppressed because one or more lines are too long

View file

@ -134,15 +134,19 @@ export class MPConverter {
const originalSpan = el as HTMLElement;
const src = originalSpan.getAttribute('src');
const alt = originalSpan.getAttribute('alt');
const parentP = originalSpan.closest('p');
if (!src) return;
try {
const newImg = document.createElement('img');
const file = this.app.vault.getAbstractFileByPath(src);
// 获取文件的元数据
const linktext = src.split('|')[0]; // 处理可能带有别名的链接
console.log(src);
console.log(linktext);
const file = this.app.metadataCache.getFirstLinkpathDest(linktext, '');
console.log(file);
if (file) {
const absolutePath = this.app.vault.adapter.getResourcePath(src);
const absolutePath = this.app.vault.adapter.getResourcePath(file.path);
const newImg = document.createElement('img');
newImg.src = absolutePath;
if (alt) newImg.alt = alt;

View file

@ -17,7 +17,7 @@ export class DonateManager {
});
this.modal.createEl('h3', {
text: '请作者喝咖啡',
text: '关注作者',
cls: 'mp-donate-title'
});
@ -27,59 +27,30 @@ export class DonateManager {
// 添加温馨提示
content.createEl('p', {
text: '您的支持是我持续更新的动力 ❤️',
text: '如果你喜欢这个插件,欢迎关注我的公众号 ❤️',
cls: 'mp-donate-desc'
});
// 创建支付方式选择
const paymentTabs = content.createEl('div', {
cls: 'mp-donate-tabs'
});
const wechatTab = paymentTabs.createEl('button', {
text: '微信支付',
cls: 'mp-donate-tab active'
});
const alipayTab = paymentTabs.createEl('button', {
text: '支付宝',
cls: 'mp-donate-tab'
});
// 创建二维码显示区域
const qrContainer = content.createEl('div', {
cls: 'mp-donate-qr-container'
});
const wechatQR = qrContainer.createEl('div', {
cls: 'mp-donate-qr active',
attr: {
'data-type': 'wechat'
}
const qrCode = qrContainer.createEl('div', {
cls: 'mp-donate-qr active'
});
wechatQR.createEl('img', {
qrCode.createEl('img', {
attr: {
src: './assets/images/wechat-qr.png',
alt: '微信支付'
src: './assets/qrcode.png',
alt: '公众号二维码'
}
});
const alipayQR = qrContainer.createEl('div', {
cls: 'mp-donate-qr',
attr: {
'data-type': 'alipay'
}
// 添加公众号名称
content.createEl('p', {
text: '公众号:夜半',
cls: 'mp-donate-desc'
});
alipayQR.createEl('img', {
attr: {
src: 'assets/images/alipay-qr.png',
alt: '支付宝'
}
});
// 添加标签切换事件
wechatTab.addEventListener('click', () => this.switchTab('wechat', paymentTabs, qrContainer));
alipayTab.addEventListener('click', () => this.switchTab('alipay', paymentTabs, qrContainer));
// 添加关闭事件
closeButton.addEventListener('click', () => this.closeDonateModal());
@ -90,24 +61,6 @@ export class DonateManager {
});
}
private static switchTab(type: string, tabsContainer: HTMLElement, qrContainer: HTMLElement) {
// 更新标签状态
tabsContainer.querySelectorAll('.mp-donate-tab').forEach(tab => {
tab.classList.remove('active');
if (tab.textContent?.includes(type === 'wechat' ? '微信' : '支付宝')) {
tab.classList.add('active');
}
});
// 更新二维码显示
qrContainer.querySelectorAll('.mp-donate-qr').forEach(qr => {
qr.classList.remove('active');
if (qr.getAttribute('data-type') === type) {
qr.classList.add('active');
}
});
}
private static closeDonateModal() {
if (this.overlay) {
this.overlay.remove();

View file

@ -227,7 +227,7 @@ export class MPView extends ItemView {
const likeButton = bottomControlsGroup.createEl('button', {
cls: 'mp-like-button'
});
likeButton.innerHTML = '<span style="margin-right: 4px">☕️</span>请作者喝咖啡';
likeButton.innerHTML = '<span style="margin-right: 4px">☕️</span>喜欢作者';
likeButton.addEventListener('click', () => {
DonateManager.showDonateModal(this.containerEl);
});