Commit Graph

13 Commits

Author SHA1 Message Date
Leandro Facchinetti cb0bf74025 . 2020-12-12 02:37:21 +00:00
Leandro Facchinetti e452838d27 Don’t store alternates explicitly to save disk space
Instead, fetch alternates from within the feed on the demand.

This makes alternates marginally more expensive to retrieve, but saves on storage (which we were running out on the DigitalOcean deployment), and is a cleaner architecture overall: no need to keep the feeds and alternates in sync.

Here’s a script to migrate existing feeds:

// Call me with, for example: env "BASE_URL=https://kill-the-newsletter.com" npx ts-node migrate.ts
// I’m idempotent and reentrant, you may call me multiple times if necessary (for example, if the migration fails in the middle for whatever reason)

import { promises as fs } from "fs";
import path from "path";
import { JSDOM } from "jsdom";

const BASE_URL = process.env.BASE_URL ?? "http://localhost:8000";
const FEEDS_PATH = "static/feeds";

(async () => {
  await fs.rmdir("static/alternate", { recursive: true });
  for (const feedPath of (await fs.readdir(FEEDS_PATH)).filter((feedPath) =>
    feedPath.endsWith(".xml")
  )) {
    const text = await fs.readFile(path.join(FEEDS_PATH, feedPath), "utf-8");
    const feed = new JSDOM(text, { contentType: "text/xml" });
    const document = feed.window.document;
    const feedIdentifier = document
      .querySelector("id")!
      .textContent!.split(":")[2];
    for (const entry of document.querySelectorAll("entry")) {
      const entryIdentifier = entry
        .querySelector("id")!
        .textContent!.split(":")[2];
      entry
        .querySelector(`link[rel="alternate"]`)
        ?.setAttribute(
          "href",
          `${BASE_URL}/alternate/${feedIdentifier}/${entryIdentifier}.html`
        );
    }
    await fs.writeFile(
      path.join(FEEDS_PATH, feedPath),
      `<?xml version="1.0" encoding="utf-8"?>${feed.serialize()}`.trim()
    );
    console.log(feedIdentifier);
  }
})();
2020-11-24 17:12:14 +00:00
Leandro Facchinetti 212b06eb49 . 2020-10-31 11:43:57 +00:00
Leandro Facchinetti 175fdcae6b . 2020-08-04 22:52:12 +01:00
Leandro Facchinetti 80ae8fab52 Fixes & refactorings 2020-07-23 16:11:41 +01:00
Johan Holmerin 62dee956d7 Add support for alternate URL 2020-07-14 19:42:41 +02:00
Leandro Facchinetti da294b92fc . 2020-05-08 05:22:48 -04:00
Leandro Facchinetti 950cb8319c . 2020-05-07 21:08:11 -04:00
Leandro Facchinetti 3dbcda5278 Change some dependencies 2020-05-05 02:12:57 -04:00
Leandro Facchinetti 2f81ad9e47 PT Serif → PT Sans 2020-04-16 09:55:00 -04:00
Leandro Facchinetti c8964c62ad Use PT Serif 2020-04-09 01:42:46 -04:00
Leandro Facchinetti 0538487c03 . 2020-03-18 00:26:41 -04:00
Leandro Facchinetti 68f933a194 . 2020-03-17 21:54:08 -04:00