SmartBlocks icon indicating copy to clipboard operation
SmartBlocks copied to clipboard

List Pages in a Namespace

Open zsviczian opened this issue 4 years ago • 1 comments

I added a new issue with a slightly alternative (and better) solution: see Issue 185

✂️ Copy of your #42SmartBlock from Roam

  • #42SmartBlock Namespace
    • <%NOBLOCKOUTPUT%><%J:```javascript var namespace = prompt('Namespace?','roam/'); window.roamAlphaAPI.q('[:find (pull ?e [*]) :where [?e :node/title] ]').forEach(search);

function search(value, index, array) { title = value[0]['title']; if (title.startsWith(namespace)) roam42.smartBlocks.activeWorkflow.outputAdditionalBlock('[['+title+']]', false); }```%>

📋 Describe the SmartBlock

Lists pages in a namespace, or more generically lists pages beginning with provided input.

✅ Describe any prerequisites or dependencies that are required for this SmartBlock

None

📷 Screenshot of your #42SmartBlock workflow/template from Roam

image

💡 Additional Info

I am 100% sure there is a nicer solution. This is the impatient man's solution... I did not have energy to read through and learn the query language. I think the solution is to use a clever predicate... but can't figure out how, and I am happy the SB works... so moving on. If you want further reading, this is where you find it:

Should you find a nicer solution, please let me know, I'd like to learn from a working example.

zsviczian avatar Jan 16 '21 11:01 zsviczian

As I have no idea how to do a pull request for a change here (sorry, I'm a Github noob), I'm going to leave this improvement as a comment. Special thanks to @dvargas92495 for helping me to make this SmartBlock work in the Roam desktop app.

- #42SmartBlock Namespace
    - <%NOBLOCKOUTPUT%><%JA:```javascript
return smalltalk.prompt("Roam42 SmartBlocks", "Namespace?", "roam/").then((namespace) => {
window.roamAlphaAPI.q('[:find (pull ?e [*]) :where [?e :node/title] ]').forEach(search);
function search(value, index, array) {
title = value[0]['title'];
if (title.startsWith(namespace))
roam42.smartBlocks.activeWorkflow.outputAdditionalBlock('[['+title+']]', false);
}
});```%>

RoamStack avatar Jun 15 '21 21:06 RoamStack