Skip to content

Commit

Permalink
add card mode and fix tags mode bug
Browse files Browse the repository at this point in the history
  • Loading branch information
TankCool committed Apr 16, 2022
1 parent f34b170 commit 3fdd3d7
Show file tree
Hide file tree
Showing 4 changed files with 4,235 additions and 4,285 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,6 @@ Random walk through your Logseq notes.
* `r n`: random note.
* Support switch random mode in command palette.
* Random note => page mode
* Random note => card mode
* Random note => tags mode
* Random note => query mode
41 changes: 30 additions & 11 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ const settingsTemplate = [
type: "enum",
default: "page",
title: "Random Mode",
description: "Page, tags or advanced query",
enumChoices: ["page", "tags", "query"],
description: "Page, card, tags or advanced query",
enumChoices: ["page", "card", "tags", "query"],
enumPicker: "radio",
},
{
Expand Down Expand Up @@ -85,7 +85,7 @@ function getQueryScript() {
[?p :block/journal? false]]`;
}
case "tags":
const tags = randomTags.map((item) => '"' + item + '"').join(",");
const tags = randomTags.map((item) => '"' + item.toLowerCase() + '"').join(",");
if (!logseq.settings.randomTags) {
logseq.App.showMsg("Random tags are required.", "warning");
}
Expand All @@ -100,6 +100,16 @@ function getQueryScript() {
`} ?name)]]
`
);
case "card":
return (
`
[:find (pull ?b [*])
:where
[?b :block/refs ?bp]
[?bp :block/name ?name]
[(contains? #{"card"} ?name)]]
`
);
case "query":
return logseq.settings.advancedQuery;
default:
Expand Down Expand Up @@ -131,12 +141,12 @@ function main() {
key: "logseq-random-note",
label: "Random note => Let's go",
keybinding: {
mode: 'non-editing',
binding: 'r n'
}
mode: "non-editing",
binding: "r n",
},
},
(data) => {
openRandomNote()
() => {
openRandomNote();
}
);

Expand All @@ -145,7 +155,7 @@ function main() {
key: "logseq-random-note:page-mode",
label: "Random note => page mode",
},
(data) => {
() => {
logseq.updateSettings({ randomMode: "page" });
}
);
Expand All @@ -154,16 +164,25 @@ function main() {
key: "logseq-random-note:tags-mode",
label: "Random note => tags mode",
},
(data) => {
() => {
logseq.updateSettings({ randomMode: "tags" });
}
);
logseq.App.registerCommandPalette(
{
key: "logseq-random-note:card-mode",
label: "Random note => card mode",
},
() => {
logseq.updateSettings({ randomMode: "card" });
}
);
logseq.App.registerCommandPalette(
{
key: "logseq-random-note:query-mode",
label: "Random note => query mode",
},
(data) => {
() => {
logseq.updateSettings({ randomMode: "query" });
}
);
Expand Down
Loading

0 comments on commit 3fdd3d7

Please sign in to comment.