diff --git a/build/Site.hs b/build/Site.hs index 7e774fa..68fc154 100644 --- a/build/Site.hs +++ b/build/Site.hs @@ -4,7 +4,7 @@ module Site (rules) where import Control.Monad (forM, forM_, when) import Data.Char (isSpace, toUpper) -import Data.List (groupBy, isPrefixOf, sort, sortBy) +import Data.List (groupBy, isPrefixOf, sort, sortBy, stripPrefix) import Data.Map.Strict (Map) import Data.Maybe (catMaybes, fromMaybe, listToMaybe) import Data.Ord (Down (..), comparing) @@ -383,13 +383,14 @@ rules = do fname = takeFileName fp isIndex = fname == "index.md" isDraft = "content/drafts/essays/" `isPrefixOf` fp + stripContent = fromMaybe fp (stripPrefix "content/" fp) in case (isDraft, isIndex) of -- content/drafts/essays/slug/index.md → drafts/essays/slug/index.html - (True, True) -> replaceExtension (drop 8 fp) "html" + (True, True) -> replaceExtension stripContent "html" -- content/drafts/essays/foo.md → drafts/essays/foo.html (True, False) -> "drafts/essays/" ++ replaceExtension fname "html" -- content/essays/slug/index.md → essays/slug/index.html - (False, True) -> replaceExtension (drop 8 fp) "html" + (False, True) -> replaceExtension stripContent "html" -- content/essays/foo.md → essays/foo.html (False, False) -> "essays/" ++ replaceExtension fname "html" compile $ essayCompiler @@ -919,6 +920,49 @@ rules = do <> defaultContext renderAtom musicFeedConfig feedCtx compositions + -- --------------------------------------------------------------------------- + -- robots.txt — minimal, just points crawlers at the sitemap + -- --------------------------------------------------------------------------- + create ["robots.txt"] $ do + route idRoute + compile $ makeItem $ unlines + [ "User-agent: *" + , "Allow: /" + , "" + , "Sitemap: https://levineuwirth.org/sitemap.xml" + ] + + -- --------------------------------------------------------------------------- + -- sitemap.xml — every dated content page (essays, blog, poetry, fiction, + -- music). Standalone pages (about, colophon, etc.) are intentionally + -- omitted: they're reachable via the main nav, lack `date:` frontmatter, + -- and would force a fallback lastmod that misrepresents staleness. + -- --------------------------------------------------------------------------- + create ["sitemap.xml"] $ do + route idRoute + compile $ do + entries <- recentFirst + =<< loadAllSnapshots + ( ( allEssays + .||. "content/blog/*.md" + .||. "content/fiction/*.md" + .||. allPoetry + .||. "content/music/*/index.md" + ) + .&&. hasNoVersion + ) + "content" + let siteRoot = "https://levineuwirth.org" + sitemapItemCtx = + constField "root" siteRoot + <> dateField "lastmod" "%Y-%m-%d" + <> defaultContext + sitemapCtx = + constField "root" siteRoot + <> listField "entries" sitemapItemCtx (return entries) + makeItem ("" :: String) + >>= loadAndApplyTemplate "templates/sitemap.xml" sitemapCtx + -- --------------------------------------------------------------------------- -- Epistemic metadata extraction -- --------------------------------------------------------------------------- diff --git a/templates/sitemap.xml b/templates/sitemap.xml new file mode 100644 index 0000000..c398f72 --- /dev/null +++ b/templates/sitemap.xml @@ -0,0 +1,12 @@ + + + + $root$/ + +$for(entries)$ + + $root$$url$ +$if(lastmod)$ $lastmod$ +$endif$ +$endfor$ +