clarusjs 0.12.0 → 0.13.0

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.
@@ -22,10 +22,34 @@ export function gitDates(root, dir) {
22
22
  }
23
23
  export function sitemapXml(siteUrl, base, pages) {
24
24
  const root = new URL(/^https?:\/\//i.test(base) ? new URL(base).pathname : base, siteUrl.replace(/\/?$/, '/'));
25
- const urls = pages.map(({ path, lastmod }) => {
25
+ const urls = pages.map(({ path, lastmod, images = [], alternates = [] }) => {
26
26
  const loc = new URL(`./${path.slice(1)}`, root).href;
27
27
  const date = lastmod === undefined ? '' : `<lastmod>${new Date(lastmod * 1000).toISOString().slice(0, 10)}</lastmod>`;
28
- return `<url><loc>${xml(loc)}</loc>${date}</url>\n`;
28
+ const pics = images.map((src) => `<image:image><image:loc>${xml(new URL(src, loc).href)}</image:loc></image:image>`).join('');
29
+ const alts = alternates.map((a) => `<xhtml:link rel="alternate" hreflang="${xml(a.hreflang)}" href="${xml(new URL(a.href, loc).href)}"/>`).join('');
30
+ return `<url><loc>${xml(loc)}</loc>${date}${alts}${pics}</url>\n`;
29
31
  });
30
- return `<?xml version="1.0" encoding="UTF-8"?>\n<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">\n${urls.join('')}</urlset>\n`;
32
+ const ns = (pages.some((p) => p.alternates?.length) ? ' xmlns:xhtml="http://www.w3.org/1999/xhtml"' : '') + (pages.some((p) => p.images?.length) ? ' xmlns:image="http://www.google.com/schemas/sitemap-image/1.1"' : '');
33
+ return `<?xml version="1.0" encoding="UTF-8"?>\n<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"${ns}>\n${urls.join('')}</urlset>\n`;
34
+ }
35
+ export function sitemapFiles(siteUrl, base, pages, max = 50_000, maxBytes = 52_428_800) {
36
+ const envelope = Buffer.byteLength(sitemapXml(siteUrl, base, [])) + 200;
37
+ const chunks = [[]];
38
+ let bytes = envelope;
39
+ for (const page of pages) {
40
+ const size = Buffer.byteLength(sitemapXml(siteUrl, base, [page])) - envelope + 200;
41
+ const chunk = chunks.at(-1);
42
+ if (chunk.length && (chunk.length >= max || bytes + size > maxBytes)) {
43
+ chunks.push([]);
44
+ bytes = envelope;
45
+ }
46
+ chunks.at(-1).push(page);
47
+ bytes += size;
48
+ }
49
+ if (chunks.length === 1)
50
+ return [{ file: 'sitemap.xml', xml: sitemapXml(siteUrl, base, pages) }];
51
+ const parts = chunks.map((chunk, i) => ({ file: `sitemap-${i + 1}.xml`, xml: sitemapXml(siteUrl, base, chunk) }));
52
+ const root = new URL(/^https?:\/\//i.test(base) ? new URL(base).pathname : base, siteUrl.replace(/\/?$/, '/'));
53
+ const entries = parts.map((p) => `<sitemap><loc>${xml(new URL(p.file, root).href)}</loc></sitemap>\n`).join('');
54
+ return [...parts, { file: 'sitemap.xml', xml: `<?xml version="1.0" encoding="UTF-8"?>\n<sitemapindex xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">\n${entries}</sitemapindex>\n` }];
31
55
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "clarusjs",
3
- "version": "0.12.0",
3
+ "version": "0.13.0",
4
4
  "description": "Clear, compiled views: templates compiled to server HTML, with JavaScript only for interactive islands. SSR, SSG and CSR from one component model, built on Vite.",
5
5
  "license": "MIT",
6
6
  "keywords": [
@@ -43,6 +43,10 @@
43
43
  "types": "./dist/compiler/index.d.ts",
44
44
  "default": "./dist/compiler/index.js"
45
45
  },
46
+ "./icons": {
47
+ "types": "./dist/icons.d.ts",
48
+ "default": "./dist/icons.js"
49
+ },
46
50
  "./runtime": {
47
51
  "types": "./dist/runtime/index.d.ts",
48
52
  "default": "./dist/runtime/index.js"