Skip to content

Instantly share code, notes, and snippets.

@ScottKillen
Created August 21, 2021 05:24
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save ScottKillen/ec858f6f7014fc41451b71e805413794 to your computer and use it in GitHub Desktop.
Save ScottKillen/ec858f6f7014fc41451b71e805413794 to your computer and use it in GitHub Desktop.
const apiUrl = "http://api.quotable.io/random?tags=";
async function start() {
var quote;
var cite;
const response = await fetch(apiUrl);
const data = await response.json();
if (response.ok) {
// Update DOM elements
quote = data.content;
cite = data.author;
} else {
quote = "An error occurred";
console.log(data);
}
/* Admonition color
* This generates the RGB components for a random color.
* Each component is generated in the 129 to 255 range to look better
* in dark themes. Remove '128 + ' from each component below for light
* themes.
*/
const red = Math.floor(128 + Math.random() * 128);
const green = Math.floor(128 + Math.random() * 128);
const blue = Math.floor(128 + Math.random() * 128);
/* Output
* This uses a template literal (https://www.javatpoint.com/es6-template-literals) to format the output
* for the obsidian note. Note that new lines are honored.
*
* This outputs a code block that will be formatted by the Admonition (https://github.com/valentine195/obsidian-admonition)
* plugin.
*/
return `\`\`\`ad-quote
title: Quote of the Day
color: ${red}, ${green}, ${blue}
${quote}
— <cite>${cite}</cite>
\`\`\``;
}
module.exports = start;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment