summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/Hakyll/Check.hs10
-rw-r--r--src/Hakyll/Web/Html.hs4
-rw-r--r--src/Hakyll/Web/Tags.hs123
-rw-r--r--src/Hakyll/Web/Template/Context.hs1
4 files changed, 108 insertions, 30 deletions
diff --git a/src/Hakyll/Check.hs b/src/Hakyll/Check.hs
index 48bb655..d48f996 100644
--- a/src/Hakyll/Check.hs
+++ b/src/Hakyll/Check.hs
@@ -198,12 +198,14 @@ checkExternalUrl url = do
else do
isOk <- liftIO $ handle (failure logger) $
Http.withManager $ \mgr -> do
- request <- Http.parseUrl url
+ request <- Http.parseUrl urlToCheck
response <- Http.http (settings request) mgr
let code = Http.statusCode (Http.responseStatus response)
return $ code >= 200 && code < 300
- modify $ S.insert url
+ modify $ if schemeRelative url
+ then S.insert urlToCheck . S.insert url
+ else S.insert url
if isOk then ok url else faulty url
where
-- Add additional request info
@@ -221,6 +223,10 @@ checkExternalUrl url = do
failure logger (SomeException e) = case cast e of
Just UserInterrupt -> throw UserInterrupt
_ -> Logger.error logger (show e) >> return False
+
+ -- Check scheme-relative links
+ schemeRelative = isPrefixOf "//"
+ urlToCheck = if schemeRelative url then "http:" ++ url else url
#else
checkExternalUrl _ = return ()
#endif
diff --git a/src/Hakyll/Web/Html.hs b/src/Hakyll/Web/Html.hs
index 4053003..58b5c43 100644
--- a/src/Hakyll/Web/Html.hs
+++ b/src/Hakyll/Web/Html.hs
@@ -54,7 +54,7 @@ demoteHeaders = withTags $ \tag -> case tag of
--------------------------------------------------------------------------------
isUrlAttribute :: String -> Bool
-isUrlAttribute = (`elem` ["src", "href"])
+isUrlAttribute = (`elem` ["src", "href", "data"])
--------------------------------------------------------------------------------
@@ -120,7 +120,7 @@ toSiteRoot = emptyException . joinPath . map parent
--------------------------------------------------------------------------------
-- | Check if an URL links to an external HTTP(S) source
isExternal :: String -> Bool
-isExternal url = any (flip isPrefixOf url) ["http://", "https://"]
+isExternal url = any (flip isPrefixOf url) ["http://", "https://", "//"]
--------------------------------------------------------------------------------
diff --git a/src/Hakyll/Web/Tags.hs b/src/Hakyll/Web/Tags.hs
index f5a6578..0fa182c 100644
--- a/src/Hakyll/Web/Tags.hs
+++ b/src/Hakyll/Web/Tags.hs
@@ -49,8 +49,12 @@ module Hakyll.Web.Tags
, tagsRules
, renderTags
, renderTagCloud
+ , renderTagCloudWith
+ , tagCloudField
+ , tagCloudFieldWith
, renderTagList
, tagsField
+ , tagsFieldWith
, categoryField
, sortTagsBy
, caseInsensitiveTags
@@ -184,7 +188,6 @@ renderTags makeHtml concatHtml tags = do
--------------------------------------------------------------------------------
-- | Render a tag cloud in HTML
--- TODO: Maybe produce a Context here
renderTagCloud :: Double
-- ^ Smallest font size, in percent
-> Double
@@ -193,19 +196,73 @@ renderTagCloud :: Double
-- ^ Input tags
-> Compiler String
-- ^ Rendered cloud
-renderTagCloud minSize maxSize = renderTags makeLink (intercalate " ")
+renderTagCloud = renderTagCloudWith makeLink (intercalate " ")
where
- makeLink tag url count min' max' = renderHtml $
- H.a ! A.style (toValue $ "font-size: " ++ size count min' max')
- ! A.href (toValue url)
- $ toHtml tag
-
- -- Show the relative size of one 'count' in percent
- size count min' max' =
- let diff = 1 + fromIntegral max' - fromIntegral min'
+ makeLink minSize maxSize tag url count min' max' =
+ -- Show the relative size of one 'count' in percent
+ let diff = 1 + fromIntegral max' - fromIntegral min'
relative = (fromIntegral count - fromIntegral min') / diff
- size' = floor $ minSize + relative * (maxSize - minSize)
- in show (size' :: Int) ++ "%"
+ size = floor $ minSize + relative * (maxSize - minSize) :: Int
+ in renderHtml $
+ H.a ! A.style (toValue $ "font-size: " ++ show size ++ "%")
+ ! A.href (toValue url)
+ $ toHtml tag
+
+
+--------------------------------------------------------------------------------
+-- | Render a tag cloud in HTML
+renderTagCloudWith :: (Double -> Double ->
+ String -> String -> Int -> Int -> Int -> String)
+ -- ^ Render a single tag link
+ -> ([String] -> String)
+ -- ^ Concatenate links
+ -> Double
+ -- ^ Smallest font size, in percent
+ -> Double
+ -- ^ Biggest font size, in percent
+ -> Tags
+ -- ^ Input tags
+ -> Compiler String
+ -- ^ Rendered cloud
+renderTagCloudWith makeLink cat minSize maxSize =
+ renderTags (makeLink minSize maxSize) cat
+
+
+--------------------------------------------------------------------------------
+-- | Render a tag cloud in HTML as a context
+tagCloudField :: String
+ -- ^ Destination key
+ -> Double
+ -- ^ Smallest font size, in percent
+ -> Double
+ -- ^ Biggest font size, in percent
+ -> Tags
+ -- ^ Input tags
+ -> Context a
+ -- ^ Context
+tagCloudField key minSize maxSize tags =
+ field key $ \_ -> renderTagCloud minSize maxSize tags
+
+
+--------------------------------------------------------------------------------
+-- | Render a tag cloud in HTML as a context
+tagCloudFieldWith :: String
+ -- ^ Destination key
+ -> (Double -> Double ->
+ String -> String -> Int -> Int -> Int -> String)
+ -- ^ Render a single tag link
+ -> ([String] -> String)
+ -- ^ Concatenate links
+ -> Double
+ -- ^ Smallest font size, in percent
+ -> Double
+ -- ^ Biggest font size, in percent
+ -> Tags
+ -- ^ Input tags
+ -> Context a
+ -- ^ Context
+tagCloudFieldWith key makeLink cat minSize maxSize tags =
+ field key $ \_ -> renderTagCloudWith makeLink cat minSize maxSize tags
--------------------------------------------------------------------------------
@@ -219,23 +276,27 @@ renderTagList = renderTags makeLink (intercalate ", ")
--------------------------------------------------------------------------------
--- | Render tags with links with custom function to get tags
-tagsFieldWith :: (Identifier -> Compiler [String]) -- ^ Get the tags
- -> String -- ^ Destination field
- -> Tags -- ^ Tags structure
- -> Context a -- ^ Resulting context
-tagsFieldWith getTags' key tags = field key $ \item -> do
+-- | Render tags with links with custom functions to get tags and to
+-- render links
+tagsFieldWith :: (Identifier -> Compiler [String])
+ -- ^ Get the tags
+ -> (String -> (Maybe FilePath) -> Maybe H.Html)
+ -- ^ Render link for one tag
+ -> ([H.Html] -> H.Html)
+ -- ^ Concatenate tag links
+ -> String
+ -- ^ Destination field
+ -> Tags
+ -- ^ Tags structure
+ -> Context a
+ -- ^ Resulting context
+tagsFieldWith getTags' renderLink cat key tags = field key $ \item -> do
tags' <- getTags' $ itemIdentifier item
links <- forM tags' $ \tag -> do
route' <- getRoute $ tagsMakeId tags tag
return $ renderLink tag route'
- return $ renderHtml $ mconcat $ intersperse ", " $ catMaybes $ links
- where
- -- Render one tag link
- renderLink _ Nothing = Nothing
- renderLink tag (Just filePath) = Just $
- H.a ! A.href (toValue $ toUrl filePath) $ toHtml tag
+ return $ renderHtml $ cat $ catMaybes $ links
--------------------------------------------------------------------------------
@@ -243,7 +304,8 @@ tagsFieldWith getTags' key tags = field key $ \item -> do
tagsField :: String -- ^ Destination key
-> Tags -- ^ Tags
-> Context a -- ^ Context
-tagsField = tagsFieldWith getTags
+tagsField =
+ tagsFieldWith getTags simpleRenderLink (mconcat . intersperse ", ")
--------------------------------------------------------------------------------
@@ -251,7 +313,16 @@ tagsField = tagsFieldWith getTags
categoryField :: String -- ^ Destination key
-> Tags -- ^ Tags
-> Context a -- ^ Context
-categoryField = tagsFieldWith getCategory
+categoryField =
+ tagsFieldWith getCategory simpleRenderLink (mconcat . intersperse ", ")
+
+
+--------------------------------------------------------------------------------
+-- | Render one tag link
+simpleRenderLink :: String -> (Maybe FilePath) -> Maybe H.Html
+simpleRenderLink _ Nothing = Nothing
+simpleRenderLink tag (Just filePath) =
+ Just $ H.a ! A.href (toValue $ toUrl filePath) $ toHtml tag
--------------------------------------------------------------------------------
diff --git a/src/Hakyll/Web/Template/Context.hs b/src/Hakyll/Web/Template/Context.hs
index b885462..2b85b30 100644
--- a/src/Hakyll/Web/Template/Context.hs
+++ b/src/Hakyll/Web/Template/Context.hs
@@ -203,6 +203,7 @@ getItemUTC locale id' = do
, "%Y-%m-%d"
, "%B %e, %Y %l:%M %p"
, "%B %e, %Y"
+ , "%b %d, %Y"
]