summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--examples/hakyll/philosophy.markdown2
-rw-r--r--src/Text/Hakyll/File.hs1
-rw-r--r--src/Text/Hakyll/Util.hs8
-rw-r--r--tests/Tests.hs6
4 files changed, 16 insertions, 1 deletions
diff --git a/examples/hakyll/philosophy.markdown b/examples/hakyll/philosophy.markdown
index 775f239..07a20c3 100644
--- a/examples/hakyll/philosophy.markdown
+++ b/examples/hakyll/philosophy.markdown
@@ -18,7 +18,7 @@ never exceed a 100 lines of code.
Hakyll tries to provide as many high-level functions as possible for common
tasks, while the lower-level functions should also be accessible. If you think
you're writing something that can be used for many sites, please send a patch,
-our your `hakyll.hs`, and we will see what we can do.
+or your `hakyll.hs`, and we will see what we can do.
## Well-documented
diff --git a/src/Text/Hakyll/File.hs b/src/Text/Hakyll/File.hs
index c535b11..0c803e1 100644
--- a/src/Text/Hakyll/File.hs
+++ b/src/Text/Hakyll/File.hs
@@ -50,6 +50,7 @@ getRecursiveContents topdir = do
-- | A filter that takes all file names with a given extension. Prefix the
-- extension with a dot:
+--
-- > havingExtension ".markdown" ["index.markdown", "style.css"] == ["index.markdown"]
havingExtension :: String -> [FilePath] -> [FilePath]
havingExtension extension = filter ((==) extension . takeExtension)
diff --git a/src/Text/Hakyll/Util.hs b/src/Text/Hakyll/Util.hs
index d498281..319bed4 100644
--- a/src/Text/Hakyll/Util.hs
+++ b/src/Text/Hakyll/Util.hs
@@ -2,6 +2,7 @@ module Text.Hakyll.Util
( trim
, split
, stripHTML
+ , link
) where
import Data.Char (isSpace)
@@ -26,3 +27,10 @@ stripHTML str = let (beforeTag, rest) = break (== '<') str
split :: String -> String -> [String]
split pattern = filter (not . null)
. splitRegex (mkRegex pattern)
+
+-- | Make a HTML link.
+--
+-- > link "foo" "bar.html" == "<a href='bar.html'>foo</a>"
+link :: String -> String -> String
+link text destination = "<a href=\"" ++ destination ++ "\">"
+ ++ text ++ "</a>"
diff --git a/tests/Tests.hs b/tests/Tests.hs
index f83399d..3c2cb1e 100644
--- a/tests/Tests.hs
+++ b/tests/Tests.hs
@@ -23,6 +23,8 @@ tests = [ testGroup "Util group" [ testProperty "trim length" prop_trim_length
, testCase "stripHTML 3" test_strip_html3
, testCase "split 1" test_split1
, testCase "split 2" test_split2
+ , testCase "link 1" test_link1
+ , testCase "link 2" test_link2
]
, testGroup "CompressCSS group" [ testProperty "compressCSS length" prop_compress_css_length
@@ -63,6 +65,10 @@ test_strip_html3 = stripHTML "<b>Hakyll</b> is an <i>awesome</i> web framework <
test_split1 = split "," "1,2,3" @?= ["1", "2", "3"]
test_split2 = split "," ",1,2," @?= ["1", "2"]
+-- Link test cases.
+test_link1 = link "foo bar" "/foo/bar.html" @?= "<a href=\"/foo/bar.html\">foo bar</a>"
+test_link2 = link "back home" "/" @?= "<a href=\"/\">back home</a>"
+
-- CSS compression should always decrease the text length.
prop_compress_css_length str = length str >= length (compressCSS str)