Created
August 9, 2024 14:02
-
-
Save nicolevanderhoeven/11acb0ac0fb0dd88f971a0a7132fb838 to your computer and use it in GitHub Desktop.
Writes Dataview query results to a Markdown note in Obsidian
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function getNumOfGames(campaign) { | |
let numOfGames = app.plugins.plugins.dataview.api | |
.pages(`"ttrpgs/${campaign}"`) | |
.where(page => { | |
if (page.type === 'session') { | |
if (page.campaign === campaign) { | |
return true; | |
} | |
} | |
}).length | |
return numOfGames; | |
} | |
function getCampaignList () { | |
let dv = app.plugins.plugins.dataview.api; | |
let campaigns = dv.pages('"ttrpgs"').where(b => b.type === "world").sort(p => p.status); | |
console.log(campaigns); | |
let results = [ | |
`|Campaign|System|Sessions|Role|Status| | |
|---|---|---|---|---| | |
`, | |
]; | |
campaigns.forEach(campaign => { | |
let numOfGames = getNumOfGames(campaign.campaign); | |
results += `|[[${campaign.file.path}\\|${campaign.campaign}]]| ${campaign.system}|${numOfGames}|${campaign.role}|${campaign.status}|\n` | |
}); | |
return results; | |
}; | |
module.exports = getCampaignList; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment