From a2620eec367711480ee2e34ada39b76dc52dbb17 Mon Sep 17 00:00:00 2001 From: Jasper Van der Jeugt Date: Fri, 14 Dec 2012 10:42:30 +0100 Subject: Work on installation tutorial --- web/hakyll.hs | 71 ---------------------------------- web/index.markdown | 3 ++ web/site.hs | 71 ++++++++++++++++++++++++++++++++++ web/templates/tutorials.html | 6 +-- web/tutorials/01-installation.markdown | 62 ++++++++++++++--------------- 5 files changed, 105 insertions(+), 108 deletions(-) delete mode 100644 web/hakyll.hs create mode 100644 web/site.hs (limited to 'web') diff --git a/web/hakyll.hs b/web/hakyll.hs deleted file mode 100644 index 93a7216..0000000 --- a/web/hakyll.hs +++ /dev/null @@ -1,71 +0,0 @@ --------------------------------------------------------------------------------- -{-# LANGUAGE OverloadedStrings #-} -import Control.Monad (forM_) -import Data.Monoid (mappend) -import Hakyll -import Text.Pandoc - - --------------------------------------------------------------------------------- -main :: IO () -main = hakyllWith config $ do - match "css/*" $ do - route idRoute - compile compressCssCompiler - - -- Static directories - forM_ ["images/*", "examples/*", "reference/**"] $ \f -> match f $ do - route idRoute - compile copyFileCompiler - - -- Pages - match "*.markdown" $ do - route $ setExtension "html" - compile $ pageCompiler - >>= requireApplyTemplate "templates/default.html" defaultContext - >>= relativizeUrls - - -- Tutorials - match "tutorials/*" $ do - route $ setExtension "html" - compile $ pageCompilerWith defaultHakyllParserState withToc - >>= requireApplyTemplate "templates/tutorial.html" defaultContext - >>= requireApplyTemplate "templates/default.html" defaultContext - >>= relativizeUrls - - -- Tutorial list - match "tutorials.html" $ do - route idRoute - compile $ do - tutorials <- requireAll "tutorials/*" - itemTpl <- requireBody "templates/tutorial-item.html" - list <- applyTemplateList itemTpl defaultContext $ - chronological tutorials - - let tutorialsCtx = - constField "title" "Tutorials" `mappend` - constField "tutorials" list `mappend` - defaultContext - - makeItem "" - >>= requireApplyTemplate "templates/tutorials.html" tutorialsCtx - >>= requireApplyTemplate "templates/default.html" tutorialsCtx - >>= relativizeUrls - - -- Templates - match "templates/*" $ compile templateCompiler - where - withToc = defaultHakyllWriterOptions - { writerTableOfContents = True - , writerTemplate = "$toc$\n$body$" - , writerStandalone = True - } - - --------------------------------------------------------------------------------- -config :: Configuration -config = defaultConfiguration - { verbosity = Debug - , deployCommand = "rsync --checksum -ave 'ssh -p 2222' \ - \_site/* jaspervdj@jaspervdj.be:jaspervdj.be/hakyll" - } diff --git a/web/index.markdown b/web/index.markdown index 68681b7..06c2780 100644 --- a/web/index.markdown +++ b/web/index.markdown @@ -4,6 +4,9 @@ title: Home # Overview +Static sites are fast, secure, easy to deploy, and manageable using version +control. + Hakyll is a [Haskell](http://haskell.org) library for generating static sites, mostly aimed at small-to-medium sites and personal blogs. It is written in a very configurable way and uses an [xmonad](http://xmonad.org)-like DSL for diff --git a/web/site.hs b/web/site.hs new file mode 100644 index 0000000..f106ca7 --- /dev/null +++ b/web/site.hs @@ -0,0 +1,71 @@ +-------------------------------------------------------------------------------- +{-# LANGUAGE OverloadedStrings #-} +import Control.Monad (forM_) +import Data.Monoid (mappend) +import Hakyll +import Text.Pandoc + + +-------------------------------------------------------------------------------- +main :: IO () +main = hakyllWith config $ do + match "css/*" $ do + route idRoute + compile compressCssCompiler + + -- Static directories + forM_ ["images/*", "examples/*", "reference/**"] $ \f -> match f $ do + route idRoute + compile copyFileCompiler + + -- Pages + match "*.markdown" $ do + route $ setExtension "html" + compile $ pageCompiler + >>= loadAndApplyTemplate "templates/default.html" defaultContext + >>= relativizeUrls + + -- Tutorials + match "tutorials/*" $ do + route $ setExtension "html" + compile $ pageCompilerWith defaultHakyllParserState withToc + >>= loadAndApplyTemplate "templates/tutorial.html" defaultContext + >>= loadAndApplyTemplate "templates/default.html" defaultContext + >>= relativizeUrls + + -- Tutorial list + match "tutorials.html" $ do + route idRoute + compile $ do + tutorials <- loadAll "tutorials/*" + itemTpl <- loadBody "templates/tutorial-item.html" + list <- applyTemplateList itemTpl defaultContext $ + chronological tutorials + + let tutorialsCtx = + constField "title" "Tutorials" `mappend` + constField "tutorials" list `mappend` + defaultContext + + makeItem "" + >>= loadAndApplyTemplate "templates/tutorials.html" tutorialsCtx + >>= loadAndApplyTemplate "templates/default.html" tutorialsCtx + >>= relativizeUrls + + -- Templates + match "templates/*" $ compile templateCompiler + where + withToc = defaultHakyllWriterOptions + { writerTableOfContents = True + , writerTemplate = "$toc$\n$body$" + , writerStandalone = True + } + + +-------------------------------------------------------------------------------- +config :: Configuration +config = defaultConfiguration + { verbosity = Debug + , deployCommand = "rsync --checksum -ave 'ssh -p 2222' \ + \_site/* jaspervdj@jaspervdj.be:jaspervdj.be/hakyll" + } diff --git a/web/templates/tutorials.html b/web/templates/tutorials.html index 36d1f03..dd3132b 100644 --- a/web/templates/tutorials.html +++ b/web/templates/tutorials.html @@ -8,7 +8,7 @@

All these tutorials assume you are using the latest stable version of Hakyll. If this is not the case, you might want to update using: -

ghc-pkg unregister hakyll
-cabal update
-cabal install hakyll
+
$ ghc-pkg unregister hakyll
+$ cabal update
+$ cabal install hakyll

diff --git a/web/tutorials/01-installation.markdown b/web/tutorials/01-installation.markdown index 131971f..a0a0f3a 100644 --- a/web/tutorials/01-installation.markdown +++ b/web/tutorials/01-installation.markdown @@ -3,46 +3,13 @@ title: Installation author: Jasper Van der Jeugt --- -Why static websites? --------------------- - -Modern web frameworks make it easy to create huge dynamic websites. Why would -anyone still care about a static website? - -- Static websites are fast, because it's simply files served directly from the - hard disk. -- Static websites are secure. Nobody has ever found an SQL injection in static - pages. -- Static websites are easy to deploy. Just copy them to your webhost using - (S)FTP/rsync/scp and you are done. They work on all webhosts: no CGI or extra - modules needed for the web server. - -Why Hakyll? ------------ - -Hakyll is a [Haskell] library meant for creating small-to-medium sized static -websites. It is a powerful publishing tool, precisely because of the power of -Haskell. By using the awesome [pandoc] library, it is able to create your -website from a large variety of input formats. - -[Haskell]: http://haskell.org/ -[pandoc]: http://johnmacfarlane.net/pandoc/ - -Features include: - -- easy templating system; -- a simple HTTP server for previewing and compiling your website on the go; -- powerful syntax highlighting; -- modules for common items such as tags and feeds; -- easily extensible. - Installation ------------ Installation is provided using [cabal], and some packages are available for different distributions. - cabal install hakyll + $ cabal install hakyll [cabal]: http://www.haskell.org/cabal/ @@ -50,3 +17,30 @@ Linux distro packages: - [Archlinux (AUR)](https://aur.archlinux.org/packages/haskell-hakyll/) - [Debian unstable](http://packages.debian.org/source/sid/haskell-hakyll) + +Building the example site +------------------------- + +Apart from the main Hakyll library, the cabal package also provided you with an +executable `hakyll-init` to create an example site. This is an easy way to get +started: + + $ hakyll-init my-site + +If `hakyll-init` is not found, you should make sure `$HOME/.cabal/bin` is in +your `$PATH`. + +The file `site.hs` holds the configuration of your site, as an executable +haskell program. We can compile and run it like this: + + $ cd my-site + $ ghc --make site.hs + $ ./site build + +If you installed `hakyll` with a preview server (this is the default), you can +now use + + $ ./site preview + +and have a look at your site at +[http://localhost:8000/](http://localhost:8000/). -- cgit v1.2.3