I am working on my first plugin, which will pull data from Spotify to get the songs that you have listened to today.
This is all working fine in testing, with the exception of an inability to properly format the output. At present it looks like this:
whereas obviously I would like it to look like this:
My code is as follows:
async function loadSpotifyData () {
const endpoint = 'http://localhost:5001/getsongs/?user_id=7f3d60ca90c1d957f0b16e2fd7d811ae16dffb6c'
const { data: { children } } = await fetch(endpoint).then(res => res.json())
let results_array = []
children.forEach(function (item, index) {
results_array.push(item['track_name'] + " by " + item['artist'])
});
let result_string = "🎺 Today you listened to on [[spotify]]:" + results_array
return result_string
}
function main () {
logseq.Editor.registerSlashCommand(
'💿 Recently played from Spotify',
async () => {
const { content, uuid } = await logseq.Editor.getCurrentBlock()
logseq.App.showMsg(`
[:div.p-2
[:h1 "Fetching from Spotify..."]
]
`)
logseq.Editor.insertAtEditingCursor (await loadSpotifyData())
},
)
logseq.Editor.registerBlockContextMenuItem('🎺 Spotify integration',
({ blockId }) => {
logseq.App.showMsg(
'🎺 Spotify integration'
)
})
}
// bootstrap
logseq.ready(main).catch(console.error)
Advice welcome please