diff --git a/manifest.json b/manifest.json index dd80a55..58cadbf 100644 --- a/manifest.json +++ b/manifest.json @@ -1,7 +1,7 @@ { "id": "hugo-publish", "name": "Hugo Publish", - "version": "1.0.4", + "version": "1.0.5", "minAppVersion": "0.15.0", "description": "Publish your blog to hugo site.", "author": "kirito", diff --git a/package.json b/package.json index bcd8aa9..135a608 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "obsidian-sample-plugin", - "version": "1.0.4", + "version": "1.0.5", "description": "This is a sample plugin for Obsidian (https://obsidian.md)", "main": "main.js", "scripts": { diff --git a/src/main.ts b/src/main.ts index f9cf784..db0512b 100644 --- a/src/main.ts +++ b/src/main.ts @@ -172,7 +172,8 @@ export default class HugoPublishPlugin extends Plugin { const meta = this.app.metadataCache.getFileCache(f); - const link2path: Map = new Map(); + // link -> path,is_md + const link2path: Map = new Map(); const abf = this.app.vault.getAbstractFileByPath(f.path); // copy files to blog dir @@ -185,7 +186,7 @@ export default class HugoPublishPlugin extends Plugin { for (const v of meta.embeds) { const embed_f = this.app.metadataCache.getFirstLinkpathDest(v.link, f.path); if (embed_f) { - link2path.set(v.link, embed_f.path); + link2path.set(v.link, [embed_f.path, false]); const src = path.join(this.base_path, embed_f.path); const dst = path.join(this.settings.get_static_abs_dir(), embed_f.path); //console.log(`copy ${src} to ${dst}`); @@ -194,16 +195,19 @@ export default class HugoPublishPlugin extends Plugin { } } - // if (meta?.links) { - // for (const v of meta.links) { - // const link_f = this.app.metadataCache.getFirstLinkpathDest(v.link, f.path); - // console.log("link", v.link, link_f); - // if (link_f) { - // link2path.set(v.link, link_f.path); - // const src = - // } - // } - // } + if (meta?.links) { + for (const v of meta.links) { + const link_f = this.app.metadataCache.getFirstLinkpathDest(v.link, f.path); + //console.log("link", v.link, link_f); + if (link_f) { + let is_md = false; + if (link_f.path.endsWith(".md")) { + is_md = true; + link2path.set(v.link, [v.link, is_md]); + } + } + } + } const static_dir = this.settings.static_dir; //console.log("this", this); @@ -212,14 +216,22 @@ export default class HugoPublishPlugin extends Plugin { const decoded_url = decodeURI(node.url); const v = link2path.get(decoded_url) if (v) { - node.url = encodeURI(path.join("/", static_dir, v).replace(/\\/g, '/')); + // eslint-disable-next-line @typescript-eslint/no-unused-vars + const [vv, _is_md] = v; + node.url = encodeURI(path.join("/", static_dir, vv).replace(/\\/g, '/')); } }) visit(ast, 'link', function (node, index, parent) { const decoded_url = decodeURI(node.url); const v = link2path.get(decoded_url) if (v) { - node.url = encodeURI(path.join("/", static_dir, v).replace(/\\/g, '/')); + const [vv, is_md] = v; + if (is_md) { + // inner md link: [[abc]] -> [](/abc) -> https://www.blog.com/abc + node.url = encodeURI(path.join("/", vv).replace(/\\/g, '/')); + } else { + node.url = encodeURI(path.join("/", static_dir, vv).replace(/\\/g, '/')); + } } }) diff --git a/versions.json b/versions.json index 1b88544..78d00a4 100644 --- a/versions.json +++ b/versions.json @@ -2,5 +2,6 @@ "1.0.0": "0.15.0", "1.0.2": "0.15.0", "1.0.3": "0.15.0", - "1.0.4": "0.15.0" + "1.0.4": "0.15.0", + "1.0.5": "0.15.0" } \ No newline at end of file