https://github.com/hashobject/sitemap
Clojure library for sitemap generation.
https://github.com/hashobject/sitemap
clojure clojure-library sitemap-generator
Last synced: 7 months ago
JSON representation
Clojure library for sitemap generation.
- Host: GitHub
- URL: https://github.com/hashobject/sitemap
- Owner: hashobject
- License: epl-1.0
- Created: 2013-05-31T17:02:32.000Z (over 12 years ago)
- Default Branch: master
- Last Pushed: 2019-02-25T01:48:25.000Z (almost 7 years ago)
- Last Synced: 2025-05-22T16:07:30.605Z (8 months ago)
- Topics: clojure, clojure-library, sitemap-generator
- Language: Clojure
- Homepage: http://os.hashobject.com/sitemap/
- Size: 42 KB
- Stars: 16
- Watchers: 1
- Forks: 6
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# sitemap
Clojure library for generating sitemaps.
[](https://travis-ci.org/hashobject/sitemap)
[](https://jarkeeper.com/hashobject/sitemap)
[](https://jarkeeper.com/hashobject/sitemap)
Sitemaps XML format described on [http://www.sitemaps.org/](http://www.sitemaps.org/protocol.html).
Sitemap library accepts Clojure list/vectore data sctructure and produces sitemap XML as string.
Optionally sitemap XML can be saved to file using provided path.
Input data structure should be in the following format:
```clojure
[
{:loc "http://hashobject.com/about"
:lastmod "2013-05-31"
:changefreq "monthly"
:priority "0.8"}
{:loc "http://hashobject.com/team"
:lastmod "2013-06-01"
:changefreq "monthly"
:priority "0.9"}]
```
So it should be sequence of hash maps. Each map should have following keys:
* loc - url to the page
* lastmod - date when page was modified in YYYY-MM-DD format
* changefreq - how often page content will be changed (daily, weekly, monthly, never)
* priority - what is the priority of this page on the site (from 0 to 1)
Note that only 'loc' key is mandatory.
Please refer to documentation for values' formats of each key.
## Install
```
[sitemap "0.4.0"]
```
## Usage
```clojure
user=> (use 'sitemap.core)
nil
user=> (generate-sitemap [{:loc "http://hashobject.com/about"
:lastmod "2013-05-31"
:changefreq "monthly"
:priority "0.8"}
{:loc "http://hashobject.com/team"
:lastmod "2013-06-01"
:changefreq "monthly"
:priority "0.9"}])
```
generates the following XML:
```xml
http://hashobject.com/about
2013-05-31
monthly
0.8
http://hashobject.com/team
2013-06-01
monthly
0.9
```
## Tips
We recommend you to validate your sitemap before submitting it to Google Webmaster tools.
You can use this library and there are also plenty of online validators.
## Validation
This library can validate the generated XML against [version 0.9](http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd) of the schema.
```clojure
(use 'sitemap.core)
(import 'java.io.File)
(->>
(generate-sitemap [{:loc "http://example.com/about"
:lastmod "2014-07-23"
:changefreq "monthly"
:priority "0.5"}])
(save-sitemap (File. "/tmp/sitemap.xml"))
(validate-sitemap)
(count)
(format "You have %d errors"))
; "You have 0 errors"
```
Validation errors are reported as a list of [SAXParseException](http://docs.oracle.com/javase/7/docs/api/org/xml/sax/SAXParseException.html):
```clojure
(->>
(generate-sitemap [{:loc "http://example.com/about"
:lastmod "2000-00-00"
:changefreq "monthly"
:priority "0.8"}])
(save-sitemap (File. "/tmp/sitemap-bad.xml"))
(validate-sitemap)
(map #(.getMessage %)))
;("cvc-datatype-valid.1.2.3: '2000-00-00' is not a valid value of union type 'lastmod'."
; "cvc-type.3.1.3: The value '2000-00-00' of element 'lastmod' is not valid.")
```
## Contributions
We love contributions. Please submit your pull requests.
## License
Copyright © 2013-2019 Hashobject Ltd (team@hashobject.com).
Distributed under the [Eclipse Public License](http://opensource.org/licenses/eclipse-1.0).