Added sitemap.xml

Generation is done and the end of app.hs. Care should be taken when
adding pages: they must be declared in the sitemap's context.
This commit is contained in:
Etienne Werly 2023-06-19 00:16:25 +02:00
parent f6a38efa1c
commit 2602d815e0
8 changed files with 81 additions and 2 deletions

View file

@ -19,6 +19,13 @@ and this project adheres to the
* Add font subsetting (or svg icons support / fonts)
* Add images utils such as conversion to png, avif and other formats (see hip and JuicyPixels)
## 0.1.0.0 - YYYY-MM-DD
## 0.1.0.0 - 2023-06-18
* Added colours and palettes support (with colour package back-end)
* Component structure
* Kit populated with
* Constants: Breakpoints, Spacing, Colors
* Atoms: Fonts, Stylesheet, BreakpointQueries, Buttons, Containers
* Molecules: Default css, Profile header pieces
* Organisms: HTML head, Profile header
* Templates: Index, Blog post

View file

@ -6,7 +6,7 @@ import Data.Hashable
import Data.String
import Hakyll
import Text.Blaze.Html5 ( Html )
import Text.Blaze.Html
import Components
import Core.Compilers
@ -55,3 +55,12 @@ main = hakyll $ do
match "assets/img/*" $ do
route idRoute
compile copyFileCompiler
create ["sitemap.xml"] $ do
route idRoute
compile $ do
posts <- recentFirst =<< loadAll "posts/*.md"
let pages = posts
sitemapCtx = listField "pages" defaultContext (return pages)
makeItem ""
>>= loadAndApplyTemplate "src/Kit/Templates/Sitemap.hs" sitemapCtx

View file

@ -45,8 +45,10 @@ library
Kit.Organisms.ProfileHeader
Kit.Templates.Index
Kit.Templates.Post
Kit.Templates.Sitemap
Routes
Utils.Clay
Utils.XML
other-modules:
Paths_etienne_moqueur
hs-source-dirs:
@ -59,6 +61,7 @@ library
, array
, base >=4.7 && <5
, blaze-html
, blaze-markup
, clay
, colour
, containers
@ -82,6 +85,7 @@ executable etienne-moqueur-exe
, array
, base >=4.7 && <5
, blaze-html
, blaze-markup
, clay
, colour
, containers
@ -107,6 +111,7 @@ test-suite etienne-moqueur-test
, array
, base >=4.7 && <5
, blaze-html
, blaze-markup
, clay
, colour
, containers

View file

@ -24,6 +24,7 @@ dependencies:
- clay
- text
- blaze-html
- blaze-markup
- array
- colour
- ansi-terminal

View file

@ -1,6 +1,7 @@
---
title: 'Building my new website: goals and dreams'
description: 'A first post to describe what I want to achieve, and the how and why.'
updated: 2023-06-19
---
This first post has two objectives:

View file

@ -3,6 +3,7 @@ module Info
, description
, bio
, mail
, root
) where
author, description, bio, mail :: String
@ -15,3 +16,5 @@ bio =
"Self taught in computer science, using Linux since 2013 and self hosting since 2020, I am taking a new turn to web development after a start as a mathematics teacher."
mail = "etienne@moqueur.chat"
root = "https://etienne.moqueur.chat"

View file

@ -0,0 +1,21 @@
module Kit.Templates.Sitemap where
import Core.Render
import Info
import Text.Blaze
import Utils.XML
sitemapTemplate :: Xml
sitemapTemplate = do
xml
urlset ! xmlns "http://www.sitemaps.org/schemas/sitemap/0.9" $ do
url $ do
loc $ toMarkup root
"$for(pages)$"
url $ do
loc $ toMarkup root <> "$url$"
lastmod "$if(updated)$$updated$$else$$if(date)$$date$$endif$$endif$"
"$endfor$"
main :: IO ()
main = print sitemapTemplate

32
src/Utils/XML.hs Normal file
View file

@ -0,0 +1,32 @@
module Utils.XML
( Xml
, xml
, urlset
, url
, loc
, lastmod
, xmlns
) where
import Text.Blaze
import Text.Blaze.Internal
type Xml = Markup
xml :: Xml
xml = preEscapedText "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
urlset :: Xml -> Xml
urlset = customParent "urlset"
url :: Xml -> Xml
url = customParent "url"
loc :: Xml -> Xml
loc = customParent "loc"
lastmod :: Xml -> Xml
lastmod = customParent "lastmod"
xmlns :: AttributeValue -> Attribute
xmlns = customAttribute "xmlns"