| | |
| | | import { GlobalConfiguration } from "../../cfg" |
| | | import { getDate } from "../../components/Date" |
| | | import { escapeHTML } from "../../util/escape" |
| | | import { FilePath, FullSlug, SimpleSlug, simplifySlug } from "../../util/path" |
| | | import { FilePath, FullSlug, SimpleSlug, joinSegments, simplifySlug } from "../../util/path" |
| | | import { QuartzEmitterPlugin } from "../types" |
| | | import { toHtml } from "hast-util-to-html" |
| | | import path from "path" |
| | |
| | | function generateSiteMap(cfg: GlobalConfiguration, idx: ContentIndex): string { |
| | | const base = cfg.baseUrl ?? "" |
| | | const createURLEntry = (slug: SimpleSlug, content: ContentDetails): string => `<url> |
| | | <loc>https://${base}/${encodeURI(slug)}</loc> |
| | | <loc>https://${joinSegments(base, encodeURI(slug))}</loc> |
| | | <lastmod>${content.date?.toISOString()}</lastmod> |
| | | </url>` |
| | | const urls = Array.from(idx) |
| | |
| | | |
| | | const createURLEntry = (slug: SimpleSlug, content: ContentDetails): string => `<item> |
| | | <title>${escapeHTML(content.title)}</title> |
| | | <link>${root}/${encodeURI(slug)}</link> |
| | | <guid>${root}/${encodeURI(slug)}</guid> |
| | | <link>${joinSegments(root, encodeURI(slug))}</link> |
| | | <guid>${joinSegments(root, encodeURI(slug))}</guid> |
| | | <description>${content.richContent ?? content.description}</description> |
| | | <pubDate>${content.date?.toUTCString()}</pubDate> |
| | | </item>` |
| | | |
| | | const items = Array.from(idx) |
| | | .sort(([_, f1], [__, f2]) => { |
| | | if (f1.date && f2.date) { |
| | | return f2.date.getTime() - f1.date.getTime() |
| | | } else if (f1.date && !f2.date) { |
| | | return -1 |
| | | } else if (!f1.date && f2.date) { |
| | | return 1 |
| | | } |
| | | |
| | | return f1.title.localeCompare(f2.title) |
| | | }) |
| | | .map(([slug, content]) => createURLEntry(simplifySlug(slug), content)) |
| | | .slice(0, limit ?? idx.size) |
| | | .join("") |