const fs = require('fs'); const { getAvatar, preparePost, encodeString, getActionDescription, getMediaUrl } = require("./utils"); require('dotenv').config(); const KEY = process.env.ITCH_API_KEY; const ITCH_SVG = ''; const TAGS_MAP = { 40801: "lifeisstrange", 1826237: "incremental", 969362: "incremental", 938153: "incremental", 2074815: "incremental", 730177: "incremental", 62179: "incremental", 814897: "incremental", 993566: "incremental" }; (async () => { const url = `https://itch.io/api/1/${KEY}/my-games`; const resp = await fetch(url).then(r => r.text()); let response; try { response = JSON.parse(resp); } catch (err) { console.error("Unexpected response from itch:", url, resp, err); process.exit(0); } if (!response.games?.length) { console.error("No games received from itch:", url, resp); process.exit(0); } console.log(`Checking ${response.games.length} games`); for await (const game of response.games) { if (!game.published) continue; let timestamp = new Date(game.published_at).getTime(); const tag = TAGS_MAP[game.id] ?? "gaming"; let embed = ''; if (game.embed) { const uploadsResponse = await fetch(`https://itch.io/api/1/${KEY}/game/${game.id}/uploads`).then(r => r.text()); embed = await getEmbed(game, uploadsResponse); } let path; for (timestamp--; path == null || fs.existsSync(path);) { path = `./site/article/${getTimestampPath(++timestamp)}`; } fs.mkdirSync(path, { recursive: true }); const fd = fs.openSync(path + "/index.md", "w+"); fs.writeSync(fd, preparePost(`--- kind: article title: ${encodeString(game.title)} published: ${timestamp} next: false prev: false tags: [${encodeString(tag, 2)}] ---