Remove old alternate entries

This commit is contained in:
Johan Holmerin 2020-07-15 19:57:27 +02:00
parent 62dee956d7
commit d56232e6b7
1 changed files with 12 additions and 2 deletions

View File

@ -96,8 +96,14 @@ export const emailServer = new SMTPServer({
while (
document.querySelector("feed > entry") !== null &&
xml.serialize().length > 500_000
)
document.querySelector("feed > entry:last-of-type")!.remove();
) {
const lastEntry = document.querySelector("feed > entry:last-of-type");
const identifier = removeUrn(
lastEntry!.querySelector("id")!.textContent as string
);
await fs.unlink(alternatePath(identifier));
lastEntry!.remove();
}
await writeFileAtomic(
path,
`<?xml version="1.0" encoding="utf-8"?>${xml.serialize()}`
@ -235,6 +241,10 @@ function urn(identifier: string): string {
return `urn:kill-the-newsletter:${identifier}`;
}
function removeUrn(identifier: string): string {
return identifier.replace(urn(""), "");
}
function X(string: string): string {
return entities.encodeXML(sanitizeXMLString.sanitize(string));
}