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/*
.ghc.environment.*
*.o
*.hi

View File

@ -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)

View File

@ -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

View File

@ -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

View File

@ -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))

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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