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eneralizedNewtypeDeriving #-}
{-# 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
-- 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
htmlLink f pwd = "/" ++ makeRelative pwd (addExtension (dropExtension f) ".html")
-- And we add the root folder for publishing
-- FIXME this will not work locally...
import Development.Shake
import Development.Shake.Command
import Development.Shake.FilePath
import Development.Shake.Util
siteExe = "_build/hakyll-site"
-- Notes are managed by pandoc manually to solve org-roam links (and Hakyll does not manage org metadata)
-- args = "-s --css /css/default.css"
-- This only works in Gentoo with packages installed globally
-- TODO: add a switch to use cabal (cabal build and cabal run) outside gentoo
-- Note: nix-build fails with some encoding issues (hGetConts).
-- Nix flakes builds several GHC version...
main :: IO ()
main = shakeArgs shakeOptions{shakeFiles="_build"} $ do
siteExe %> \out -> do
let hs = "src/Main.hs"
need [hs]
cmd_ "ghc --make -o" [out] hs
-- Shake cannot use directories
phony "build" $ do
cmd_ siteExe "build"
need [siteExe]
phony "clean" $ do
putInfo "Cleaning files in _build"
removeFilesAfter "_build" ["//*"]
-- phony "watch" $ do
-- putInfo "Generate site locally"
-- cmd_ "_build/hakyll-site watch"
-- -- 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/*"
phony "archive" $ do
cmd_ "tar cvzf " ["_build/site.tar.gz"] "-C _site ."
need ["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"
putInfo "Cleaning _site "
cmd_ siteExe "clean"
phony "cleanall" $ do
need ["clean"]
want ["archive", "hut"]