dvargas92495 / SmartBlocks

Useful examples from developer community for Roam42 SmartBlocks
147 stars 7 forks source link

List pages in namespace v2 #185

Open zsviczian opened 3 years ago

zsviczian commented 3 years ago

Namespace-SB-JSON.zip

✂️ Copy of your #42SmartBlock from Roam

function getLocation(uid) { if (window.location.href.includes('/page/')) return window.location.href.substring(window.location.origin.length+1,window.location.href.length-9)+uid; else return window.location.href.substring(window.location.origin.length+1,window.location.href.length)+'/page/'+uid }

function pageLink(title, uid) { return [:div {:class "dont-focus-block"} [:a {:class "rm-page__title", :href "${getLocation(uid)}"} "${title}"]]; }

function toTwoDigits(number) { return ("0" + number).slice(-2); }

function msToDate(ms) { dt = new Date(ms); month = toTwoDigits(dt.getMonth()+1); day = toTwoDigits(dt.getDate()); year = dt.getFullYear(); uid = [month,day,year].join('-'); title = [year, month, day].join('-'); return pageLink(title,uid); }

function buildTable(value, index, array) { hiccup = hiccup + '[:tr [:td ' + pageLink(value[0], value[1]) + '] '; hiccup = hiccup + '[:td ' + msToDate(value[2]) + ']] '; }

var results = window.roamAlphaAPI.q([:find ?title ?uid ?time :in $ ?starts_with :where [?page :node/title ?title] [?page :block/uid ?uid] [?page :edit/time ?time] [(clojure.string/starts-with? ?title ?starts_with)]],namespace).forEach(buildTable); hiccup = hiccup + ']]' roam42.smartBlocks.activeWorkflow.outputAdditionalBlock(hiccup, false);```%>

📋 Describe the SmartBlock

Functionally similar to https://github.com/roamhacker/SmartBlocks/issues/184 but this outputs results to a :hiccup table.

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

None

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

image

💡 Additional Info

kalmir commented 3 years ago

Very cool, thanks!

RRoudt commented 3 years ago

This SmartBlock does not seem to work any longer? The only output I get is: Results:<%CURSOR%>