Remove google-translate dep, upgrade firebase-admin, pin csv-parse, and improve processUsers.js

- Remove @iamtraction/google-translate (and undici vulnerability) — translation
  no longer needed, language files now copy English content directly
- Upgrade firebase-admin from ^12.0.0 to ^13.8.0
- Pin csv-parse to ~5.5.0 to avoid major version bump
- Use networkidle2 + 2s delay in processUsers.js for reliable screenshots

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
Nuno Coração
2026-04-13 22:19:07 +01:00
parent 8fda75b134
commit c6d40c6d3f
5 changed files with 234 additions and 148 deletions
+4 -41
View File
@@ -1,51 +1,17 @@
const fs = require("fs/promises");
const crypto = require("crypto");
const puppeteer = require("puppeteer");
const translate = require("@iamtraction/google-translate");
const configDir = "./exampleSite/config/_default";
const defaultLang = "en";
const usersFolderPath = "./exampleSite/content/users/";
let cache = {};
function generateDirName(seed, index) {
const hash = crypto.createHash("md5");
hash.update(seed);
return index + "-" + hash.digest("hex");
}
async function convert(text, from, to) {
const options = { from, to };
if (!cache[to]) cache[to] = {};
if (cache[to][text]) return cache[to][text];
const translated_text = await translate(text, options);
cache[to][text] = translated_text.text;
return translated_text.text;
}
async function translateFrontMatterTags(block, targetLang, tags) {
const array = block.split("\n");
let translatedBlock = "";
for (const line of array) {
let newElement = line;
if (line.indexOf(":") > -1) {
const elements = line.split(":");
if (elements[0].indexOf("tags") != -1) {
const translatedTags = [];
for (const tag of tags) {
const tempTag = await convert(tag, defaultLang, targetLang);
translatedTags.push(tempTag);
}
const trasnlatedTagsString = translatedTags.join(", ");
newElement = elements[0] + ": [" + trasnlatedTagsString + "]";
}
}
translatedBlock += newElement + "\n";
}
return translatedBlock;
}
(async () => {
const targetLangs = [];
const configFiles = await fs.readdir(configDir);
@@ -129,14 +95,11 @@ async function translateFrontMatterTags(block, targetLang, tags) {
console.log(i, user.title, dir);
await fs.writeFile(dir + "/index.md", userMDFile);
for (var lang of targetLangs) {
const langfilename = lang
if (lang == "pt-br" || lang == "pt-pt")
lang = "pt"
const content = await translateFrontMatterTags(userMDFile, lang, user.tags);
await fs.writeFile(dir + `/index.${langfilename}.md`, content);
for (const lang of targetLangs) {
await fs.writeFile(dir + `/index.${lang}.md`, userMDFile);
}
await page.goto(user.url);
await page.goto(user.url, { waitUntil: "networkidle2", timeout: 30000 });
await new Promise(resolve => setTimeout(resolve, 2000));
await page.screenshot({ path: dir + "/feature.webp", type: "webp", quality: 50 });
}
}