summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--hakyll.cabal3
-rw-r--r--src/Hakyll/Check.hs15
-rw-r--r--src/Hakyll/Core/Rules/Internal.hs24
-rw-r--r--tests/Hakyll/Core/Rules/Tests.hs16
-rw-r--r--tests/Hakyll/Core/Runtime/Tests.hs22
-rw-r--r--tests/data/images/favicon.icobin0 -> 1150 bytes
-rw-r--r--web/examples.markdown4
-rw-r--r--web/tutorials/faq.markdown2
8 files changed, 53 insertions, 33 deletions
diff --git a/hakyll.cabal b/hakyll.cabal
index 5dce405..f9dfd5a 100644
--- a/hakyll.cabal
+++ b/hakyll.cabal
@@ -64,10 +64,11 @@ Data-files:
Extra-source-files:
tests/data/example.md
tests/data/example.md.metadata
+ tests/data/images/favicon.ico
+ tests/data/posts/2010-08-26-birthday.md
tests/data/russian.md
tests/data/template.html
tests/data/template.html.out
- tests/data/posts/2010-08-26-birthday.md
Source-Repository head
Type: git
diff --git a/src/Hakyll/Check.hs b/src/Hakyll/Check.hs
index 5f8f4f7..a426f87 100644
--- a/src/Hakyll/Check.hs
+++ b/src/Hakyll/Check.hs
@@ -16,11 +16,12 @@ import Control.Monad.RWS (RWST, runRWST)
import Control.Monad.State (get, modify)
import Control.Monad.Trans (liftIO)
import Control.Monad.Writer (tell)
-import Data.List (isPrefixOf)
+import Data.List (intercalate, isPrefixOf)
import Data.Monoid (Monoid (..))
import Data.Set (Set)
import qualified Data.Set as S
import Data.Typeable (cast)
+import GHC.Exts (fromString)
import qualified Network.HTTP.Conduit as Http
import qualified Network.HTTP.Types as Http
import System.Directory (doesDirectoryExist, doesFileExist)
@@ -30,11 +31,13 @@ import qualified Text.HTML.TagSoup as TS
--------------------------------------------------------------------------------
+import Data.Version (versionBranch)
import Hakyll.Core.Configuration
import Hakyll.Core.Logger (Logger, Verbosity)
import qualified Hakyll.Core.Logger as Logger
import Hakyll.Core.Util.File
import Hakyll.Web.Html
+import qualified Paths_hakyll as Paths_hakyll
--------------------------------------------------------------------------------
@@ -172,11 +175,17 @@ checkExternalUrl url = do
modify $ S.insert url
if isOk then ok url else faulty url
where
+ -- Add additional request info
settings r = r
- { Http.method = "HEAD"
- , Http.redirectCount = 10
+ { Http.method = "HEAD"
+ , Http.redirectCount = 10
+ , Http.requestHeaders = ("User-Agent", ua) : Http.requestHeaders r
}
+ -- Nice user agent info
+ ua = fromString $ "hakyll-check/" ++
+ (intercalate "." $ map show $ versionBranch $ Paths_hakyll.version)
+
-- Catch all the things except UserInterrupt
failure logger (SomeException e) = case cast e of
Just UserInterrupt -> throw UserInterrupt
diff --git a/src/Hakyll/Core/Rules/Internal.hs b/src/Hakyll/Core/Rules/Internal.hs
index 09d9b1e..6bb82df 100644
--- a/src/Hakyll/Core/Rules/Internal.hs
+++ b/src/Hakyll/Core/Rules/Internal.hs
@@ -16,9 +16,9 @@ import Control.Applicative (Applicative, (<$>))
import Control.Monad.Reader (ask)
import Control.Monad.RWS (RWST, runRWST)
import Control.Monad.Trans (liftIO)
+import qualified Data.Map as M
import Data.Monoid (Monoid, mappend, mempty)
import Data.Set (Set)
-import qualified Data.Set as S
--------------------------------------------------------------------------------
@@ -92,25 +92,17 @@ instance MonadMetadata Rules where
runRules :: Rules a -> Provider -> IO RuleSet
runRules rules provider = do
(_, _, ruleSet) <- runRWST (unRules rules) env emptyRulesState
- case findDuplicate (map fst $ rulesCompilers ruleSet) of
- Nothing -> return ruleSet
- Just id' -> error $
- "Hakyll.Core.Rules.Internal: two different rules for " ++
- show id' ++ " exist, bailing out"
+ -- Ensure compiler uniqueness
+ let ruleSet' = ruleSet
+ { rulesCompilers = M.toList $
+ M.fromListWith (flip const) (rulesCompilers ruleSet)
+ }
+
+ return ruleSet'
where
env = RulesRead
{ rulesProvider = provider
, rulesMatches = []
, rulesVersion = Nothing
}
-
-
---------------------------------------------------------------------------------
-findDuplicate :: Ord a => [a] -> Maybe a
-findDuplicate = go S.empty
- where
- go _ [] = Nothing
- go s (x : xs)
- | x `S.member` s = Just x
- | otherwise = go (S.insert x s) xs
diff --git a/tests/Hakyll/Core/Rules/Tests.hs b/tests/Hakyll/Core/Rules/Tests.hs
index ee12010..47d3b3b 100644
--- a/tests/Hakyll/Core/Rules/Tests.hs
+++ b/tests/Hakyll/Core/Rules/Tests.hs
@@ -10,7 +10,6 @@ import Data.IORef (IORef, newIORef, readIORef,
writeIORef)
import qualified Data.Set as S
import Test.Framework (Test, testGroup)
-import Test.Framework.Providers.HUnit (testCase)
import Test.HUnit (Assertion, assert, (@=?))
@@ -28,18 +27,17 @@ import TestSuite.Util
--------------------------------------------------------------------------------
tests :: Test
-tests = testGroup "Hakyll.Core.Rules.Tests"
- [ testCase "runRules" rulesTest
- ]
+tests = testGroup "Hakyll.Core.Rules.Tests" $ fromAssertions "runRules"
+ [case01]
--------------------------------------------------------------------------------
-rulesTest :: Assertion
-rulesTest = do
+case01 :: Assertion
+case01 = do
ioref <- newIORef False
store <- newTestStore
provider <- newTestProvider store
- ruleSet <- runRules (rules ioref) provider
+ ruleSet <- runRules (rules01 ioref) provider
let identifiers = S.fromList $ map fst $ rulesCompilers ruleSet
routes = rulesRoutes ruleSet
@@ -64,8 +62,8 @@ rulesTest = do
--------------------------------------------------------------------------------
-rules :: IORef Bool -> Rules ()
-rules ioref = do
+rules01 :: IORef Bool -> Rules ()
+rules01 ioref = do
-- Compile some posts
match "*.md" $ do
route $ setExtension "html"
diff --git a/tests/Hakyll/Core/Runtime/Tests.hs b/tests/Hakyll/Core/Runtime/Tests.hs
index c68d99e..8a05824 100644
--- a/tests/Hakyll/Core/Runtime/Tests.hs
+++ b/tests/Hakyll/Core/Runtime/Tests.hs
@@ -20,7 +20,8 @@ import TestSuite.Util
--------------------------------------------------------------------------------
tests :: Test
-tests = testGroup "Hakyll.Core.Runtime.Tests" $ fromAssertions "run" [case01]
+tests = testGroup "Hakyll.Core.Runtime.Tests" $
+ fromAssertions "run" [case01, case02]
--------------------------------------------------------------------------------
@@ -48,3 +49,22 @@ case01 = do
head (lines bodies) @?= "This is an example."
cleanTestEnv
+
+
+--------------------------------------------------------------------------------
+case02 :: Assertion
+case02 = do
+ _ <- run testConfiguration Logger.Error $ do
+ match "images/favicon.ico" $ do
+ route $ gsubRoute "images/" (const "")
+ compile $ makeItem ("Test" :: String)
+
+ match "images/**" $ do
+ route idRoute
+ compile copyFileCompiler
+
+ favicon <- readFile $
+ destinationDirectory testConfiguration </> "favicon.ico"
+ favicon @?= "Test"
+
+ cleanTestEnv
diff --git a/tests/data/images/favicon.ico b/tests/data/images/favicon.ico
new file mode 100644
index 0000000..fc2cca2
--- /dev/null
+++ b/tests/data/images/favicon.ico
Binary files differ
diff --git a/web/examples.markdown b/web/examples.markdown
index ad1fadb..6def57b 100644
--- a/web/examples.markdown
+++ b/web/examples.markdown
@@ -21,6 +21,8 @@ this list. This list has no particular ordering.
[source](https://github.com/bneijt/bneijt.nl)
- <http://brianshourd.com/>,
[source](https://github.com/brianshourd/brianshourd.com)
+- <http://variadic.me>,
+ [source](https://github.com/eakron/variadic.me)
## Hakyll 3.X
@@ -46,8 +48,6 @@ this list. This list has no particular ordering.
[source](https://github.com/deepakjois/website)
- <http://sigkill.dk/>,
[literate source](http://sigkill.dk/programs/sigkill.html)
-- <http://variadic.me>,
- [source](https://github.com/eakron/variadic.me)
- <http://orftz.com>,
[source](https://github.com/orftz/orftz.com)
- <http://citationneeded.me/>,
diff --git a/web/tutorials/faq.markdown b/web/tutorials/faq.markdown
index ad6dbd8..63f310f 100644
--- a/web/tutorials/faq.markdown
+++ b/web/tutorials/faq.markdown
@@ -49,7 +49,7 @@ blocks][pandoc-code-blocks] and [inline code][pandoc-inline-code].
If you execute a `./site build`, Hakyll will build your site incrementally.
However, we can not detect if you edited `site.hs`. In this case, you first want
-to compile it again `site.hs` again, and then do a `./site rebuild`.
+to compile `site.hs` again, and then do a `./site rebuild`.
After rebuilding your site, all files will look as "modified" to the filesystem.
This means that when you upload your site, it will usually transfer all files --