munge file path in notes with wallabag URL or actual book path
parent
f359172059
commit
794a702aaa
30
command.fnl
30
command.fnl
|
@ -5,6 +5,8 @@
|
|||
(local stringx (require :pl.stringx))
|
||||
(local tablex (require :pl.tablex))
|
||||
(local text (require :pl.text))
|
||||
(local wallabag (require :wallabag))
|
||||
(local api-prefix wallabag.api-prefix)
|
||||
|
||||
(local sha256 (require :hashings.sha256))
|
||||
|
||||
|
@ -71,6 +73,17 @@
|
|||
(print "parsed" sum "highlights")
|
||||
output))
|
||||
|
||||
(local wallabag-token (->> ".wallabag"
|
||||
(wallabag.load-client-credentials)
|
||||
(wallabag.get-token (.. api-prefix "/oauth/v2/token"))))
|
||||
|
||||
(fn get-single-entry-from-wallabag [id]
|
||||
(let [(headers body) (wallabag.api-req wallabag-token "GET" (.. api-prefix "/api/entries/" id ".json"))]
|
||||
body))
|
||||
|
||||
(fn get-wallabag-url [id]
|
||||
(. (get-single-entry-from-wallabag id) :url))
|
||||
|
||||
(local template (. text :Template))
|
||||
|
||||
(local highlight-tmpl (template
|
||||
|
@ -119,15 +132,28 @@
|
|||
(local book-tmpl (template
|
||||
":PROPERTIES:
|
||||
:ID: koreader-${md5}
|
||||
:ROAM_REFS: \"${path}\"
|
||||
:END:
|
||||
#+TITLE: Notes from ${title}
|
||||
#+AUTHORS: ${authors}
|
||||
[[file:${path}][${path}]]
|
||||
[[${path}][${path}]]
|
||||
"))
|
||||
|
||||
(fn munge-book-path [book-md]
|
||||
(let [path (. book-md :path)
|
||||
(_ _ bag-id) (string.find path "%[w%-id_(%d+)%]")]
|
||||
(if bag-id
|
||||
(do
|
||||
(print "bag id" bag-id)
|
||||
(set book-md.path (get-wallabag-url bag-id)))
|
||||
;; sickos.jpg
|
||||
(set book-md.path (.. "file:"
|
||||
(string.gsub path "sdr/metadata.([^.]+).lua" "%1"))))))
|
||||
|
||||
(fn render-one-book [book]
|
||||
(let [authors (?. book "authors")
|
||||
title (?. book "title")]
|
||||
(munge-book-path book)
|
||||
(.. (: book-tmpl :substitute book)
|
||||
(stringx.join "\n"
|
||||
(icollect [_i1 chapter-hls (pairs (?. book "highlights"))]
|
||||
|
@ -176,7 +202,7 @@
|
|||
(lambda [book book-path]
|
||||
(write-one-book-from-md book book-path out-path))))
|
||||
|
||||
(let [default-book-dir "~/mobile-library/books"
|
||||
(let [default-book-dir "~/mobile-library/"
|
||||
default-note-dir "~/org/highlights/"
|
||||
args (lapp (stringx.join
|
||||
"\n"
|
||||
|
|
Loading…
Reference in New Issue