mirror of
https://github.com/woodchen-ink/obsidian-publish-to-discourse.git
synced 2025-07-18 13:52:07 +08:00
Compare commits
2 Commits
Author | SHA1 | Date | |
---|---|---|---|
6b81570366 | |||
094784f28e |
@ -1,7 +1,7 @@
|
||||
{
|
||||
"id": "publish-to-discourse",
|
||||
"name": "Publish to Discourse",
|
||||
"version": "1.0.12",
|
||||
"version": "1.0.13",
|
||||
"minAppVersion": "0.15.0",
|
||||
"description": "Publish notes to the Discourse forum.",
|
||||
"author": "WoodChen",
|
||||
|
4
package-lock.json
generated
4
package-lock.json
generated
@ -1,12 +1,12 @@
|
||||
{
|
||||
"name": "obsidian-publish-to-discourse",
|
||||
"version": "1.0.12",
|
||||
"version": "1.0.13",
|
||||
"lockfileVersion": 3,
|
||||
"requires": true,
|
||||
"packages": {
|
||||
"": {
|
||||
"name": "obsidian-publish-to-discourse",
|
||||
"version": "1.0.12",
|
||||
"version": "1.0.13",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"yaml": "^2.7.0"
|
||||
|
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "obsidian-publish-to-discourse",
|
||||
"version": "1.0.12",
|
||||
"version": "1.0.13",
|
||||
"description": "Post notes to the Discourse forum.",
|
||||
"main": "main.js",
|
||||
"scripts": {
|
||||
|
19
src/main.ts
19
src/main.ts
@ -58,7 +58,7 @@ export default class DiscourseSyncPlugin extends Plugin {
|
||||
}
|
||||
|
||||
extractImageReferences(content: string): string[] {
|
||||
const regex = /!\[\[(.*?)\]\]/g;
|
||||
const regex = /!\[\[(.*?)(?:\|.*?)?\]\]/g;
|
||||
const matches = [];
|
||||
let match;
|
||||
while ((match = regex.exec(content)) !== null) {
|
||||
@ -150,10 +150,12 @@ export default class DiscourseSyncPlugin extends Plugin {
|
||||
const imageReferences = this.extractImageReferences(content);
|
||||
const imageUrls = await this.uploadImages(imageReferences);
|
||||
|
||||
// 替换所有图片引用,包括带有属性的图片
|
||||
imageReferences.forEach((ref, index) => {
|
||||
const obsRef = `![[${ref}]]`;
|
||||
// 使用正则表达式匹配包含属性的图片引用
|
||||
const regex = new RegExp(`!\\[\\[${ref.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')}(?:\\|.*?)?\\]\\]`, 'g');
|
||||
const discoRef = ``;
|
||||
content = content.replace(obsRef, discoRef);
|
||||
content = content.replace(regex, discoRef);
|
||||
});
|
||||
|
||||
const isUpdate = postId !== undefined;
|
||||
@ -342,6 +344,13 @@ export default class DiscourseSyncPlugin extends Plugin {
|
||||
}
|
||||
|
||||
await this.app.vault.modify(activeFile, newContent);
|
||||
|
||||
// 更新 activeFile 对象,确保它反映最新状态
|
||||
this.activeFile = {
|
||||
name: activeFile.basename,
|
||||
content: newContent,
|
||||
postId: postId
|
||||
};
|
||||
} catch (error) {
|
||||
return {
|
||||
message: "Error",
|
||||
@ -517,8 +526,7 @@ export default class DiscourseSyncPlugin extends Plugin {
|
||||
}
|
||||
|
||||
private async openCategoryModal() {
|
||||
// 确保activeFile已设置
|
||||
if (!this.activeFile) {
|
||||
// 每次都重新获取 activeFile 的最新内容,不使用缓存
|
||||
const activeFile = this.app.workspace.getActiveFile();
|
||||
if (!activeFile) {
|
||||
new NotifyUser(this.app, t('NO_ACTIVE_FILE')).open();
|
||||
@ -532,7 +540,6 @@ export default class DiscourseSyncPlugin extends Plugin {
|
||||
content: content,
|
||||
postId: fm?.discourse_post_id
|
||||
};
|
||||
}
|
||||
|
||||
const [categories, tags] = await Promise.all([
|
||||
this.fetchCategories(),
|
||||
|
@ -11,5 +11,6 @@
|
||||
"1.0.9": "0.15.0",
|
||||
"1.0.10": "0.15.0",
|
||||
"1.0.11": "0.15.0",
|
||||
"1.0.12": "0.15.0"
|
||||
"1.0.12": "0.15.0",
|
||||
"1.0.13": "0.15.0"
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user