Skip to content

Commit

Permalink
Fix external post ordering
Browse files Browse the repository at this point in the history
  • Loading branch information
ldgrp committed Aug 19, 2023
1 parent fe207b0 commit 231d9f4
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 17 deletions.
5 changes: 5 additions & 0 deletions posts/external/2023-03-11-tax-cut.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
title: How big is my tax cut?
date: 2023-03-11
url: https://observablehq.com/@ldgrp/how-big-is-my-tax-cut
---
38 changes: 25 additions & 13 deletions site.hs
Original file line number Diff line number Diff line change
@@ -1,16 +1,13 @@
--------------------------------------------------------------------------------
{-# LANGUAGE OverloadedStrings #-}
import Data.Maybe (fromMaybe)
import Data.Monoid (mappend)
import Hakyll
import System.FilePath.Posix ((</>))

--------------------------------------------------------------------------------
main :: IO ()
main = hakyll $ do
match "fonts/*" $ do
route idRoute
compile copyFileCompiler

match "images/*" $ do
route idRoute
compile copyFileCompiler
Expand All @@ -35,6 +32,10 @@ main = hakyll $ do
>>= loadAndApplyTemplate "templates/post.html" ideaCtx
>>= loadAndApplyTemplate "templates/default.html" ideaCtx
>>= relativizeUrls

match "posts/external/*.md" $ do
route $ metadataRoute urlRoute
compile pandocCompiler

match "posts/*.md" $ do
route removeDateRoute
Expand Down Expand Up @@ -74,7 +75,6 @@ main = hakyll $ do

match "templates/*" $ compile templateBodyCompiler


--------------------------------------------------------------------------------
entryCtx :: String -> Context String
entryCtx entryType =
Expand All @@ -91,27 +91,39 @@ ideaCtx = entryCtx "idea"
recipeCtx :: Context String
recipeCtx = entryCtx "recipe"

--------------------------------------------------------------------------------
posts = do
x <- loadAll "posts/*.md"
y <- loadAll "posts/external/*.md"
pure (x ++ y)

ideas = loadAll "ideas/*.md"

--------------------------------------------------------------------------------
archiveCtx :: Context String
archiveCtx =
listField "posts" postCtx (recentFirst =<< loadAll "posts/*.md") `mappend`
listField "ideas" ideaCtx (recentFirst =<< loadAll "ideas/*.md") `mappend`
constField "title" "Archive" `mappend`
listField "posts" postCtx (recentFirst =<< posts) `mappend`
listField "ideas" ideaCtx (recentFirst =<< ideas) `mappend`
constField "title" "Archive" `mappend`
defaultContext

indexCtx :: Context String
indexCtx =
listField "posts" postCtx (recentFirst =<< loadAll "posts/*.md") `mappend`
listField "ideas" ideaCtx (recentFirst =<< loadAll "ideas/*.md") `mappend`
listField "posts" postCtx (recentFirst =<< posts) `mappend`
listField "ideas" ideaCtx (recentFirst =<< ideas) `mappend`
constField "title" "Leo Orpilla III" `mappend`
defaultContext

ideasCtx :: Context String
ideasCtx =
listField "ideas" ideaCtx (recentFirst =<< loadAll "ideas/*.md") `mappend`
listField "ideas" ideaCtx (recentFirst =<< ideas) `mappend`
constField "title" "Ideas" `mappend`
defaultContext


--------------------------------------------------------------------------------
removeDateRoute :: Routes
removeDateRoute =
composeRoutes (gsubRoute "[0-9]{4}-[0-9]{2}-[0-9]{2}-" $ const "") (setExtension "html")
composeRoutes (gsubRoute "[0-9]{4}-[0-9]{2}-[0-9]{2}-" $ const "") (setExtension "html")

urlRoute :: Metadata -> Routes
urlRoute = constRoute . fromMaybe "\\#" . lookupString "url"
4 changes: 0 additions & 4 deletions templates/post-list.html
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
<ul class="entry-list">
<li>
<div class="date">11 Mar 2023</div>
<a class="title" href="https://observablehq.com/@ldgrp/how-big-is-my-tax-cut">How big is my tax cut?</a>
</li>
$for(posts)$
<li>
<div class="date">$date$</div>
Expand Down

0 comments on commit 231d9f4

Please sign in to comment.