Switch to cabal builds.

No more stackage.
This commit is contained in:
Justin Hsu 2021-01-03 18:31:52 +00:00
parent 2602bdd594
commit 525aa09f61
8 changed files with 157 additions and 63 deletions

View File

@ -1,4 +1,4 @@
Copyright Author name here (c) 2018
Copyright (c) 2021, Justin Hsu
All rights reserved.
@ -13,7 +13,7 @@ modification, are permitted provided that the following conditions are met:
disclaimer in the documentation and/or other materials provided
with the distribution.
* Neither the name of Author name here nor the names of other
* Neither the name of Justin Hsu nor the names of other
contributors may be used to endorse or promote products derived
from this software without specific prior written permission.

View File

@ -1,7 +1,7 @@
TOP=stack exec website-exe
TOP=cabal v2-run justin-site
all:
stack build
cabal v2-build
check:
$(TOP) check
@ -17,4 +17,4 @@ install:
gem update --system && gem install compass
clean:
stack clean
cabal v2-clean

View File

@ -1,4 +1,5 @@
{-# OPTIONS_GHC -fno-warn-unused-do-bind #-}
{-# LANGUAGE OverloadedStrings #-}
-----------------------------------------------------------------------------
-- |
-- Module : Text.CSL.Input.Bibtex
@ -32,6 +33,7 @@ import System.Environment (getEnvironment)
import Text.CSL.Style (Formatted(..), Locale(..), CslTerm(..), Agent(..))
import qualified Text.Pandoc.Walk as Walk
import qualified Text.Pandoc.UTF8 as UTF8
import qualified Data.Text as T
data Item = Item{ identifier :: String
, entryType :: String
@ -101,7 +103,7 @@ fieldName :: BibParser String
fieldName = (map toLower) <$> many1 (letter <|> digit <|> oneOf "-_")
isBibtexKeyChar :: Char -> Bool
isBibtexKeyChar c = isAlphaNum c || c `elem` ".:;?!`'()/*@_+=-[]*"
isBibtexKeyChar c = isAlphaNum c || c `elem` (".:;?!`'()/*@_+=-[]*" :: String)
bibItem :: BibParser Item
bibItem = do
@ -266,7 +268,7 @@ langToLocale (Lang x y) = x ++ ('-':y)
resolveKey :: Lang -> Formatted -> Formatted
resolveKey lang (Formatted ils) = Formatted (Walk.walk go ils)
where go (Str s) = Str $ resolveKey' lang s
where go (Str s) = Str $ T.pack $ resolveKey' lang $ T.unpack s
go x = x
resolveKey' :: Lang -> String -> String

108
app/Main.hs Normal file
View File

@ -0,0 +1,108 @@
module Main where
--------------------------------------------------------------------------------
{-# LANGUAGE OverloadedStrings #-}
import Data.Monoid
import Control.Monad (forM_)
import Hakyll
import HakyllBibTex
import System.Process
import Text.Pandoc.Options
config :: Configuration
config = defaultConfiguration
{ deployCommand = "echo `pwd`; ./scripts/deploy.sh" }
--------------------------------------------------------------------------------
bibHeaders :: [(String, [String])]
bibHeaders = [ ("drafts" , [ "-c", "$type='UNPUBLISHED'" ] ) ,
("thesis" , [ "-c", "$type='PHDTHESIS'" ] ) ,
("pubs" , [ "-c", "$type='INPROCEEDINGS' or $type='ARTICLE'" ] ) ]
bibSources :: [String]
bibSources = [ "bibs/header.bib"
, "bibs/myrefs.bib"
]
contentSections :: [String]
contentSections = [ "contacts", "about", "news", "biblio" ]
--------------------------------------------------------------------------------
compass :: Compiler (Item String)
compass =
getResourceString >>=
withItemBody (unixFilter "sass" ["-s", "--scss", "--compass"])
b2bflags :: [String]
b2bflags = [ "--expand"
, "-c"
, "jh:'yes'"
, "-s"
, "$date"
, "-r"
]
bib2bib :: [String]
-> Compiler (Item String)
bib2bib flags = (unsafeCompiler $
readProcess "bib2bib" (bibSources ++ b2bflags ++ flags) "")
>>= makeItem
bib2bibParse :: Item String
-> Compiler [Item BibEntry]
bib2bibParse file =
let (BibFile bf) = parseBibFile (itemBody file) in
sequence $ fmap makeItem bf
--------------------------------------------------------------------------------
main :: IO ()
main = hakyllWith config $ do
match (fromGlob "files/**") $ do
route idRoute
compile copyFileCompiler
match (fromGlob "images/**") $ do
route idRoute
compile copyFileCompiler
match (fromGlob "css/*.scss") $ do
route $ setExtension "css"
compile $ compass
match (fromGlob "content/*.md") $ do
route $ setExtension "html"
compile $ do
let secDiv = defaultHakyllWriterOptions { writerSectionDivs = True }
pandocCompilerWith defaultHakyllReaderOptions secDiv
>>= relativizeUrls
match (fromGlob "index.html") $ do
route idRoute
compile $ do
let loadSec sec = field sec
(\_ -> loadBody (fromFilePath $ "content/" ++ sec ++ ".md"))
makeBibCtx (nick, _) =
field nick (\_ -> loadBody $ fromFilePath ("bibs/" ++ nick ++ ".html"))
biblioContext = mconcat $ map makeBibCtx bibHeaders
indexContext = mconcat $ fmap loadSec contentSections
footerContext = field "footer" (\_ -> loadBody $ fromFilePath "content/footer.md")
getResourceBody
>>= applyAsTemplate (indexContext <> biblioContext <> footerContext <> defaultContext)
>>= relativizeUrls
forM_ bibHeaders $ \(nick, flags) ->
create [fromCapture (fromGlob "bibs/*.html") nick] $ do
route idRoute
compile $
let biblioCtx = mconcat
[ field "bibitems" $ return . itemBody ] in do
bibTpl <- loadBody $ fromFilePath "templates/bibitem.html"
(bib2bib flags)
>>= bib2bibParse
>>= applyTemplateList bibTpl bibEntryContext
>>= makeItem
>>= applyAsTemplate biblioCtx
>>= relativizeUrls
match (fromGlob "templates/*") $ compile templateCompiler

40
justin-site.cabal Normal file
View File

@ -0,0 +1,40 @@
cabal-version: 2.2
-- Initial package description 'justin-site.cabal' generated by 'cabal
-- init'. For further documentation, see
-- http://haskell.org/cabal/users-guide/
name: justin-site
version: 0.1.0.0
-- synopsis:
-- description:
-- bug-reports:
license: BSD-3-Clause
license-file: LICENSE
author: Justin Hsu
maintainer: email@justinh.su
-- copyright:
-- category:
extra-source-files: CHANGELOG.md
executable justin-site
main-is: Main.hs
other-modules:
Bibtex,
HakyllBibTex
-- other-extensions:
build-depends:
base ^>=4.13.0.0,
hakyll ^>=4.13,
pandoc,
process,
binary,
containers,
mtl,
pandoc-citeproc,
pandoc-types,
parsec,
split,
text
hs-source-dirs: app
default-language: Haskell2010

View File

@ -1,54 +0,0 @@
name: website
version: 0.1.0.0
github: "githubuser/website"
license: BSD3
author: "Author name here"
maintainer: "example@example.com"
copyright: "2018 Author name here"
# Metadata used when publishing your package
# synopsis: Short description of your package
# category: Web
# To avoid duplicated efforts in documentation and dealing with the
# complications of embedding Haddock markup inside cabal files, it is
# common to point users to the README.md file.
dependencies:
- base >= 4.7 && < 5
- binary
- containers
- hakyll
- mtl
- pandoc
- pandoc-citeproc
- pandoc-types
- parsec
- process
- split
- text
library:
source-dirs: src
executables:
website-exe:
main: site.hs
source-dirs: app
ghc-options:
- -threaded
- -rtsopts
- -with-rtsopts=-N
dependencies:
- website
tests:
website-test:
main: Spec.hs
source-dirs: test
ghc-options:
- -threaded
- -rtsopts
- -with-rtsopts=-N
dependencies:
- website

View File

@ -1,2 +0,0 @@
main :: IO ()
main = putStrLn "Test suite not yet implemented"