Skip to content
This repository has been archived by the owner on Sep 20, 2024. It is now read-only.

Commit

Permalink
feat: Support opening the page on rendered tag.
Browse files Browse the repository at this point in the history
  • Loading branch information
jjaychen1e authored and peanball committed Jun 30, 2023
1 parent ce07403 commit 791f361
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ async function main() {
if (propertyName in properties) {
value = properties[propertyName]
if (propertyName === "tags" && formatTemplate === undefined) {
const htmlTemplate = '<a data-ref="${pageName}" class="tag">#${pageName}</a>'
const htmlTemplate = '<a data-ref="${pageName}" class="tag" data-on-click="openPage">#${pageName}</a>'
const separatorSpanTemplate = '<span> </span>'
if (Array.isArray(value)) {
value = `<div>${value.map((tag) => {
Expand Down Expand Up @@ -141,5 +141,17 @@ async function main() {
})
}

const model = {
openPage: async (e: any) => {
const pageName = e.dataset.ref
if (pageName) {
const pageEntity = await logseq.Editor.getPage(pageName)
if (pageEntity) {
await logseq.Editor.scrollToBlockInPage(pageName, pageEntity.uuid)
}
}
}
}

// bootstrap the plugin
logseq.ready(main).catch(console.error)
logseq.ready(model, main).catch(console.error)

0 comments on commit 791f361

Please sign in to comment.