<commit_before>{-# LANGUAGE OverloadedStrings #-}

module Site.Sitemap
  ( sitemap
  ) where

import Blaze.ByteString.Builder (toLazyByteString)
import qualified Data.Text as T
import Snap.Core (writeLBS)
import Text.XmlHtml
  ( Document(..)
  , Encoding(..)
  , Node(..)
  , render
  )

import Application (AppHandler)
import Config
import Database (getPosts, getTags)
import Types

sitemap :: AppHandler ()
sitemap = do
  posts <- getPosts Nothing 0 1000000
  tags <- getTags
  writeLBS $ toLazyByteString $ render $ sitemapDocument posts tags

sitemapDocument :: [Post] -> [Tag] -> Document
sitemapDocument posts tags = XmlDocument UTF8 Nothing
  [ Element "urlset" [("xmlns", "http://www.sitemaps.org/schemas/sitemap/0.9")] $
    [ writeUrl (Just "1.0") "/"
    , writeUrl (Just "1.0") "/about"
    , writeUrl (Just "0.7") "/movies"
    , writeUrl Nothing "/shoutbox"
    ] ++ (map (writeUrl (Just "1.0") . T.append "/post/" . postUrl) posts)<commit_msg>Add archive page to sitemap<commit_after>{-# LANGUAGE OverloadedStrings #-}

module Site.Sitemap
  ( sitemap
  ) where

import Blaze.ByteString.Builder (toLazyByteString)
import qualified Data.Text as T
import Snap.Core (writeLBS)
import Text.XmlHtml
  ( Document(..)
  , Encoding(..)
  , Node(..)
  , render
  )

import Application (AppHandler)
import Config
import Database (getPosts, getTags)
import Types

sitemap :: AppHandler ()
sitemap = do
  posts <- getPosts Nothing 0 1000000
  tags <- getTags
  writeLBS $ toLazyByteString $ render $ sitemapDocument posts tags

sitemapDocument :: [Post] -> [Tag] -> Document
sitemapDocument posts tags = XmlDocument UTF8 Nothing
  [ Element "urlset" [("xmlns", "http://www.sitemaps.org/schemas/sitemap/0.9")] $
    [ writeUrl (Just "0.5") "/"
    , writeUrl (Just "1.0") "/about"
    , writeUrl (Just "0.7") "/movies"
    , writeUrl (Just "0.1") "/archive"
    , writeUrl Nothing "/shoutbox"
    ] ++ (map (writeUrl (Just "1.0") . T.append "/post/" . postUrl) posts)
{'fraction_non_alphanumeric': 0.1447435246317928, 'fraction_numerical': 0.02031488065007618, 'mean_word_length': 3.6462264150943398, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 2}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1415153', 'n_tokens_mistral': 716, 'n_tokens_neox': 682, 'n_words': 183}