From 2651627189ba8b35949580b9a31cc1dde4911f88 Mon Sep 17 00:00:00 2001 From: "Ivan N. Veselov" Date: Sat, 4 May 2013 17:24:03 +0300 Subject: Added "teasers" support to be used in posts index. Just add "" to separate the teaser and the rest of the article and use "$teaser$" key in the template! Closes issue #35. --- src/Hakyll/Core/Util/String.hs | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'src/Hakyll/Core/Util') diff --git a/src/Hakyll/Core/Util/String.hs b/src/Hakyll/Core/Util/String.hs index 514dd14..d9ec91c 100644 --- a/src/Hakyll/Core/Util/String.hs +++ b/src/Hakyll/Core/Util/String.hs @@ -4,9 +4,11 @@ module Hakyll.Core.Util.String ( trim , replaceAll , splitAll + , needlePrefix ) where import Data.Char (isSpace) +import Data.List (isPrefixOf) import Data.Maybe (listToMaybe) import Text.Regex.TDFA ((=~~)) @@ -46,3 +48,21 @@ splitAll pattern = filter (not . null) . splitAll' Just (o, l) -> let (before, tmp) = splitAt o src in before : splitAll' (drop l tmp) + + +-- | Find the first instance of needle (must be non-empty) in +-- haystack. We return the prefix of haystack before needle is +-- matched. +-- +-- Examples: +-- needlePrefix "cd" "abcde" = "ab" +-- needlePrefix "ab" "abc" = "" +-- needlePrefix "ab" "xxab" = "xx" +-- needlePrefix "a" "xx" = "xx" +-- +needlePrefix :: String -> String -> String +needlePrefix needle haystack = go haystack + where + go [] = [] + go xss@(x:xs) | needle `isPrefixOf` xss = [] + | otherwise = x : go xs -- cgit v1.2.3