Logseq Template Gallery Logo Logseq Template Gallery

template: book → tags

{ ! var [ authors, name ] = c.page.name.split(' — '); name = «${name}»; authors = authors.split(', ') _}

tags: book,

rating:

link:

category: <span class="bracket">[[</span><span class="link">📖</span><span class="bracket">]]</span>

year:

author: ``{ authors.map(ref).join(', ') }``

alias: ``{ name.indexOf(',') >= 0 ? ref(name) : name }``

id:

🏛 book → tags

Required plugins: Full House Templates How to use? Inside a page named via pattern «Author1, Author2, ... — Book Name» Note: It is not a minus sign: «-». It is EM DASH (U+2014). You can change it in the first template line: …split('<YOUR ANOTHER CHAR>')

Shared by stdword

collapsed: true

template: get book → labirint

`typescript

{ !

const request = new XMLHttpRequest()

const link = empty(c.args.link, dev.links(c.block.content)[0])

if (!link)

return

request.open('GET', link)

request.onload = function() {

if (this.status !== 200)

return

const doc = this.responseText

console.info('Got data from book link')

var m = /

Аннотация к книге "([^"]+)/.exec(doc)

if (!m)

return

const title = m[1]

console.log('RU:', title)

var m = /([^<]*)/.exec(doc)

const titleEng = (m ? m[1] : '').toLowerCase().replace(/(^\w{1})|(\s+\w{1})/g, letter => letter.toUpperCase())

console.log('EN:', titleEng)

var m = doc.matchAll(/data-event-label="author"\s+data-event-content="([^"]*)/g)

if (!m)

return

const authors = []

for (const authorMatch of m) {

const words = authorMatch[1].split(' ').filter((w) => !w.endsWith('.'))

words.unshift(words.pop())

const author = words.join(' ')

authors.push(author)

}

console.log('Authors', authors)

const titles = [title]

if (titleEng)

titles.push(titleEng)

const pageName = authors.join(', ') + ' — ' + title

const properties = {

alias: titles.map((t) => ref(«${t}»)).join(', '),

author: authors.map(ref).join(', '),

year: '',

category: '[[📖]]',

link: ,

rating: '',

tags: 'book,',

}

console.info('Properties:', properties)

const tree = top.logseq.api.getpageblocks_tree(pageName)

let uuid

if (!tree || tree.length === 0) {

// page doesn't exist or is empty

uuid = top.logseq.api.insert_block(pageName, '').uuid

} else {

// there is at least one block in page

uuid = tree[0].uuid

}

for (const [ p, v ] of Object.entries(properties))

top.logseq.api.upsertblockproperty(uuid, p, v)

top.logseq.api.update_block(c.block.uuid, ref(pageName))

}

request.send()

_}

`

🏛 get book → labirint

Required plugin: Full House Templates How to use? 1) {{renderer :template, get book → labirint, :link https://www.labirint.ru/books/529331}} — to fetch data from provided link and render page ref to current block 2) {{renderer :template, get book → labirint, :link https://www.labirint.ru/books/529331, :block <block ref / uuid>}} — to fetch data from provided link and render page ref to specified block 3) {{renderer :template, get book → labirint, :block 649327eb-e5cd-4d3d-a19b-0c57458bcdd1}} — to fetch data from link in specified block and render page ref to that block

Shared by stdword