PTH.share [PTH.mkPersist PTH.sqlSettings, PTH.mkMigrate "migrateAll"] [PTH.persistLowerCase|
Node sql=nodes
Id T.Text sql=id
file T.Text
title T.Text
deriving Show
|]
path = "/home/alex/.config/emacs/.local/cache/org-roam.db"
T.replace "\"" ""
-- From "id:XXXX" search in org-roam database for path to file
-- If there is no id, just return the string unchanged
runSqlite path $ do
-- Get id and add (escaped) quote
let s = T.concat ["\"", last (T.splitOn "id:" id), "\""]
test <- get (NodeKey s)
let res = case test of
Just x -> unescape . nodeFile $ x
Nothing -> id
return res
-- Change link to HTML version for publishing it
-- Link is transformed from absolute to relative
makeRelative pwd (addExtension (dropExtension f) ".html")
-- Replace org-mode internal link to link to the full path of the file
do
p <- pathFromID (fst t)
pwd <- getCurrentDirectory
let p' = htmlLink (T.unpack p) pwd
return $ Link attr xs (T.pack p', snd t)
replaceLink x = return x
toJSONFilter replaceLink