|
| 1 | +import { readdir, readFile, writeFile, cp } from "node:fs/promises"; |
| 2 | +import { join } from "node:path"; |
| 3 | + |
| 4 | +const DIST = "dist"; |
| 5 | +const OG_TAGS = `<meta property="og:type" content="website" /> |
| 6 | +<meta property="og:title" content="Polyglot SQL API Documentation" /> |
| 7 | +<meta property="og:description" content="Transpile SQL between 30+ database dialects in the browser" /> |
| 8 | +<meta property="og:image" content="https://polyglot.gh.tobilg.com/polyglot-opengraph.png" /> |
| 9 | +<meta name="twitter:card" content="summary_large_image" /> |
| 10 | +<meta name="twitter:title" content="Polyglot SQL API Documentation" /> |
| 11 | +<meta name="twitter:description" content="Transpile SQL between 30+ database dialects in the browser" /> |
| 12 | +<meta name="twitter:image" content="https://polyglot.gh.tobilg.com/polyglot-opengraph.png" />`; |
| 13 | + |
| 14 | +async function findHtmlFiles(dir) { |
| 15 | + const files = []; |
| 16 | + for (const entry of await readdir(dir, { withFileTypes: true })) { |
| 17 | + const path = join(dir, entry.name); |
| 18 | + if (entry.isDirectory()) files.push(...(await findHtmlFiles(path))); |
| 19 | + else if (entry.name.endsWith(".html")) files.push(path); |
| 20 | + } |
| 21 | + return files; |
| 22 | +} |
| 23 | + |
| 24 | +const htmlFiles = await findHtmlFiles(DIST); |
| 25 | +for (const file of htmlFiles) { |
| 26 | + const content = await readFile(file, "utf8"); |
| 27 | + if (!content.includes("og:title")) { |
| 28 | + await writeFile(file, content.replace("</head>", `${OG_TAGS}\n</head>`)); |
| 29 | + } |
| 30 | +} |
| 31 | + |
| 32 | +await cp("public", DIST, { recursive: true }); |
| 33 | + |
| 34 | +console.log(`Injected OG tags into ${htmlFiles.length} HTML files and copied public assets.`); |
0 commit comments