TODO: even with setting relative paths, it does not work well with Shake
GPHHMPIFY3HIZKBOI2BTPTULLMRRICZPL2KK6EW7E3NKMAUYUCPAC
2NNA6FS2KSFIK3OXYUJ3Q3ZEVI7CXLWVPB3NKU5KUAHQXQIX3XNQC
CKXX2K6A6RCMJENA3XKDBHO3YULTUDORZ2M5ZXE4UQKIIXHBVIQQC
RHWQQAAHNHFO3FLCGVB3SIDKNOUFJGZTDNN57IQVBMXXCWX74MKAC
JGMCSDW663DQSK7XSWDBPVYQE57ZBP7ZVZLSEXUJOQVE7KY6BB4QC
2ZULESGU4H6GRQUHINYMYXW2FR33QNNA5OWBCCRAD26CX7WHT57QC
J3CFALT6SR7GY5QWRZEZI2YL5X42YULB2RYVWPBXHRI3K7A5KTSAC
4RX6SVVGVS3LKLZGNTWY5S6DOJGS5AJWZNDM3D3SEWXXLZG6PTAQC
ZW5JL2RSM3UIBU4DDWMALMRDXGDWGOBW4YFUISRJY3HDEXVXYB7AC
- [[./medecine/20230528225221-classification_bacteries.html][Classification bacteries]]
- [[./medecine/20230528225531-bacteries.html][Bacteries]]
- [[./medecine/20230528235213-maladies_infectieuses.html][Maladies infectieuses]]
- [[./medecine/20230528235406-antibiotiques.html][Antibiotiques]]
- [[./medecine/20230528235124-culture.html][Culture]]
- [[id:6b2bf94d-9539-4a64-b15b-9511aa90772c][Classification bactéries]]
- [[id:9160ba80-117b-4434-acc9-13676a534da0][Bactéries]]
- [[id:00e9454a-9a71-4fbd-bfde-0fdf323bce15][Maladies infectieuses]]
- [[id:46dca88b-671f-4f23-a340-5dc564a48659][Antibiotiques]]
- [[id:a8ad4c3b-9f08-4878-8d9d-febddae20069][Culture]]
{-# LANGUAGE TemplateHaskell #-}
{-# LANGUAGE QuasiQuotes #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
{-# LANGUAGE RecordWildCards #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE DerivingStrategies #-}
{-# LANGUAGE StandaloneDeriving #-}
{-# LANGUAGE UndecidableInstances #-}
{-# LANGUAGE DataKinds #-}
import qualified Database.Persist.TH as PTH
import Database.Persist (Entity(..))
import Database.Persist.Sql (toSqlKey)
import qualified Data.Text as T
import Database.Persist.Sqlite
import Control.Monad.IO.Class
import Control.Monad.Logger
import Text.Pandoc.JSON
import System.FilePath (addExtension, dropExtension, makeRelative)
import System.Directory (getCurrentDirectory)
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/.emacs.d/.local/cache/org-roam.db"
unescape :: T.Text -> T.Text
unescape = T.replace "\"" ""
-- From "id:XXXX" search in org-roam database for path to file
-- If there is no id, just return the string unchanged
pathFromID :: T.Text -> IO (T.Text)
pathFromID id = 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
htmlLink :: FilePath -> FilePath -> FilePath
htmlLink f pwd = makeRelative pwd (addExtension (dropExtension f) ".html")
-- Replace org-mode internal link to link to the full path of the file
replaceLink :: Inline -> IO (Inline)
replaceLink (Link attr xs t) = 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
main :: IO ()
main = toJSONFilter replaceLink
siteExe %> \out -> do
let src = "src/Main.hs"
need [src, "notes/20230511180745-microbiologie.org"]
cmd_ "ghc --make -o" [out] [src]
"_build/notes/index.html" %> \out -> do
let src = "notes/index.org"
org <- getDirectoryFiles "" ["notes/medecine/*.org"]
let html = ["_build" </> n -<.> "html" | n <- org]
need html
cmd "pandoc" src "--filter ./filterOrgRoam -o" [out]
-- Shake cannot use directories
phony "build" $ do
need [siteExe]
cmd_ siteExe "build"
"_build/notes/medecine/*.html" %> \out -> do
let org = dropDirectory1 $ out -<.> "org"
putInfo org
putInfo out
cmd "pandoc" [org] "--filter ./filterOrgRoam -o" [out]
-- want ["build", "hut"]
-- siteExe %> \out -> do
-- let src = "src/Main.hs"
-- need [src, "notes/20230511180745-microbiologie.org"]
-- cmd_ "ghc --make -o" [out] [src]
-- -- Shake cannot use directories
-- phony "build" $ do
-- need [siteExe]
-- cmd_ siteExe "build"
phony "hut" $ do
putInfo "Upload to blog hosted by sourcehut"
need ["archive"]
cmd_ "hut pages publish _build/site.tar.gz -d scut.srht.site"
-- phony "hut" $ do
-- putInfo "Upload to blog hosted by sourcehut"
-- need ["archive"]
-- cmd_ "hut pages publish _build/site.tar.gz -d scut.srht.site"
-- z option is important to avoid re-uploading everything
phony "free" $ do
putInfo "Upload to blog hosted by Free"
cmd_ "ncftpput -z -f login.cfg -R . _site/*"
cmd_ "ncftpput -z -f login.cfg -R . files/*"
-- -- z option is important to avoid re-uploading everything
-- phony "free" $ do
-- putInfo "Upload to blog hosted by Free"
-- cmd_ "ncftpput -z -f login.cfg -R . _site/*"
-- cmd_ "ncftpput -z -f login.cfg -R . files/*"