Stop relying on cabal auto-generated stuff

This commit is contained in:
Tissevert 2023-08-04 10:39:57 +02:00
parent e2d79dd77e
commit c256f96ab4
9 changed files with 54 additions and 21 deletions

2
.gitignore vendored
View File

@ -1,2 +1,4 @@
/dist-newstyle/* /dist-newstyle/*
.ghc.environment.* .ghc.environment.*
*.o
*.hi

View File

@ -62,6 +62,18 @@ mkdir -p ~/.sjw
cp -r src/ ~/.sjw/unitJS cp -r src/ ~/.sjw/unitJS
``` ```
Then, the static data used by hablo need to be available in a XDG path. Depending on whether you are installing for your user or system-wide, you may want to perform something either
```bash
cp -R share ~/.local/share/hablo
```
or
```bash
sudo cp -R share /usr/local/share/hablo
```
### Using hablo (tutorials) ### Using hablo (tutorials)
Wanna give it a try ? Start by [generating your blog](https://git.marvid.fr/Tissevert/hablo/wiki/Generating%20your%20blog) Wanna give it a try ? Start by [generating your blog](https://git.marvid.fr/Tissevert/hablo/wiki/Generating%20your%20blog)

View File

@ -29,10 +29,19 @@
ghc-sjw ghc-sjw
ghc-template ghc-template
ghc-xdg-basedir)) ghc-xdg-basedir))
(arguments
`(#:phases
(modify-phases %standard-phases
(insert-after 'install 'copy-static-resources
(lambda* #:key outputs #:allow-other-keys
(let ((out (assoc-ref outputs "out")))
(copy-recursively "share" (string-append out "/share/hablo"))))))))
(native-search-paths (native-search-paths
(list (list
(search-path-specification (variable "SJW_PATH") (search-path-specification (variable "SJW_PATH")
(files '("lib/SJW"))))) (files '("lib/SJW")))
(search-path-specification (variable "XDG_DATA_DIRS")
(files '("share")))))
(home-page "https://git.marvid.fr/Tissevert/SJW") (home-page "https://git.marvid.fr/Tissevert/SJW")
(synopsis "The Simple Javascript Wrench") (synopsis "The Simple Javascript Wrench")
(description (description

View File

@ -23,9 +23,6 @@ maintainer: tissevert+devel@marvid.fr
category: Web category: Web
extra-source-files: CHANGELOG.md extra-source-files: CHANGELOG.md
build-type: Simple build-type: Simple
data-dir: share
data-files: js/*.js
defaultWording.conf
library library
exposed-modules: Arguments exposed-modules: Arguments
@ -46,7 +43,6 @@ library
, JSON , JSON
, Markdown , Markdown
, Page , Page
, Paths_hablo
, Pretty , Pretty
, RSS , RSS
-- other-extensions: -- other-extensions:
@ -65,13 +61,13 @@ library
, time >= 1.8.0 && < 1.12 , time >= 1.8.0 && < 1.12
, SJW >= 0.1.2 && < 0.2 , SJW >= 0.1.2 && < 0.2
, unix >= 2.7.2 && < 2.8 , unix >= 2.7.2 && < 2.8
, xdg-basedir >= 0.2.2 && < 0.3
ghc-options: -Wall ghc-options: -Wall
hs-source-dirs: src hs-source-dirs: src
default-language: Haskell2010 default-language: Haskell2010
executable hablo executable hablo
main-is: src/Main.hs main-is: src/Main.hs
other-modules: Paths_hablo
-- other-extensions: -- other-extensions:
build-depends: base build-depends: base
, hablo , hablo

View File

@ -2,21 +2,23 @@
module Arguments ( module Arguments (
Arguments(..) Arguments(..)
, get , get
, version
) where ) where
#if !MIN_VERSION_base(4,11,0) #if !MIN_VERSION_base(4,11,0)
import Data.Monoid ((<>)) import Data.Monoid ((<>))
#endif #endif
import Data.Version (showVersion)
import Control.Applicative ((<|>), (<**>), optional) import Control.Applicative ((<|>), (<**>), optional)
import Options.Applicative ( import Options.Applicative (
Parser, ReadM, argument, auto, eitherReader, execParser, flag', fullDesc Parser, ReadM, argument, auto, eitherReader, execParser, flag', fullDesc
, header, help, helper, info, long, metavar, short, str, switch, value , header, help, helper, info, long, metavar, short, str, switch, value
) )
import qualified Options.Applicative as Optparse (option) import qualified Options.Applicative as Optparse (option)
import qualified Paths_hablo as Hablo (version)
import System.FilePath (dropTrailingPathSeparator, isValid) import System.FilePath (dropTrailingPathSeparator, isValid)
version :: String
version = "0.3.0.0"
data Arguments = BlogConfig { data Arguments = BlogConfig {
sourceDir :: FilePath sourceDir :: FilePath
, articlesPath :: Maybe FilePath , articlesPath :: Maybe FilePath
@ -81,15 +83,15 @@ blogConfig = BlogConfig
<*> option filePath 'u' "site-url" "URL" "URL where the blog is published" <*> option filePath 'u' "site-url" "URL" "URL where the blog is published"
<*> option filePath 'w' "wording" "FILE" "path to the file containing the wording to use" <*> option filePath 'w' "wording" "FILE" "path to the file containing the wording to use"
version :: Parser Arguments versionP :: Parser Arguments
version = flag' Version ( versionP = flag' Version (
long "version" long "version"
<> short 'v' <> short 'v'
<> help "print the version number" <> help "print the version number"
) )
arguments :: Parser Arguments arguments :: Parser Arguments
arguments = blogConfig <|> version arguments = blogConfig <|> versionP
filePath :: ReadM FilePath filePath :: ReadM FilePath
filePath = eitherReader $ \path -> filePath = eitherReader $ \path ->
@ -102,4 +104,4 @@ get = do
execParser $ execParser $
info info
(arguments <**> helper) (arguments <**> helper)
(fullDesc <> header ("Hablo v" ++ showVersion Hablo.version)) (fullDesc <> header ("Hablo v" ++ version))

View File

@ -12,7 +12,7 @@ import Data.Map (Map)
import qualified Data.Map as Map (empty, fromList, keys, map, union) import qualified Data.Map as Map (empty, fromList, keys, map, union)
import Data.Text (Text) import Data.Text (Text)
import qualified Data.Text as Text (pack) import qualified Data.Text as Text (pack)
import Paths_hablo (getDataFileName) import Files (getXDGData)
import Text.ParserCombinators.Parsec ( import Text.ParserCombinators.Parsec (
Parser Parser
, (<|>) , (<|>)
@ -64,6 +64,6 @@ wordingP = Map.map Text.pack . Map.fromList <$>
build :: Arguments -> IO Wording build :: Arguments -> IO Wording
build arguments = do build arguments = do
defaultWording <- getDataFileName "defaultWording.conf" defaultWording <- getXDGData "defaultWording.conf"
let wordingFiles = maybe id (:) (wording arguments) $ [defaultWording] let wordingFiles = maybe id (:) (wording arguments) $ [defaultWording]
Wording <$> foldM addWording Map.empty wordingFiles Wording <$> foldM addWording Map.empty wordingFiles

View File

@ -3,9 +3,12 @@ module Files (
, absoluteLink , absoluteLink
, filePath , filePath
, find , find
, getXDGData
) where ) where
import System.Directory (doesDirectoryExist, doesFileExist, listDirectory) import System.Directory (doesDirectoryExist, doesFileExist, doesPathExist, listDirectory)
import System.Environment.XDG.BaseDir (getAllDataDirs)
import System.Exit (die)
import System.FilePath ((</>)) import System.FilePath ((</>))
data File = File FilePath | Dir FilePath data File = File FilePath | Dir FilePath
@ -30,3 +33,14 @@ find path =
filePath (Dir path) >>= emptyIfMissing (fmap ((path </>) <$>) . listDirectory) filePath (Dir path) >>= emptyIfMissing (fmap ((path </>) <$>) . listDirectory)
where where
emptyIfMissing = either (\_ -> return []) emptyIfMissing = either (\_ -> return [])
getXDGData :: FilePath -> IO FilePath
getXDGData resource = getAllDataDirs relativePath >>= findFirst
where
relativePath = "hablo" </> resource
findFirst [] = die ("Install is broken: "
<> relativePath
<> " directory wasn't found in any of $XDG_DATA_DIRS")
findFirst (path:paths) = do
fileExists <- doesPathExist path
if fileExists then pure path else findFirst paths

View File

@ -13,8 +13,8 @@ import Data.ByteString.Lazy (
) )
import Data.ByteString.Lazy.Char8 (pack) import Data.ByteString.Lazy.Char8 (pack)
import Data.Text.Encoding (encodeUtf8) import Data.Text.Encoding (encodeUtf8)
import Files (getXDGData)
import JSON (exportBlog) import JSON (exportBlog)
import Paths_hablo (getDataDir)
import Pretty ((.$)) import Pretty ((.$))
import SJW (compile, source) import SJW (compile, source)
import System.Directory (createDirectoryIfMissing) import System.Directory (createDirectoryIfMissing)
@ -44,7 +44,7 @@ generateConfig destinationDir = do
generateMain :: FilePath -> IO () generateMain :: FilePath -> IO ()
generateMain destinationDir = do generateMain destinationDir = do
habloSources <- (</> "js") <$> getDataDir habloSources <- getXDGData "js"
compile (source [destinationDir, "unitJS", habloSources]) compile (source [destinationDir, "unitJS", habloSources])
>>= either abort (output . fst) >>= either abort (output . fst)
where where

View File

@ -1,13 +1,11 @@
module Main where module Main where
import Arguments (Arguments(..)) import Arguments (Arguments(..), version)
import qualified Arguments (get) import qualified Arguments (get)
import qualified Blog (build) import qualified Blog (build)
import Control.Monad.Reader (runReaderT) import Control.Monad.Reader (runReaderT)
import Data.Version (showVersion)
import qualified HTML (generate) import qualified HTML (generate)
import qualified JS (generate) import qualified JS (generate)
import qualified Paths_hablo as Hablo (version)
import qualified RSS (generate) import qualified RSS (generate)
import System.Exit (exitSuccess) import System.Exit (exitSuccess)
@ -15,7 +13,7 @@ main :: IO ()
main = do main = do
arguments <- Arguments.get arguments <- Arguments.get
case arguments of case arguments of
Version -> (putStrLn $ showVersion Hablo.version) >> exitSuccess Version -> (putStrLn version) >> exitSuccess
config@(BlogConfig {}) -> Blog.build config >>= runReaderT (do config@(BlogConfig {}) -> Blog.build config >>= runReaderT (do
HTML.generate HTML.generate
JS.generate JS.generate