/
sitemap.clj
28 lines (24 loc) · 919 Bytes
/
sitemap.clj
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
(ns cryogen-core.sitemap
(:require [clojure.xml :refer [emit]]
[cryogen-core.io :as cryogen-io])
(:import java.util.Date))
;;generate sitemaps using the sitemap spec
;;http://www.sitemaps.org/protocol.html
(defn format-date [date]
(let [fmt (java.text.SimpleDateFormat. "yyyy-MM-dd")]
(.format fmt date)))
(defn loc [^java.io.File f]
(-> f (.getAbsolutePath) (.split (cryogen-io/path cryogen-io/public "/")) second))
(defn generate [site-url ignored-files]
(with-out-str
(emit
{:tag :urlset
:attrs {:xmlns "http://www.sitemaps.org/schemas/sitemap/0.9"}
:content
(for [^java.io.File f (cryogen-io/find-assets cryogen-io/public ".html" ignored-files)]
{:tag :url
:content
[{:tag :loc
:content [(str site-url (loc f))]}
{:tag :lastmod
:content [(-> f (.lastModified) (Date.) format-date)]}]})})))