-
-
Save AdamBuchweitz/58b41d0eb96e0d6b4984e9153a7461fd to your computer and use it in GitHub Desktop.
This is an Obsidian Templater script that generates frontmatter for literature notes from Goodreads link
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
---<%* | |
let url = await tp.system.clipboard() | |
let page = await tp.obsidian.request({url}) | |
let p = new DOMParser() | |
let doc = p.parseFromString(page, "text/html") | |
let $ = s => doc.querySelector(s) | |
let $A = s => doc.querySelectorAll(s) | |
let title = $("h1[id='bookTitle']").innerHTML.trim() | |
let shortTitle = /[A-Za-z0-9_ ]+/.exec(title)[0] | |
%> | |
<% tp.file.rename(shortTitle) %> | |
title: "<% title %>" | |
authors: [<%* let authors = $A("span[itemprop=name]") | |
var keys = Array.from(authors, authors => authors.textContent) | |
tR += keys.join(', ') %>] | |
isbn: <% $("meta[property='books:isbn']").content %> | |
publishedDate: <%* | |
var pubDate = "" | |
let nobr = $("nobr[class='greyText']") | |
if (nobr) | |
{ | |
pubDate = nobr.innerHTML | |
} | |
else | |
{ | |
let details = $A("div[id='details'] div.row") | |
pubDate = details[details.length -1].innerHTML | |
} | |
const regex = /\d{4}/ | |
let match = regex.exec(pubDate) | |
if (match) | |
{ | |
tR += match[0] | |
} | |
%> | |
series: | |
genres: [<%* let genres = $A("a[class='actionLinkLite bookPageGenreLink']") | |
var keys = Array.from(genres, genres => genres.textContent.toLowerCase()) | |
tR += keys.join(', ') %>] | |
cover: "<% $("img[id='coverImage']").src %>" | |
tags: [book] | |
status: Unread | |
--- | |
Up:: [[Books]] | |
Author:: [[<% authors[0].textContent %>]] |
Latest version will also rename the file to the titled of the book, shortened to avoid non-word characters like colons.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Revisions: