Shake.hs, site/hakyll-std: remove mentions/dependencies of hakyll-std

This commit is contained in:
Everett Hildenbrandt 2018-04-27 21:23:05 -06:00 committed by Simon Michael
parent 567a86b810
commit 1a909fe2a3
7 changed files with 1 additions and 341 deletions

View File

@ -19,7 +19,6 @@ compiling is recommended; run the script in interpreted mode to do that.
It requires stack (https://haskell-lang.org/get-started) and It requires stack (https://haskell-lang.org/get-started) and
auto-installs the packages above. Also, some rules require: auto-installs the packages above. Also, some rules require:
- site/hakyll-std/hakyll-std
- runhaskell - runhaskell
- groff - groff
- m4 - m4
@ -304,19 +303,6 @@ main = do
let input = "site" </> dropDirectory2 out let input = "site" </> dropDirectory2 out
copyFile' input out copyFile' input out
-- build standard hakyll script used for site rendering
hakyllstd %> \out -> do
let dir = takeDirectory out
need [out <.> "hs", dir </> "TableOfContents.hs"] -- XXX hard-coded dep
unit $ liftIO $
cmd (Cwd dir) "./hakyll-std.hs"
`catch` (\(e::IOException) -> putStr $ unlines $
["I could not run ./hakyll-std.hs in "++dir++" to install Hakyll."
,"If you see a hakyll-std build error after this, please do it manually:"
,"$ (cd site/hakyll-std; ./hakyll-std.hs)"
,"and try again."
])
phony "website-render" $ do phony "website-render" $ do
need webhtmlpages need webhtmlpages
@ -347,10 +333,8 @@ main = do
phony "Clean" $ do phony "Clean" $ do
need ["clean"] need ["clean"]
putNormal "Cleaning all hakyll generated files" putNormal "Cleaning all site generated files"
removeFilesAfter "site" ["_*"] removeFilesAfter "site" ["_*"]
putNormal "Cleaning executables"
removeFilesAfter "." $ [ hakyllstd ]
putNormal "Cleaning object files" -- also forces rebuild of executables putNormal "Cleaning object files" -- also forces rebuild of executables
removeFilesAfter "tools" ["*.o","*.p_o","*.hi"] removeFilesAfter "tools" ["*.o","*.p_o","*.hi"]
removeFilesAfter "site" ["*.o","*.p_o","*.hi"] removeFilesAfter "site" ["*.o","*.p_o","*.hi"]

View File

@ -1,30 +0,0 @@
Copyright (c) 2015
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above
copyright notice, this list of conditions and the following
disclaimer in the documentation and/or other materials provided
with the distribution.
* Neither the name of Your name here nor the names of other
contributors may be used to endorse or promote products derived
from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

View File

@ -1,2 +0,0 @@
import Distribution.Simple
main = defaultMain

View File

@ -1,91 +0,0 @@
-- from https://github.com/blaenk/blaenk.github.io
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE CPP #-}
module TableOfContents (
tableOfContents,
ignoreTOC,
collectHeaders,
TOCAlignment(TOCOff,TOCLeft,TOCRight)
) where
import Text.Pandoc
import Text.Pandoc.Walk (walk, query)
import Text.Pandoc.Class (runPure)
import Text.Pandoc.Builder (text, toList)
import Text.Pandoc.Options (def)
import Data.Either (fromRight)
import Data.List (groupBy)
import Data.Tree (Forest, Tree(Node))
#if !(MIN_VERSION_base(4,11,0))
import Data.Monoid ((<>), mconcat)
#endif
import Data.Function (on)
import Data.Maybe (fromMaybe)
import Data.Text (unpack)
import Text.Blaze.Html (preEscapedToHtml, (!))
import Text.Blaze.Html.Renderer.String (renderHtml)
import qualified Text.Blaze.Html5 as H
import qualified Text.Blaze.Html5.Attributes as A
data TOCAlignment = TOCOff | TOCLeft | TOCRight
headerLevel :: Block -> Int
headerLevel (Header level _ _) = level
headerLevel _ = error "not a header"
ignoreTOC :: Block -> Block
ignoreTOC (Header level (ident, classes, params) inlines) =
Header level (ident, "notoc" : classes, params) inlines
ignoreTOC x = x
collectHeaders :: Block -> [Block]
collectHeaders header@(Header _ (_, classes, _) _) =
if "notoc" `elem` classes
then []
else [header]
collectHeaders _ = []
groupByHierarchy :: [Block] -> Forest Block
groupByHierarchy = map (\(x:xs) -> Node x (groupByHierarchy xs)) . groupBy ((<) `on` headerLevel)
markupLink :: Attr -> [Inline] -> Inline
markupLink (headerId, _, headerProperties) headerText
= let linkText = fromMaybe headerText (fmap (toList . text) $ lookup "toc" headerProperties)
in Link nullAttr linkText (("#" ++ headerId), headerId)
markupHeader :: Tree Block -> [Block]
markupHeader n@(Node (Header _ hAttr hText) headers)
| headers == [] = [link]
| otherwise = [link, markupHeaders headers]
where link = Plain [markupLink hAttr hText]
markupHeader n = error $ "'markupHeader' should only be passed a 'Node $ Header'\n"
++ " saw: " ++ show n
markupHeaders :: Forest Block -> Block
markupHeaders = OrderedList (1, Decimal, Period) . map markupHeader
createTable :: TOCAlignment -> Forest Block -> Block
createTable _ [] = Null
createTable alignment headers
= let alignAttr = case alignment of
TOCRight -> " class=\"right-toc\""
_ -> ""
navBegin = "<nav id=\"toc\"" ++ alignAttr ++ ">"
navEnd = "</nav>"
tocDoc = Pandoc nullMeta [Para [Str "Contents"], markupHeaders headers]
tocString = unpack . fromRight mempty . runPure . writeHtml5String def $ tocDoc
in RawBlock "html" (navBegin ++ "\n" ++ tocString ++ "\n" ++ navEnd)
generateTOC :: [Block] -> TOCAlignment -> Block -> Block
generateTOC headers alignment x@(BulletList (( (( Plain ((Str "toc"):_)):_)):_))
= createTable alignment . groupByHierarchy $ headers
generateTOC _ _ x = x
tableOfContents :: TOCAlignment -> Pandoc -> Pandoc
tableOfContents TOCOff ast = walk ignoreTOC ast
tableOfContents alignment ast = let headers = query collectHeaders ast
in walk (generateTOC headers alignment) ast

View File

@ -1,45 +0,0 @@
-- This file has been generated from package.yaml by hpack version 0.5.2.
--
-- see: https://github.com/sol/hpack
name: hakyll-std
version: 0.1.0
synopsis: Generic hakyll site builder script (shipped with hledger)
description: A simple hakyll website builder suitable for (eg) software-related websites, intended to be used as-is without recompilation. Features:
.
- renders markdown and common web file types found in standard places
- a site.tmpl template will be used when rendering markdown files
- "- toc" in markdown files is replaced by a table of contents
- fenced code blocks are appropriately syntax-highlighted by highlighting-kate
(you should provide a syntax.css)
.
See the module doc (follow homepage link) for precise details.
category: Web
homepage: https://github.com/simonmichael/hledger/blob/master/doc/site/hakyll-std.hs
bug-reports: https://github.com/simonmichael/hledger/issues
author: Simon Michael <simon@joyful.com>
maintainer: -
license: BSD3
license-file: LICENSE
build-type: Simple
cabal-version: >= 1.10
source-repository head
type: git
location: https://github.com/simonmichael/hledger
executable hakyll-std
main-is: hakyll-std.hs
build-depends:
base >= 4.7 && < 5
, hakyll >=4.7
, pandoc
, pandoc-types
, process
, directory
, data-default
, blaze-html
, containers
other-modules:
TableOfContents
default-language: Haskell2010

View File

@ -1,117 +0,0 @@
#!/usr/bin/env stack
{- stack exec --verbosity info
--package hakyll
ghc
-}
-- pandoc must be >= 2
--
-- must use older stack-ghc8.2.yaml for hakyll/pandoc
-- (hledger and Shake use stack.yaml by default so you may
-- end up downloading and building two large snapshots)
--
-- hakyll-std will go away soon hopefully
{- |
A simple hakyll website builder suitable for software project sites,
intended to be used as-is without recompilation. Functionality:
- copies these static files to _site/ :
*.{html,htm,css,js,gif,jpg,jpeg,png}
{css,img,js,files}/** (** means everything below)
site/{css,img,js,files,etc}/**
doc/**.{html,htm,txt,gif,jpg,jpeg,png}
- renders these markdown files to _site/*.html :
*.{md,mdwn,markdown}
doc/**.{md,mdwn,markdown}
- applies this template file to markdown content:
site.tmpl or site/site.tmpl (the first found)
- a single markdown list item containing the word "toc" is replaced by
a table of contents based on headings
- syntax highlighting of fenced code blocks in markdown is enabled
(if you provide suitable kate styles, eg a syntax.css)
Usage:
$ hakyll-std [--help|clean|build|preview|...] # standard hakyll options
-}
{-# LANGUAGE OverloadedStrings #-}
import Control.Monad
import Data.Default
import Hakyll
import System.Directory
import System.Environment (getArgs)
import System.Exit (exitSuccess)
import System.Process (system)
-- import Text.Highlighting.Kate (pygments, kate, espresso, tango, haddock, monochrome, zenburn)
import Text.Pandoc.Options
import TableOfContents (tableOfContents, TOCAlignment(TOCRight))
import Debug.Trace
strace :: Show a => a -> a
strace a = trace (show a) a
filesToRender =
["*.md"
,"*.mdwn"
,"*.markdown"
,"doc/**.md"
,"doc/**.mdwn"
,"doc/**.markdown"
]
pandocReaderOptions = def
{ readerExtensions = pandocExtensions
}
pandocWriterOptions = def
--- {writerHighlight=True
-- this would change the value of pandoc's $highlight-css$ var
-- for now, let the user provide these styles
-- ,writerHighlightStyle=tango
--- }
pandocTransform = tableOfContents TOCRight
main = do
args <- getArgs
when (any (`elem` args) ["--version"]) $ do
putStrLn "hakyll standard site builder v0.1"
exitSuccess
hakyll $ do
-- there might or might not be a site template in ./ or ./site/
mtmpl <- preprocess $ do
t1 <- doesFileExist "site.tmpl"
t2 <- doesFileExist "site/site.tmpl"
return $ case (t1, t2) of (False, True) -> Just "site/site.tmpl"
(True, _) -> Just "site.tmpl"
(False, False) -> Nothing
case mtmpl of
Just tmpl -> match tmpl $ compile templateCompiler
Nothing -> return ()
match (foldl1 (.||.) filesToRender) $ do
route $ setExtension "html"
compile $
pandocCompilerWithTransformM pandocReaderOptions pandocWriterOptions (return . pandocTransform)
>>= (case mtmpl of
Just tmpl -> loadAndApplyTemplate (fromCapture tmpl "") defaultContext
Nothing -> return)
>>= relativizeUrls
-- this fails the first time after a clean because it runs before README.html generation
-- when ("build" `elem` args) $ preprocess linkReadmeToIndex
-- can't do anything here, hakyll exits
linkReadmeToIndex = void $ system "ln -sf README.html _site/index.html"

View File

@ -1,39 +0,0 @@
# hpack specification for generating the cabal file
# (run "hpack" in this directory)
name : hakyll-std
version : 0.1.0
license : BSD3
synopsis : Generic hakyll site builder script (shipped with hledger)
description : |
A simple hakyll website builder suitable for (eg) software-related websites, intended to be used as-is without recompilation. Features:
- renders markdown and common web file types found in standard places
- a site.tmpl template will be used when rendering markdown files
- "- toc" in markdown files is replaced by a table of contents
- fenced code blocks are appropriately syntax-highlighted by highlighting-kate
(you should provide a syntax.css)
See the module doc (follow homepage link) for precise details.
category : Web
github : simonmichael/hledger
homepage : https://github.com/simonmichael/hledger/blob/master/doc/site/hakyll-std.hs
author : Simon Michael <simon@joyful.com>
maintainer : '-'
dependencies:
- base >=4.7 && <4.12
- hakyll >=4.7
- pandoc #>=1.15
- pandoc-types
- process
- directory
- data-default
- blaze-html
- containers
executables:
hakyll-std:
main: hakyll-std.hs
other-modules: TableOfContents