From 31fb7749b7af6d8630d08f1b6b231aa233ae3bd2 Mon Sep 17 00:00:00 2001 From: jamie Date: Fri, 20 Jun 2025 21:03:21 +0100 Subject: feat: prettify urls --- pages/playlists.html | 59 ++++++++++++++++++++++++++++++++++++++++++++++++++ playlists.html | 59 -------------------------------------------------- site.hs | 55 ++++++++++++++++++++++++++++++++++++++++------ skiletro.cabal | 1 + templates/default.html | 6 ++--- templates/post.html | 4 ++-- 6 files changed, 113 insertions(+), 71 deletions(-) create mode 100644 pages/playlists.html delete mode 100644 playlists.html diff --git a/pages/playlists.html b/pages/playlists.html new file mode 100644 index 0000000..b11cfad --- /dev/null +++ b/pages/playlists.html @@ -0,0 +1,59 @@ +--- +title: Playlists +--- + +

Consider Yourself Drunk

+ + + A chill DnB-ish Playlist + + +

Lofi Refined

+ + + A smaller set of lofi songs, more carefully picked + + +

Chilled Out

+ + + Mix of chiller DnB and stuff like that + + +

Pills

+ + + DnB, Jump-up, all that good stuff + + +

More Playlists

+

+ More playlists can be found on my + Spotify profile! I try + and add new songs to my playlists as much as I can, and I'm always creating + new playlists too! +

diff --git a/playlists.html b/playlists.html deleted file mode 100644 index b11cfad..0000000 --- a/playlists.html +++ /dev/null @@ -1,59 +0,0 @@ ---- -title: Playlists ---- - -

Consider Yourself Drunk

- - - A chill DnB-ish Playlist - - -

Lofi Refined

- - - A smaller set of lofi songs, more carefully picked - - -

Chilled Out

- - - Mix of chiller DnB and stuff like that - - -

Pills

- - - DnB, Jump-up, all that good stuff - - -

More Playlists

-

- More playlists can be found on my - Spotify profile! I try - and add new songs to my playlists as much as I can, and I'm always creating - new playlists too! -

diff --git a/site.hs b/site.hs index dffdd47..dfc2cc7 100644 --- a/site.hs +++ b/site.hs @@ -1,9 +1,12 @@ -------------------------------------------------------------------------------- {-# LANGUAGE OverloadedStrings #-} -import Data.Monoid (mappend) +import Data.List (isInfixOf, sortBy) +import Data.Monoid (mappend) import Hakyll -import Hakyll.Web.Sass (sassCompiler) +import Hakyll.Web.Sass (sassCompiler) +import System.FilePath.Posix (splitFileName, takeBaseName, + takeDirectory, ()) -------------------------------------------------------------------------------- main :: IO () @@ -21,24 +24,34 @@ main = hakyll $ do let compressCssItem = fmap compressCss compile (compressCssItem <$> sassCompiler) - match (fromList ["playlists.html", "404.html"]) $ do - route $ setExtension "html" + match "404.html" $ do + route idRoute compile $ pandocCompiler >>= loadAndApplyTemplate "templates/default.html" defaultContext >>= relativizeUrls + >>= removeIndexHtml + + match "pages/*.html" $ do + route prettyRoute + compile $ + pandocCompiler + >>= loadAndApplyTemplate "templates/default.html" defaultContext + >>= relativizeUrls + >>= removeIndexHtml match "posts/*" $ do - route $ setExtension "html" + route prettyRoute compile $ pandocCompiler >>= loadAndApplyTemplate "templates/post.html" postCtx >>= saveSnapshot "content" >>= loadAndApplyTemplate "templates/default.html" postCtx >>= relativizeUrls + >>= removeIndexHtml create ["archive.html"] $ do - route idRoute + route prettyRoute compile $ do posts <- recentFirst =<< loadAll "posts/*" let archiveCtx = @@ -50,6 +63,7 @@ main = hakyll $ do >>= loadAndApplyTemplate "templates/archive.html" archiveCtx >>= loadAndApplyTemplate "templates/default.html" archiveCtx >>= relativizeUrls + >>= removeIndexHtml create ["atom.xml"] $ do route idRoute @@ -81,6 +95,7 @@ main = hakyll $ do >>= applyAsTemplate indexCtx >>= loadAndApplyTemplate "templates/default.html" indexCtx >>= relativizeUrls + >>= removeIndexHtml match "templates/*" $ compile templateBodyCompiler @@ -95,11 +110,37 @@ feedConfiguration = feedRoot = "https://skiletro.com" } +-------------------------------------------------------------------------------- + +prettyRoute :: Routes +prettyRoute = customRoute createIndexRoute + where + createIndexRoute ident = + takeDirectory p takeBaseName p "index.html" + where + p = toFilePath ident + +removeIndexHtml :: Item String -> Compiler (Item String) +removeIndexHtml item = return $ fmap (withUrls removeIndexStr) item + where + removeIndexStr :: String -> String + removeIndexStr url = case splitFileName url of + (dir, "index.html") | isLocal dir -> dir + _ -> url + where + isLocal uri = not (isInfixOf "://" uri) + +-------------------------------------------------------------------------------- + postCtx :: Context String -postCtx = hDateCtx <> cDateCtx <> defaultContext +postCtx = hDateCtx <> cDateCtx <> modifiedCtx <> defaultContext hDateCtx :: Context String hDateCtx = dateField "hdate" "%B %e, %Y" cDateCtx :: Context String cDateCtx = dateField "cdate" "%Y-%m-%d" + +modifiedCtx :: Context String +modifiedCtx = modificationTimeField "modified" "%B %e, %Y" +-------------------------------------------------------------------------------- diff --git a/skiletro.cabal b/skiletro.cabal index 36dda08..2eb185b 100644 --- a/skiletro.cabal +++ b/skiletro.cabal @@ -6,6 +6,7 @@ cabal-version: >= 1.10 executable site main-is: site.hs build-depends: base == 4.* + , filepath , hakyll == 4.16.* , hakyll-sass == 0.2.* ghc-options: -threaded -rtsopts -with-rtsopts=-N diff --git a/templates/default.html b/templates/default.html index af8ada0..3cab4b4 100644 --- a/templates/default.html +++ b/templates/default.html @@ -2,7 +2,7 @@ - $title$ | skiletro + $title$ | Skiletro @@ -74,8 +74,8 @@ >
Home - Archive - Playlists + Archive + Playlists
diff --git a/templates/post.html b/templates/post.html index 6d94c31..cfcd59b 100644 --- a/templates/post.html +++ b/templates/post.html @@ -1,6 +1,6 @@
- Posted on By - + Posted on by + . Last modified $modified$.

-- cgit v1.3.1