From c256f96ab44281d2c78677a442fe08f91f0d5766 Mon Sep 17 00:00:00 2001 From: Tissevert Date: Fri, 4 Aug 2023 10:39:57 +0200 Subject: [PATCH] Stop relying on cabal auto-generated stuff --- .gitignore | 2 ++ README.md | 12 ++++++++++++ guix.scm | 11 ++++++++++- hablo.cabal | 6 +----- src/Arguments.hs | 14 ++++++++------ src/Blog/Wording.hs | 4 ++-- src/Files.hs | 16 +++++++++++++++- src/JS.hs | 4 ++-- src/Main.hs | 6 ++---- 9 files changed, 54 insertions(+), 21 deletions(-) diff --git a/.gitignore b/.gitignore index bf5b663..c71fc18 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,4 @@ /dist-newstyle/* .ghc.environment.* +*.o +*.hi diff --git a/README.md b/README.md index 82dd94b..42e0ddf 100644 --- a/README.md +++ b/README.md @@ -62,6 +62,18 @@ mkdir -p ~/.sjw 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) Wanna give it a try ? Start by [generating your blog](https://git.marvid.fr/Tissevert/hablo/wiki/Generating%20your%20blog) diff --git a/guix.scm b/guix.scm index 1466f8b..8bcdc91 100644 --- a/guix.scm +++ b/guix.scm @@ -29,10 +29,19 @@ ghc-sjw ghc-template 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 (list (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") (synopsis "The Simple Javascript Wrench") (description diff --git a/hablo.cabal b/hablo.cabal index 15ab00c..9af0ddf 100644 --- a/hablo.cabal +++ b/hablo.cabal @@ -23,9 +23,6 @@ maintainer: tissevert+devel@marvid.fr category: Web extra-source-files: CHANGELOG.md build-type: Simple -data-dir: share -data-files: js/*.js - defaultWording.conf library exposed-modules: Arguments @@ -46,7 +43,6 @@ library , JSON , Markdown , Page - , Paths_hablo , Pretty , RSS -- other-extensions: @@ -65,13 +61,13 @@ library , time >= 1.8.0 && < 1.12 , SJW >= 0.1.2 && < 0.2 , unix >= 2.7.2 && < 2.8 + , xdg-basedir >= 0.2.2 && < 0.3 ghc-options: -Wall hs-source-dirs: src default-language: Haskell2010 executable hablo main-is: src/Main.hs - other-modules: Paths_hablo -- other-extensions: build-depends: base , hablo diff --git a/src/Arguments.hs b/src/Arguments.hs index a762abe..cb8b12c 100644 --- a/src/Arguments.hs +++ b/src/Arguments.hs @@ -2,21 +2,23 @@ module Arguments ( Arguments(..) , get + , version ) where #if !MIN_VERSION_base(4,11,0) import Data.Monoid ((<>)) #endif -import Data.Version (showVersion) import Control.Applicative ((<|>), (<**>), optional) import Options.Applicative ( Parser, ReadM, argument, auto, eitherReader, execParser, flag', fullDesc , header, help, helper, info, long, metavar, short, str, switch, value ) import qualified Options.Applicative as Optparse (option) -import qualified Paths_hablo as Hablo (version) import System.FilePath (dropTrailingPathSeparator, isValid) +version :: String +version = "0.3.0.0" + data Arguments = BlogConfig { sourceDir :: FilePath , articlesPath :: Maybe FilePath @@ -81,15 +83,15 @@ blogConfig = BlogConfig <*> 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" -version :: Parser Arguments -version = flag' Version ( +versionP :: Parser Arguments +versionP = flag' Version ( long "version" <> short 'v' <> help "print the version number" ) arguments :: Parser Arguments -arguments = blogConfig <|> version +arguments = blogConfig <|> versionP filePath :: ReadM FilePath filePath = eitherReader $ \path -> @@ -102,4 +104,4 @@ get = do execParser $ info (arguments <**> helper) - (fullDesc <> header ("Hablo v" ++ showVersion Hablo.version)) + (fullDesc <> header ("Hablo v" ++ version)) diff --git a/src/Blog/Wording.hs b/src/Blog/Wording.hs index 3be9b38..c531389 100644 --- a/src/Blog/Wording.hs +++ b/src/Blog/Wording.hs @@ -12,7 +12,7 @@ import Data.Map (Map) import qualified Data.Map as Map (empty, fromList, keys, map, union) import Data.Text (Text) import qualified Data.Text as Text (pack) -import Paths_hablo (getDataFileName) +import Files (getXDGData) import Text.ParserCombinators.Parsec ( Parser , (<|>) @@ -64,6 +64,6 @@ wordingP = Map.map Text.pack . Map.fromList <$> build :: Arguments -> IO Wording build arguments = do - defaultWording <- getDataFileName "defaultWording.conf" + defaultWording <- getXDGData "defaultWording.conf" let wordingFiles = maybe id (:) (wording arguments) $ [defaultWording] Wording <$> foldM addWording Map.empty wordingFiles diff --git a/src/Files.hs b/src/Files.hs index b6bec82..4b68495 100644 --- a/src/Files.hs +++ b/src/Files.hs @@ -3,9 +3,12 @@ module Files ( , absoluteLink , filePath , find + , getXDGData ) 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 (()) data File = File FilePath | Dir FilePath @@ -30,3 +33,14 @@ find path = filePath (Dir path) >>= emptyIfMissing (fmap ((path ) <$>) . listDirectory) where 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 diff --git a/src/JS.hs b/src/JS.hs index 2731c42..08e0456 100644 --- a/src/JS.hs +++ b/src/JS.hs @@ -13,8 +13,8 @@ import Data.ByteString.Lazy ( ) import Data.ByteString.Lazy.Char8 (pack) import Data.Text.Encoding (encodeUtf8) +import Files (getXDGData) import JSON (exportBlog) -import Paths_hablo (getDataDir) import Pretty ((.$)) import SJW (compile, source) import System.Directory (createDirectoryIfMissing) @@ -44,7 +44,7 @@ generateConfig destinationDir = do generateMain :: FilePath -> IO () generateMain destinationDir = do - habloSources <- ( "js") <$> getDataDir + habloSources <- getXDGData "js" compile (source [destinationDir, "unitJS", habloSources]) >>= either abort (output . fst) where diff --git a/src/Main.hs b/src/Main.hs index 4856b1f..7cf576f 100644 --- a/src/Main.hs +++ b/src/Main.hs @@ -1,13 +1,11 @@ module Main where -import Arguments (Arguments(..)) +import Arguments (Arguments(..), version) import qualified Arguments (get) import qualified Blog (build) import Control.Monad.Reader (runReaderT) -import Data.Version (showVersion) import qualified HTML (generate) import qualified JS (generate) -import qualified Paths_hablo as Hablo (version) import qualified RSS (generate) import System.Exit (exitSuccess) @@ -15,7 +13,7 @@ main :: IO () main = do arguments <- Arguments.get case arguments of - Version -> (putStrLn $ showVersion Hablo.version) >> exitSuccess + Version -> (putStrLn version) >> exitSuccess config@(BlogConfig {}) -> Blog.build config >>= runReaderT (do HTML.generate JS.generate