munge file path in notes with wallabag URL or actual book path

Ryan Rix 2022-09-07 18:51:01 -07:00
parent f359172059
commit 794a702aaa
1 changed files with 28 additions and 2 deletions

View File

@ -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")
(local wallabag-token (->> ".wallabag"
(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"))]
(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
:ID: koreader-${md5}
:ROAM_REFS: \"${path}\"
#+TITLE: Notes from ${title}
#+AUTHORS: ${authors}
(fn munge-book-path [book-md]
(let [path (. book-md :path)
(_ _ bag-id) (string.find path "%[w%-id_(%d+)%]")]
(if bag-id
(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