Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/mika-f/smxml

Create valid sitemap with builder pattern, written in TypeScript.
https://github.com/mika-f/smxml

Last synced: 4 days ago
JSON representation

Create valid sitemap with builder pattern, written in TypeScript.

Awesome Lists containing this project

README

        

# @natsuneko-laboratory/smxml

Create valid sitemap with builder pattern, written in TypeScript.

## Install

```bash
$ npm install @natsuneko-laboratory/smxml
$ yarn add @natsuneko-laboratory/smxml
$ pnpm add @natsuneko-laboratory/smxml
```

## Usage

```typescript
import { SitemapBuilder } from "@natsuneko-laboratory/smxml";

// create base builder
const base = SitemapBuilder.create("https://www.natsuneko.blog");

// create sitemap index
const index = base.asIndex().addLocation({ url: "/sitemap-0.xml" });

console.log(index.build());
// https://www.natsuneko.blog/sitemap-0.xml

console.log(index.build({ minified: false }));
/*
*
*
*
* https://www.natsuneko.blog/sitemap-0.xml
*
*
*/

// create sitemap index
const urls = base.asUrlSet().addUrl({
loc: "/categories",
lastMod: new Date(),
changeFreq: "daily",
priority: 0.7,
});

console.log(urls.build({ minified: false }));
/*
*
*
*
* https://www.natsuneko.blog/categories
* 2024-01-24T14:33:13.603Z
* daily
* 0.7
*
*
*/
```

## License

MIT by [@6jz](https://twitter.com/6jz)