Skip to content

Instantly share code, notes, and snippets.

@nicolevanderhoeven
Created August 9, 2024 14:02
Show Gist options
  • Save nicolevanderhoeven/11acb0ac0fb0dd88f971a0a7132fb838 to your computer and use it in GitHub Desktop.
Save nicolevanderhoeven/11acb0ac0fb0dd88f971a0a7132fb838 to your computer and use it in GitHub Desktop.
Writes Dataview query results to a Markdown note in Obsidian
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