From d2b76ea2c59744ba7e48cad44ebf2a33ed99c363 Mon Sep 17 00:00:00 2001 From: adueck Date: Fri, 29 Dec 2023 12:51:48 +0400 Subject: [PATCH] add lastmod to sitemap --- functions/src/publish.ts | 30 ++++++++++++++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) diff --git a/functions/src/publish.ts b/functions/src/publish.ts index 22da173..f907e5d 100644 --- a/functions/src/publish.ts +++ b/functions/src/publish.ts @@ -296,10 +296,25 @@ async function uploadDictionaryToStorage(dictionary: T.Dictionary) { } function makeSitemap(dictionary: T.Dictionary): string { + function tsToDate(ts: number): string { + if (ts < 10000000000) { + // approximate date for old-style timestamps + return "2021-01-01"; + } + return getDateString(new Date(ts)); + } + function getDateString(d: Date): string { + return d.toISOString().split("T")[0]; + } const pages = [ - ...["", "about", "settings", "account", "phrase-builder", "new-entries"], - ...dictionary.entries.map((x) => `word?id=${x.ts}`), + "", + "about", + "settings", + "account", + "phrase-builder", + "new-entries", ]; + const currentDate = getDateString(new Date()); return ` ${pages @@ -308,9 +323,20 @@ function makeSitemap(dictionary: T.Dictionary): string { ` https://dictionary.lingdocs.com/${page} + ${currentDate} ` ) .join("")} + ${dictionary.entries + .map( + (entry) => + ` + + https://dictionary.lingdocs.com/word?id=${entry.ts} + ${tsToDate(entry.ts)} + ` + ) + .join("")} `; }