Bibliography Generator

Hello, I was getting tired to every single moment I need to put a bibliography to my note, fill a template and need to worry about the formatting, so, I made this code to Templater plugin, and I hope it can be useful for someone (:

NOTE: I using the ABNT Bibliography Style to format the string, but its very similar to Chicago or Harvard, and I don’t think is interesting to put some stuff like local or publishing company, but feel free to modify the code and publish the way you think is best.

<%*
let lastname = await tp.system.prompt("Author Last Name", "Unknown", true, "ERRO!")
let authorname = await tp.system.prompt("Author Name", "Unknown", true, "ERRO!")
let date = await tp.system.prompt("Year", "", true, "ERRO!")
let title = await tp.system.prompt("Title", "No Title", true, "ERRO!")
let titlebacklink = await tp.system.suggester(["Yes", "No"], ["Yes", "No"], false, "Create/Exists a backlink to " + title.trim().toLowerCase().replace(/\w\S*/g, (w) => (w.replace(/^\w/, (c) => c.toUpperCase()))) + "?")
let edition = await tp.system.prompt("Edition", "", true, "ERRO!")
let page = await tp.system.prompt("Page", "", true, "ERRO!")
if (titlebacklink === "Yes") {
tp.file.cursor_append(lastname.toUpperCase() + ", " + authorname.trim().replace(/^\w/, (c) => c.toUpperCase()) + ". " + date + ". [[" + title.trim().toLowerCase().replace(/\w\S*/g, (w) => (w.replace(/^\w/, (c) => c.toUpperCase()))) + ".]] " + edition + " ed. - " + "pg. " + page)
} else {
tp.file.cursor_append(lastname.toUpperCase() + ", " + authorname.trim().replace(/^\w/, (c) => c.toUpperCase()) + ". " + date + ". **" + title.trim().toLowerCase().replace(/\w\S*/g, (w) => (w.replace(/^\w/, (c) => c.toUpperCase()))) + ".** " + edition + "ª ed. - " + "pg. " + page)
}
%>

Basically, when you call the Templater, it gonna popup you with a prompt to write (in order):

  • Author Last Name
  • Author Name
  • Title
  • A box which you need to choose between “Yes” or “No” to create or (if it exists yet) mentioned a backlink with the same name of the title (previously prompted)
  • Edition
  • Page interval (eg. pg. 50-52) (you can only put one single page).

and you dont need to formatting or capitalize your bibliography, the regex do it for you! (:

thanks for your attention!

5 Likes