diff options
Diffstat (limited to 'src/Hakyll/Web')
-rw-r--r-- | src/Hakyll/Web/CompressCss.hs | 2 | ||||
-rw-r--r-- | src/Hakyll/Web/Feed.hs | 2 | ||||
-rw-r--r-- | src/Hakyll/Web/Page.hs | 2 | ||||
-rw-r--r-- | src/Hakyll/Web/Page/Metadata.hs | 2 | ||||
-rw-r--r-- | src/Hakyll/Web/Page/Read.hs | 2 | ||||
-rw-r--r-- | src/Hakyll/Web/Preview/Server.hs | 2 | ||||
-rw-r--r-- | src/Hakyll/Web/RelativizeUrls.hs | 2 | ||||
-rw-r--r-- | src/Hakyll/Web/Tags.hs | 3 | ||||
-rw-r--r-- | src/Hakyll/Web/Util/String.hs | 73 | ||||
-rw-r--r-- | src/Hakyll/Web/Util/Url.hs | 30 |
10 files changed, 39 insertions, 81 deletions
diff --git a/src/Hakyll/Web/CompressCss.hs b/src/Hakyll/Web/CompressCss.hs index 94ba9a9..2df08fd 100644 --- a/src/Hakyll/Web/CompressCss.hs +++ b/src/Hakyll/Web/CompressCss.hs @@ -12,7 +12,7 @@ import Control.Arrow ((>>^)) import Hakyll.Core.Compiler import Hakyll.Core.ResourceProvider -import Hakyll.Web.Util.String +import Hakyll.Core.Util.String -- | Compiler form of 'compressCss' -- diff --git a/src/Hakyll/Web/Feed.hs b/src/Hakyll/Web/Feed.hs index d91a60f..85674c6 100644 --- a/src/Hakyll/Web/Feed.hs +++ b/src/Hakyll/Web/Feed.hs @@ -33,7 +33,7 @@ import Hakyll.Web.Page import Hakyll.Web.Page.Metadata import Hakyll.Web.Template import Hakyll.Web.Template.Read.Hakyll (readTemplate) -import Hakyll.Web.Util.String +import Hakyll.Web.Util.Url import Paths_hakyll diff --git a/src/Hakyll/Web/Page.hs b/src/Hakyll/Web/Page.hs index 8a16ef8..955e1a8 100644 --- a/src/Hakyll/Web/Page.hs +++ b/src/Hakyll/Web/Page.hs @@ -73,7 +73,7 @@ import Hakyll.Web.Page.Read import Hakyll.Web.Page.Metadata import Hakyll.Web.Pandoc import Hakyll.Web.Template -import Hakyll.Web.Util.String +import Hakyll.Web.Util.Url -- | Create a page from a body, without metadata -- diff --git a/src/Hakyll/Web/Page/Metadata.hs b/src/Hakyll/Web/Page/Metadata.hs index 23d98a4..72742e6 100644 --- a/src/Hakyll/Web/Page/Metadata.hs +++ b/src/Hakyll/Web/Page/Metadata.hs @@ -24,7 +24,7 @@ import System.FilePath (takeFileName) import System.Locale (TimeLocale, defaultTimeLocale) import Hakyll.Web.Page.Internal -import Hakyll.Web.Util.String +import Hakyll.Core.Util.String -- | Get a metadata field. If the field does not exist, the empty string is -- returned. diff --git a/src/Hakyll/Web/Page/Read.hs b/src/Hakyll/Web/Page/Read.hs index d72f32a..cf39ddd 100644 --- a/src/Hakyll/Web/Page/Read.hs +++ b/src/Hakyll/Web/Page/Read.hs @@ -12,7 +12,7 @@ import Data.Map (Map) import qualified Data.Map as M import Hakyll.Web.Page.Internal -import Hakyll.Web.Util.String +import Hakyll.Core.Util.String -- | We're using a simple state monad as parser -- diff --git a/src/Hakyll/Web/Preview/Server.hs b/src/Hakyll/Web/Preview/Server.hs index 77b3cb0..c550b69 100644 --- a/src/Hakyll/Web/Preview/Server.hs +++ b/src/Hakyll/Web/Preview/Server.hs @@ -18,7 +18,7 @@ import Snap.Http.Server ( httpServe, setAccessLog, setErrorLog, addListen , ConfigListen (..), emptyConfig ) -import Hakyll.Web.Util.String (replaceAll) +import Hakyll.Core.Util.String (replaceAll) -- | The first file in the list that actually exists is returned -- diff --git a/src/Hakyll/Web/RelativizeUrls.hs b/src/Hakyll/Web/RelativizeUrls.hs index 1df4fea..2de4a0e 100644 --- a/src/Hakyll/Web/RelativizeUrls.hs +++ b/src/Hakyll/Web/RelativizeUrls.hs @@ -29,7 +29,7 @@ import Text.HTML.TagSoup import Hakyll.Core.Compiler import Hakyll.Web.Page -import Hakyll.Web.Util.String +import Hakyll.Web.Util.Url -- | Compiler form of 'compressCss' which automatically picks the right root -- path diff --git a/src/Hakyll/Web/Tags.hs b/src/Hakyll/Web/Tags.hs index 77dc440..211a06b 100644 --- a/src/Hakyll/Web/Tags.hs +++ b/src/Hakyll/Web/Tags.hs @@ -55,10 +55,11 @@ import qualified Text.Blaze.Html5.Attributes as A import Hakyll.Web.Page import Hakyll.Web.Page.Metadata -import Hakyll.Web.Util.String +import Hakyll.Web.Util.Url import Hakyll.Core.Writable import Hakyll.Core.Identifier import Hakyll.Core.Compiler +import Hakyll.Core.Util.String -- | Data about tags -- diff --git a/src/Hakyll/Web/Util/String.hs b/src/Hakyll/Web/Util/String.hs deleted file mode 100644 index 0dde74a..0000000 --- a/src/Hakyll/Web/Util/String.hs +++ /dev/null @@ -1,73 +0,0 @@ --- | Miscellaneous string manipulation functions. --- -module Hakyll.Web.Util.String - ( trim - , replaceAll - , splitAll - , toUrl - , toSiteRoot - ) where - -import Data.Char (isSpace) -import Data.Maybe (listToMaybe) - -import System.FilePath (splitPath, takeDirectory, joinPath) -import Text.Regex.PCRE ((=~~)) - --- | Trim a string (drop spaces, tabs and newlines at both sides). --- -trim :: String -> String -trim = reverse . trim' . reverse . trim' - where - trim' = dropWhile isSpace - --- | A simple (but inefficient) regex replace funcion --- -replaceAll :: String -- ^ Pattern - -> (String -> String) -- ^ Replacement (called on capture) - -> String -- ^ Source string - -> String -- ^ Result -replaceAll pattern f source = replaceAll' source - where - replaceAll' src = case listToMaybe (src =~~ pattern) of - Nothing -> src - Just (o, l) -> - let (before, tmp) = splitAt o src - (capture, after) = splitAt l tmp - in before ++ f capture ++ replaceAll' after - --- | A simple regex split function. The resulting list will contain no empty --- strings. --- -splitAll :: String -- ^ Pattern - -> String -- ^ String to split - -> [String] -- ^ Result -splitAll pattern = filter (not . null) . splitAll' - where - splitAll' src = case listToMaybe (src =~~ pattern) of - Nothing -> [src] - Just (o, l) -> - let (before, tmp) = splitAt o src - in before : splitAll' (drop l tmp) - --- | Convert a filepath to an URL starting from the site root --- --- Example: --- --- > toUrl "foo/bar.html" --- --- Result: --- --- > "/foo/bar.html" --- -toUrl :: FilePath -> String -toUrl = ('/' :) - --- | Get the relative url to the site root, for a given (absolute) url --- -toSiteRoot :: String -> String -toSiteRoot = emptyException . joinPath . map parent . splitPath . takeDirectory - where - parent = const ".." - emptyException [] = "." - emptyException x = x diff --git a/src/Hakyll/Web/Util/Url.hs b/src/Hakyll/Web/Util/Url.hs new file mode 100644 index 0000000..54a361e --- /dev/null +++ b/src/Hakyll/Web/Util/Url.hs @@ -0,0 +1,30 @@ +-- | Miscellaneous URL manipulation functions. +-- +module Hakyll.Web.Util.Url + ( toUrl + , toSiteRoot + ) where + +import System.FilePath (splitPath, takeDirectory, joinPath) + +-- | Convert a filepath to an URL starting from the site root +-- +-- Example: +-- +-- > toUrl "foo/bar.html" +-- +-- Result: +-- +-- > "/foo/bar.html" +-- +toUrl :: FilePath -> String +toUrl = ('/' :) + +-- | Get the relative url to the site root, for a given (absolute) url +-- +toSiteRoot :: String -> String +toSiteRoot = emptyException . joinPath . map parent . splitPath . takeDirectory + where + parent = const ".." + emptyException [] = "." + emptyException x = x |