Skip to content

Commit d7c9a23

Browse files
authored
Merge pull request #123 from Maeevick/feat/hakyll-news-pages-migration
Feat/hakyll news pages migration
2 parents 33c1c65 + 4b1d267 commit d7c9a23

17 files changed

+304
-394
lines changed

affiliates/index.html

-71
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
title: Haskell Foundation Announced
3+
---
4+
5+
Today Simon Peyton-Jones announced the formation of The Haskell Foundation, a non-profit organization focused on increasing adoption of the Haskell programming language. Watch the announcemnt <a href='https://youtu.be/MEmRarBL9kw' target='_blank'>here.</a>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
title: Haskell Foundation Board Of Directors Call For Nominations
3+
---
4+
5+
The Haskell Foundation has issued a <a href='/board-nominations'>call for nominations to the Board of Directors</a>. Nominations will remain open until January 11, 2021. New Board members will be selected by the interim members of the <a href='/who-we-are'>Board of Directors</a>.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
title: Haskell Foundation Seeks Executive Director
3+
---
4+
5+
The Haskell Foundation is seeking a full-time <a href='https://haskell.foundation/ed-job-description/' target='_blank'>Executive Director.</a>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
title: Announcing the Haskell Foundation Board
3+
---
4+
5+
Simon Peyton-Jones <a href='https://discourse.haskell.org/t/announcing-the-haskell-foundation-board/1811' target='_blank'>announced the Haskell Foundation Board.</a>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
title: Haskell Foundation Executive Director and Chief Technology Officer
3+
---
4+
5+
Simon Peyton-Jones <a href='https://discourse.haskell.org/t/haskell-foundation-executive-director-and-chief-technology-officer/1861' target='_blank'>announced the appointments of the Executive Director and Chief Technology Officer.</a>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
title: Haskell Foundation March Update
3+
---
4+
5+
Andrew Boardman posted the <a href='https://discourse.haskell.org/t/haskell-foundation-update-2021-03-19/2152' target='_blank'>March Foundation update.</a>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
title: Haskell Foundation April Update
3+
---
4+
5+
Andrew Boardman posted the <a href='https://discourse.haskell.org/t/haskell-foundation-april-update/2445' target='_blank'>April Foundation update.</a>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
title: Haskell Foundation May Update
3+
---
4+
5+
Andrew Boardman posted the <a href='https://discourse.haskell.org/t/haskell-foundation-may-update/2567' target='_blank'>May Foundation update.</a>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
title: Haskell Foundation June Update
3+
---
4+
5+
Andrew Boardman posted the <a href='https://discourse.haskell.org/t/haskell-foundation-june-update/2722' target='_blank'>June Foundation update.</a>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
title: Haskell Foundation July Update
3+
---
4+
5+
Andrew Boardman posted the <a href='https://discourse.haskell.org/t/haskell-foundation-july-update/2812' target='_blank'>July Foundation update.</a>

site.hs

