This commit is contained in:
Jasper Van der Jeugt 2012-12-14 12:12:28 +01:00
parent a2620eec36
commit adc8cf8528
2 changed files with 28 additions and 61 deletions

View file

@ -1,40 +1,33 @@
-------------------------------------------------------------------------------- --------------------------------------------------------------------------------
-- | Module providing pattern matching and capturing on 'Identifier's. -- | As 'Identifier' is used to specify a single item, a 'Pattern' is used to
-- 'Pattern's come in two kinds: -- specify a list of items.
-- --
-- * Simple glob patterns, like @foo\/*@; -- In most cases, globs are used for patterns.
-- --
-- * Custom, arbitrary predicates of the type @Identifier -> Bool@. -- A very simple pattern of such a pattern is @\"foo\/bar\"@. This pattern will
--
-- They both have advantages and disadvantages. By default, globs are used,
-- unless you construct your 'Pattern' using the 'predicate' function.
--
-- A very simple pattern could be, for example, @foo\/bar@. This pattern will
-- only match the exact @foo\/bar@ identifier. -- only match the exact @foo\/bar@ identifier.
-- --
-- To match more than one identifier, there are different captures that one can -- To match more than one identifier, there are different captures that one can
-- use: -- use:
-- --
-- * @*@: matches at most one element of an identifier; -- * @\"*\"@: matches at most one element of an identifier;
-- --
-- * @**@: matches one or more elements of an identifier. -- * @\"**\"@: matches one or more elements of an identifier.
-- --
-- Some examples: -- Some examples:
-- --
-- * @foo\/*@ will match @foo\/bar@ and @foo\/foo@, but not @foo\/bar\/qux@; -- * @\"foo\/*\"@ will match @\"foo\/bar\"@ and @\"foo\/foo\"@, but not
-- @\"foo\/bar\/qux\"@;
-- --
-- * @**@ will match any identifier; -- * @\"**\"@ will match any identifier;
-- --
-- * @foo\/**@ will match @foo\/bar@ and @foo\/bar\/qux@, but not @bar\/foo@; -- * @\"foo\/**\"@ will match @\"foo\/bar\"@ and @\"foo\/bar\/qux\"@, but not
-- @\"bar\/foo\"@;
-- --
-- * @foo\/*.html@ will match all HTML files in the @foo\/@ directory. -- * @\"foo\/*.html\"@ will match all HTML files in the @\"foo\/\"@ directory.
-- --
-- The 'capture' function allows the user to get access to the elements captured -- The 'capture' function allows the user to get access to the elements captured
-- by the capture elements in the pattern. -- by the capture elements in the pattern.
--
-- Like an 'Identifier', a 'Pattern' also has a type parameter. This is simply
-- an extra layer of safety, and can be discarded using the 'castPattern'
-- function.
module Hakyll.Core.Identifier.Pattern module Hakyll.Core.Identifier.Pattern
( -- * The pattern type ( -- * The pattern type
Pattern Pattern
@ -213,8 +206,8 @@ withVersion p v = optimize $ And p $ fromVersion $ Just v
-------------------------------------------------------------------------------- --------------------------------------------------------------------------------
-- | Check if a pattern is a literal. @"*.markdown"@ is not a literal but -- | Check if a pattern is a literal. @\"*.markdown\"@ is not a literal but
-- @"posts.markdown"@ is. -- @\"posts.markdown\"@ is.
fromLiteral :: Pattern -> Maybe Identifier fromLiteral :: Pattern -> Maybe Identifier
fromLiteral pattern = case pattern of fromLiteral pattern = case pattern of
Glob p -> fmap fromFilePath $ foldr fromLiteral' (Just "") p Glob p -> fmap fromFilePath $ foldr fromLiteral' (Just "") p

View file

@ -3,52 +3,26 @@ title: The basics
author: Jasper Van der Jeugt author: Jasper Van der Jeugt
--- ---
## Let's get started! Building and cleaning
---------------------
We're going to discuss a small brochure site to start with. You can find all If you followed along with the previous tutorial, you should now have the
code and files necessary to build this site example site up and running. By running `./site build`, you created two
[right here](http://github.com/jaspervdj/hakyll-examples/tree/master/brochure) directories:
-- feel free to look at them as we go trough the tutorial. To fetch all examples
in order to play with them locally, use:
git clone git://github.com/jaspervdj/hakyll-examples.git - `_site`, with your site as HTML files, ready to be deployed;
- `_cache`, which Hakyll uses internally.
or navigate to the download menu on GitHub. `./site clean` removes these directories, and `./site rebuild` performs a
`clean` and then a `build`.
Now, for this first tutorial, there's a number of files we will use: In general, it's only necessary to use `rebuild` when you made changes to your
`site.hs`, and not when you just made changes to the contents of your website.
about.rst A simple page written in RST format Basic rules
code.lhs Another page with some code (which can be highlighted) -----------
css Directory for CSS files
|- default.css The main CSS file
\- syntax.css CSS file for code syntax highlighting
hakyll.hs Our code to generate the site
images Directory for images
\- haskell-logo.png The logo of my favorite programming language
index.markdown A simple page in markdown format
templates Directory for templates
\- default.html The main template for the site
By default, hakyll will compile everything to the `_site` directory. We can try TODO
this like this:
[jasper@phoenix] ghc --make hakyll.hs
[jasper@phoenix] ./hakyll build
Instead of using `build`, we can also use `preview`, which will fire up a
webserver serving the `_site` directory, so have a look!
All files have been compiled, and their output has been placed in the `_site`
directory as illustrated in this diagram:
![Brochure files](/images/brochure-files.png)
No magic is involved at all -- we will precisely study how and why our items are
compiled like that. All of this is specified in the `hakyll.hs` file. You can
view the full `hakyll.hs` file online [here][brochure-hakyll.hs], or you can
look in the directory you cloned or downloaded.
[brochure-hakyll.hs]: http://github.com/jaspervdj/hakyll-examples/blob/master/brochure/hakyll.hs
## Images ## Images