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))
|
|
|
|
|
2014-12-27 07:38:25 +00:00
|
|
|
(defn generate [site-url ignored-files]
|
2014-12-04 16:38:48 +00:00
|
|
|
(with-out-str
|
|
|
|
(emit
|
|
|
|
{:tag :urlset
|
|
|
|
:attrs {:xmlns "http://www.sitemaps.org/schemas/sitemap/0.9"}
|
|
|
|
:content
|
2017-01-16 07:37:19 +00:00
|
|
|
(for [^java.io.File f (cryogen-io/find-assets "public" ".html" ignored-files)]
|
2014-12-04 16:38:48 +00:00
|
|
|
{:tag :url
|
|
|
|
:content
|
|
|
|
[{:tag :loc
|
|
|
|
:content [(str site-url (loc f))]}
|
|
|
|
{:tag :lastmod
|
|
|
|
:content [(-> f (.lastModified) (Date.) format-date)]}]})})))
|