import { diffHtml } from "https://esm.town/v/chet/diffHtml";
import { blob } from "https://esm.town/v/std/blob?v=11";
import { email } from "https://esm.town/v/std/email?v=11";
import { fetch } from "https://esm.town/v/std/fetch";
export const watchWebsite = async () => {
const url = "https://transformer-circuits.pub";
const newHtml = await fetch(url).then(r => r.text());
const key = "watch:" + url;
let oldHtml = "";
try {
oldHtml = await blob.get(key).then(r => r.text());
} catch (error) {
console.log("error");
}
await blob.set(key, newHtml);
if (!oldHtml) {
console.log("NO OLD", { oldHtml, newHtml });
return;
}
const diff = diffHtml(oldHtml, newHtml);
if (!diff) {
console.log("NO DIFF", { oldHtml, newHtml });
return;
}
console.log("DIFF", diff);
email({ subject: `Diff for ${url}`, text: diff });
};