+112-53
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
1-
{-# Language DeriveGeneric #-}
21
{-# Language ScopedTypeVariables #-}
32
{-# Language OverloadedStrings #-}
4-
{-# Language TemplateHaskell #-}
3+
{-# Language ViewPatterns #-}
54

65
import Hakyll
76
import Control.Monad (filterM)
87
import Data.List (sortOn)
98
import Data.Ord (comparing)
109

11-
config :: Configuration
12-
config = defaultConfiguration
13-
10+
--------------------------------------------------------------------------------------------------------
11+
-- MAIN GENERATION -------------------------------------------------------------------------------------
12+
--------------------------------------------------------------------------------------------------------
1413
main :: IO ()
15-
main = hakyllWith config $ do
14+
main = hakyll $ do
15+
-- statics ---------------------------------------------------------------------------------------------
1616
match "assets/css/main.css" $ do
1717
route idRoute
1818
compile compressCssCompiler
@@ -21,88 +21,147 @@ main = hakyllWith config $ do
2121
route idRoute
2222
compile copyFileCompiler
2323

24+
-- home ------------------------------------------------------------------------------------------------
2425
match "index.html" $ do
2526
route idRoute
2627
compile $ do
27-
sponsors <- sponsorsCtx defaultContext . sortOn itemIdentifier <$> loadAll "donations/sponsors/*.markdown"
28+
sponsors <- sponsorsCtx . sortOn itemIdentifier <$> loadAll "donations/sponsors/*.markdown"
2829
getResourceBody
2930
>>= applyAsTemplate sponsors
3031
>>= loadAndApplyTemplate "templates/boilerplate.html" sponsors
3132
>>= relativizeUrls
3233

33-
match "affiliates/*.markdown" $ compile pandocCompiler
34-
34+
-- sponsors --------------------------------------------------------------------------------------------
3535
match "donations/sponsors/*.markdown" $ compile pandocCompiler
3636

37-
match "affiliates/index.html" $ do
37+
-- affiliates ------------------------------------------------------------------------------------------
38+
match "affiliates/*.markdown" $ compile pandocCompiler
39+
create ["affiliates/index.html"] $ do
3840
route idRoute
3941
compile $ do
40-
affils <- affiliatesCtx . sortOn itemIdentifier <$> loadAll "affiliates/*.markdown"
41-
sponsors <- sponsorsCtx affils . sortOn itemIdentifier <$> loadAll "donations/sponsors/*.markdown"
42+
sponsors <- sponsorsCtx . sortOn itemIdentifier <$> loadAll "donations/sponsors/*.markdown"
43+
ctx <- affiliatesCtx . sortOn itemIdentifier <$> loadAll "affiliates/*.markdown"
4244

43-
getResourceBody
44-
>>= applyAsTemplate sponsors
45-
>>= loadAndApplyTemplate "templates/boilerplate.html" sponsors
45+
makeItem ""
46+
>>= loadAndApplyTemplate "templates/affiliates/list.html" ctx
47+
>>= loadAndApplyTemplate "templates/boilerplate.html" sponsors
4648
>>= relativizeUrls
4749

48-
match "**/index.html" $ do
50+
-- projects --------------------------------------------------------------------------------------------
51+
match "projects/*.markdown" $ compile pandocCompiler
52+
create ["projects/index.html"] $ do
4953
route idRoute
5054
compile $ do
51-
sponsors <- sponsorsCtx defaultContext . sortOn itemIdentifier <$> loadAll "donations/sponsors/*.markdown"
52-
getResourceBody
53-
>>= applyAsTemplate sponsors
54-
>>= loadAndApplyTemplate "templates/boilerplate.html" sponsors
55+
sponsors <- sponsorsCtx . sortOn itemIdentifier <$> loadAll "donations/sponsors/*.markdown"
56+
ctx <- projectsCtx . sortOn itemIdentifier <$> loadAll "projects/*.markdown"
57+
58+
makeItem ""
59+
>>= loadAndApplyTemplate "templates/projects/list.html" ctx
60+
>>= loadAndApplyTemplate "templates/boilerplate.html" sponsors
5561
>>= relativizeUrls
5662

57-
match "projects/*.markdown" $ compile pandocCompiler
63+
-- news ------------------------------------------------------------------------------------------------
64+
match "news/**.markdown" $ compile pandocCompiler
65+
categories <- buildCategories "news/**.markdown" (fromCapture "news/categories/**.html")
5866

59-
create ["projects/index.html"] $ do
67+
tagsRules categories $ \category catId -> compile $ do
68+
news <- recentFirst =<< loadAll catId
69+
let ctx =
70+
listField "news" (newsWithCategoriesCtx categories) (pure news) <>
71+
dateField "category" "%B %e, %Y" <>
72+
defaultContext
73+
74+
makeItem ""
75+
>>= loadAndApplyTemplate "templates/news/tile.html" ctx
76+
>>= relativizeUrls
77+
78+
create ["news/index.html"] $ do
6079
route idRoute
6180
compile $ do
62-
ctx <- projectsCtx . sortOn itemIdentifier <$> loadAll "projects/*.markdown"
63-
sponsors <- sponsorsCtx ctx . sortOn itemIdentifier <$> loadAll "donations/sponsors/*.markdown"
81+
sponsors <- sponsorsCtx . sortOn itemIdentifier <$> loadAll "donations/sponsors/*.markdown"
82+
newsWithCategories <- recentFirst =<< loadAll "news/categories/**.html"
83+
84+
let ctx =
85+
listField "categories" defaultContext (return newsWithCategories) <>
86+
defaultContext
6487

6588
makeItem ""
66-
>>= loadAndApplyTemplate "templates/projects/list.html" sponsors
89+
>>= loadAndApplyTemplate "templates/news/list.html" ctx
6790
>>= loadAndApplyTemplate "templates/boilerplate.html" sponsors
6891
>>= relativizeUrls
6992

93+
-- templates -------------------------------------------------------------------------------------------
94+
match "templates/*" $ compile templateBodyCompiler
7095
match "templates/**" $ compile templateBodyCompiler
7196

97+
98+
--------------------------------------------------------------------------------------------------------
99+
-- CONTEXT ---------------------------------------------------------------------------------------------
100+
--------------------------------------------------------------------------------------------------------
101+
102+
-- sponsors --------------------------------------------------------------------------------------------
103+
-- | Partition sponsors into by level: monad, applicative, and functor
104+
-- Sponsors are listed in the footer template, which means we need this
105+
-- context for most pages.
106+
sponsorsCtx :: [Item String] -> Context String
107+
sponsorsCtx sponsors =
108+
listField "monads" defaultContext (ofMetadataField "level" "Monad" sponsors) <>
109+
listField "applicatives" defaultContext (ofMetadataField "level" "Applicative" sponsors) <>
110+
listField "functors" defaultContext (ofMetadataField "level" "Functor" sponsors) <>
111+
defaultContext
112+
113+
-- affiliates ------------------------------------------------------------------------------------------
72114
-- | Partition affiliates into affiliates and pending
73115
affiliatesCtx :: [Item String] -> Context String
74-
affiliatesCtx tuts =
75-
listField "affiliated" defaultContext (ofStatus "affiliated" tuts) <>
76-
listField "pending" defaultContext (ofStatus "pending" tuts) <>
116+
affiliatesCtx affiliates =
117+
listField "affiliated" defaultContext (ofMetadataField "status" "affiliated" affiliates) <>
118+
listField "pending" defaultContext (ofMetadataField "status" "pending" affiliates) <>
77119
defaultContext
78120

121+
-- projects --------------------------------------------------------------------------------------------
79122
-- | Partition projects into : Ideation | Proposed | In Progress | Completed
80123
projectsCtx :: [Item String] -> Context String
81-
projectsCtx p =
82-
listField "ideas" defaultContext (ofStatus "ideation" p) <>
83-
listField "proposals" defaultContext (ofStatus "proposed" p) <>
84-
listField "inprogress" defaultContext (ofStatus "inprogress" p) <>
85-
listField "completed" defaultContext (ofStatus "completed" p) <>
124+
projectsCtx projects =
125+
listField "ideas" defaultContext (ofMetadataField "status" "ideation" projects) <>
126+
listField "proposals" defaultContext (ofMetadataField "status" "proposed" projects) <>
127+
listField "inprogress" defaultContext (ofMetadataField "status" "inprogress" projects) <>
128+
listField "completed" defaultContext (ofMetadataField "status" "completed" projects) <>
86129
defaultContext
87130

88-
ofStatus :: String -> [Item String] -> Compiler [Item String]
89-
ofStatus v = filterM (\item -> do
90-
mbStatus <- getMetadataField (itemIdentifier item) "status"
91-
return $ Just v == mbStatus
131+
-- news ------------------------------------------------------------------------------------------------
132+
-- | build group of news inside date of publishing (category)
133+
newsWithCategoriesCtx :: Tags -> Context String
134+
newsWithCategoriesCtx categories =
135+
listField "categories" categoryCtx getAllCategories <>
136+
defaultContext
137+
where
138+
getAllCategories :: Compiler [Item (String, [Identifier])]
139+
getAllCategories = pure . map buildItemFromTag $ tagsMap categories
140+
where
141+
buildItemFromTag :: (String, [Identifier]) -> Item (String, [Identifier])
142+
buildItemFromTag c@(name, _) = Item (tagsMakeId categories name) c
143+
categoryCtx :: Context (String, [Identifier])
144+
categoryCtx =
145+
listFieldWith "news" newsCtx getNews <>
146+
metadataField <>
147+
urlField "url" <>
148+
pathField "path" <>
149+
titleField "title" <>
150+
missingField
151+
where
152+
getNews:: Item (String, [Identifier]) -> Compiler [Item String]
153+
getNews (itemBody -> (_, ids)) = mapM load ids
154+
newsCtx :: Context String
155+
newsCtx = newsWithCategoriesCtx categories
156+
157+
158+
--------------------------------------------------------------------------------------------------------
159+
-- UTILS -----------------------------------------------------------------------------------------------
160+
--------------------------------------------------------------------------------------------------------
161+
162+
-- | filter list of item string based on the given value to match on the given metadata field
163+
ofMetadataField :: String -> String -> [Item String] -> Compiler [Item String]
164+
ofMetadataField field value = filterM (\item -> do
165+
mbStatus <- getMetadataField (itemIdentifier item) field
166+
return $ Just value == mbStatus
92167
)
93-
94-
-- | Partition sponsors into by level: monad, applicative, and functor
95-
-- Sponsors are listed in the footer template, which means we need this
96-
-- context for most pages. The first argument is another context so
97-
-- we can compose them together, and the usage site can pass in the
98-
-- context it is in.
99-
sponsorsCtx :: Context String -> [Item String] -> Context String
100-
sponsorsCtx ctx sponsors =
101-
listField "monads" defaultContext (ofLevel "Monad") <>
102-
listField "applicatives" defaultContext (ofLevel "Applicative") <>
103-
listField "functors" defaultContext (ofLevel "Functor") <>
104-
ctx
105-
where
106-
ofLevel ty = filterM (\item -> do
107-
mbLevel <- getMetadataField (itemIdentifier item) "level"
108-
return $ Just ty == mbLevel) sponsors

0 commit comments

Comments
 (0)