Skip to content

Commit

Permalink
Merge branch 'article-order'
Browse files Browse the repository at this point in the history
  • Loading branch information
koterpillar committed Feb 4, 2015
2 parents ff4d9bb + ceb2386 commit 76ef655
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/App.hs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ module App where
import Control.Monad.State

import qualified Data.ByteString.Char8 as B
import Data.List
import Data.Maybe
import qualified Data.Text as T
import Data.Time
Expand Down Expand Up @@ -86,8 +87,9 @@ article date slug = do
articleList :: (Article -> Bool) -> AppPart Response
articleList articleFilter = do
articles <- lift $ getFiltered articleFilter
let sorted = sortBy reverseCompare articles
language <- languageHeaderM
articleListDisplay language articles >>= html
articleListDisplay language sorted >>= html

meta :: String -> AppPart Response
meta slug = do
Expand Down
3 changes: 3 additions & 0 deletions src/Models.hs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ data Article = Article { arSlug :: String
}
deriving (Eq, Show)

instance Ord Article where
a `compare` b = (arAuthored a, arSlug a) `compare` (arAuthored b, arSlug b)

data Meta = Meta { mtSlug :: String
, mtContent :: LanguageContent
}
Expand Down
3 changes: 3 additions & 0 deletions src/Utils.hs
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,6 @@ isSpecial :: FilePath -> Bool
isSpecial "." = True
isSpecial ".." = True
isSpecial _ = False

reverseCompare :: Ord a => a -> a -> Ordering
reverseCompare a b = compare b a
6 changes: 6 additions & 0 deletions testsuite/Integration/Base.hs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,12 @@ assertContains needle haystack =
(show needle ++ " not found in:\n" ++ show haystack)
(needle `isInfixOf` haystack)

assertContainsBefore :: (Eq a, Show a) => [a] -> [a] -> [a] -> Assertion
assertContainsBefore first second haystack =
subAssert $ assertBoolVerbose
(show first ++ " does not precede " ++ show second ++ " in:\n" ++ show haystack)
(second `isInfixOf` (head $ dropWhile (first `isInfixOf`) $ tails haystack))

-- Create a request with a specified URL
-- Happstack doesn't make it easy
mkRequest :: String -> IO Request
Expand Down
1 change: 1 addition & 0 deletions testsuite/Integration/TestHome.hs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ test_home = do
home <- testRequest req
resp <- responseContent home
assertContains "Test site" resp
assertContainsBefore "Another article" "First test article" resp

test_home_lang = do
req <- liftM (withLang1 RU) (mkRequest "/")
Expand Down
9 changes: 9 additions & 0 deletions testsuite/Integration/content/2015-02-01-another-en.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
lang: en
slug: second-article
---

Another article
---------------

This article should appear above the first one.

0 comments on commit 76ef655

Please sign in to comment.