@sphido/sitemap 3.0.0 → 3.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/sitemap.d.ts CHANGED
@@ -1,12 +1,12 @@
1
1
  interface SitemapParams {
2
- url?: string;
2
+ url: string;
3
3
  date?: Date;
4
4
  priority?: number;
5
5
  changefreq?: "daily" | "weekly" | "monthly" | "yearly";
6
6
  }
7
7
  export type Sitemap = {
8
8
  add: (params: SitemapParams) => void;
9
- end: () => void;
9
+ end: () => Promise<void>;
10
10
  };
11
11
  /**
12
12
  * Generate XML sitemap
@@ -1 +1 @@
1
- {"version":3,"file":"sitemap.d.ts","sourceRoot":"","sources":["../lib/sitemap.ts"],"names":[],"mappings":"AAcA,UAAU,aAAa;IACtB,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,IAAI,CAAC,EAAE,IAAI,CAAC;IACZ,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,UAAU,CAAC,EAAE,OAAO,GAAG,QAAQ,GAAG,SAAS,GAAG,QAAQ,CAAC;CACvD;AAED,MAAM,MAAM,OAAO,GAAG;IACrB,GAAG,EAAE,CAAC,MAAM,EAAE,aAAa,KAAK,IAAI,CAAC;IACrC,GAAG,EAAE,MAAM,IAAI,CAAC;CAChB,CAAC;AAEF;;;GAGG;AACH,wBAAsB,aAAa,CAAC,IAAI,SAAuB,GAAG,OAAO,CAAC,OAAO,CAAC,CA+BjF"}
1
+ {"version":3,"file":"sitemap.d.ts","sourceRoot":"","sources":["../lib/sitemap.ts"],"names":[],"mappings":"AAcA,UAAU,aAAa;IACtB,GAAG,EAAE,MAAM,CAAC;IACZ,IAAI,CAAC,EAAE,IAAI,CAAC;IACZ,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,UAAU,CAAC,EAAE,OAAO,GAAG,QAAQ,GAAG,SAAS,GAAG,QAAQ,CAAC;CACvD;AAED,MAAM,MAAM,OAAO,GAAG;IACrB,GAAG,EAAE,CAAC,MAAM,EAAE,aAAa,KAAK,IAAI,CAAC;IACrC,GAAG,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC;CACzB,CAAC;AAEF;;;GAGG;AACH,wBAAsB,aAAa,CAAC,IAAI,SAAuB,GAAG,OAAO,CAAC,OAAO,CAAC,CAmCjF"}
package/dist/sitemap.js CHANGED
@@ -25,20 +25,24 @@ export async function createSitemap(file = "public/sitemap.xml") {
25
25
  }
26
26
  // Create stream
27
27
  const sitemap = createWriteStream(file, { flags: "a" });
28
- sitemap.write('<?xml version="1.0" encoding="UTF-8"?>\r\n');
29
- sitemap.write('<urlset xmlns="https://www.sitemaps.org/schemas/sitemap/0.9">\r\n');
28
+ sitemap.write('<?xml version="1.0" encoding="UTF-8"?>\n');
29
+ sitemap.write('<urlset xmlns="https://www.sitemaps.org/schemas/sitemap/0.9">\n');
30
30
  return {
31
- add({ url, date = new Date(), priority = 0.5, changefreq = "monthly" } = {}) {
32
- sitemap.write("\t<url>\r\n");
33
- sitemap.write(`\t\t<loc>${escapeXml(String(url))}</loc>\r\n`);
34
- sitemap.write(`\t\t<lastmod>${date.toISOString()}</lastmod>\r\n`);
35
- sitemap.write(`\t\t<priority>${priority}</priority>\r\n`);
36
- sitemap.write(`\t\t<changefreq>${changefreq}</changefreq>\r\n`);
37
- sitemap.write("\t</url>\r\n");
31
+ add({ url, date = new Date(), priority = 0.5, changefreq = "monthly" }) {
32
+ sitemap.write("\t<url>\n");
33
+ sitemap.write(`\t\t<loc>${escapeXml(String(url))}</loc>\n`);
34
+ sitemap.write(`\t\t<lastmod>${date.toISOString()}</lastmod>\n`);
35
+ sitemap.write(`\t\t<priority>${priority}</priority>\n`);
36
+ sitemap.write(`\t\t<changefreq>${changefreq}</changefreq>\n`);
37
+ sitemap.write("\t</url>\n");
38
38
  },
39
39
  end() {
40
- sitemap.write("</urlset>");
41
- sitemap.end();
40
+ return new Promise((resolve, reject) => {
41
+ sitemap.write("</urlset>");
42
+ sitemap.end();
43
+ sitemap.on("finish", resolve);
44
+ sitemap.on("error", reject);
45
+ });
42
46
  },
43
47
  };
44
48
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sphido/sitemap",
3
- "version": "3.0.0",
3
+ "version": "3.0.1",
4
4
  "type": "module",
5
5
  "author": "Roman Ožana <roman@ozana.cz> (https://ozana.cz)",
6
6
  "homepage": "https://sphido.cz",
package/readme.md CHANGED
@@ -1,5 +1,7 @@
1
1
  # @sphido/sitemap
2
2
 
3
+ Generates [XML sitemap](https://www.sitemaps.org/protocol.html) files for Sphido CMS.
4
+
3
5
  ## Install
4
6
 
5
7
  ```bash
@@ -15,7 +17,6 @@ import { dirname, relative, join } from 'node:path';
15
17
  import { getPages, allPages } from '@sphido/core';
16
18
  import slugify from '@sindresorhus/slugify';
17
19
  import { createSitemap } from '@sphido/sitemap';
18
- import got from 'got';
19
20
 
20
21
  const pages = await getPages({path: 'content'});
21
22
  const map = await createSitemap('sitemap.xml');
@@ -36,7 +37,7 @@ for (const page of await allPages(pages)) {
36
37
  map.add(page);
37
38
  }
38
39
 
39
- map.end();
40
+ await map.end();
40
41
  ```
41
42
 
42
43
  ## Source code