cryogen-core/src/cryogen_core/sitemap.clj

29 lines
880 B
Clojure
Raw Normal View History

2014-12-05 15:56:40 +00:00
(ns cryogen-core.sitemap
2014-12-04 16:38:48 +00:00
(:require [clojure.xml :refer [emit]]
2017-01-16 07:37:19 +00:00
[cryogen-core.io :as cryogen-io])
2014-12-04 16:38:48 +00:00
(: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)))
2015-09-14 10:06:35 +00:00
(defn loc [^java.io.File f]
2014-12-04 16:38:48 +00:00
(-> f (.getAbsolutePath) (.split "resources/public/") second))
(defn generate [site-url ignored-files]
2014-12-04 16:38:48 +00:00
(with-out-str
(emit
2019-12-20 14:55:53 +00:00
{:tag :urlset
:attrs {:xmlns "http://www.sitemaps.org/schemas/sitemap/0.9"}
:content
(for [^java.io.File f (cryogen-io/find-assets "public" ".html" ignored-files)]
{:tag :url
:content
[{:tag :loc
:content [(str site-url (loc f))]}
{:tag :lastmod
:content [(-> f (.lastModified) (Date.) format-date)]}]})})))