-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathrobots.ts
40 lines (36 loc) · 1.21 KB
/
robots.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
import {DateTime} from "luxon";
import {books} from "./books";
const PREFIX = `<?xml version="1.0" encoding="UTF-8"?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">`;
const SUFFIX = "</urlset>";
export class Sitemap {
constructor(private readonly baseUrl: string) {}
private pageXml(url: string): string {
const lastmod = DateTime.now().startOf("month").toISODate();
return `<url>
<loc>${this.baseUrl}/${url}</loc>
<lastmod>${lastmod}</lastmod>
</url>`;
}
generate(): string {
const sections = [PREFIX];
for (const [name, book] of Object.entries(books.byCanonicalName)) {
const canonicalName = books.canonicalUrlName(name);
if (book.bookType() === "Siddur") {
sections.push(this.pageXml(canonicalName));
} else {
for (const section of book.sections) {
sections.push(this.pageXml(`${canonicalName}/${section}`));
}
}
}
sections.push(this.pageXml("daf-yomi"));
sections.push(this.pageXml("mishna-yomit"));
sections.push(this.pageXml("rambam-yomi"));
if (sections.length > 50_000) {
throw new Error("Only 50k entries are allowed per sitemap");
}
sections.push(SUFFIX);
return sections.join("\n");
}
}