Tudo: Primeiro commit
This commit is contained in:
commit
06a90928dc
4633 files changed
+6327263
No files matched your search
@@ -0,0 +1,98 @@
|
||||
#!/usr/bin/env node
|
||||
/*
|
||||
* Gera build/robo-movel.pdf a partir de build/index.html.
|
||||
*
|
||||
* - Sobe um servidor estático local (porta efêmera) para servir o build.
|
||||
* - Usa o @media print de styles.css: cada .slide ocupa uma página 1920x1080.
|
||||
* - Injeta CSS para deixar reveals no estado final e esconder botões/progresso.
|
||||
* - page.pdf() mantém o texto selecionável (diferente de juntar PNGs).
|
||||
*
|
||||
* Uso: node scripts/build-pdf.cjs
|
||||
*/
|
||||
const http = require("http");
|
||||
const fs = require("fs");
|
||||
const path = require("path");
|
||||
const { chromium } = require("/home/marcel/.npm/_npx/e41f203b7505f1fb/node_modules/playwright");
|
||||
|
||||
const BUILD = path.resolve(__dirname, "..", "build");
|
||||
const OUT = path.join(BUILD, "robo-movel.pdf");
|
||||
|
||||
const MIME = {
|
||||
".html": "text/html; charset=utf-8",
|
||||
".css": "text/css; charset=utf-8",
|
||||
".js": "text/javascript; charset=utf-8",
|
||||
".png": "image/png",
|
||||
".jpg": "image/jpeg",
|
||||
".jpeg": "image/jpeg",
|
||||
".svg": "image/svg+xml",
|
||||
".woff2": "font/woff2",
|
||||
};
|
||||
|
||||
// Estado final das animações + oculta chrome de navegação/edição no PDF.
|
||||
const PRINT_STATE_CSS = `
|
||||
.reveal, .reveal-scale {
|
||||
opacity: 1 !important;
|
||||
transform: none !important;
|
||||
transition: none !important;
|
||||
animation: none !important;
|
||||
}
|
||||
.edit-toggle, .edit-hotzone, .progress, .deck-controls { display: none !important; }
|
||||
`;
|
||||
|
||||
function startServer() {
|
||||
const server = http.createServer((req, res) => {
|
||||
const urlPath = decodeURIComponent(req.url.split("?")[0]);
|
||||
let filePath = path.join(BUILD, urlPath === "/" ? "index.html" : urlPath);
|
||||
if (!filePath.startsWith(BUILD)) {
|
||||
res.writeHead(403).end();
|
||||
return;
|
||||
}
|
||||
fs.readFile(filePath, (err, data) => {
|
||||
if (err) {
|
||||
res.writeHead(404).end("not found");
|
||||
return;
|
||||
}
|
||||
res.writeHead(200, { "Content-Type": MIME[path.extname(filePath)] || "application/octet-stream" });
|
||||
res.end(data);
|
||||
});
|
||||
});
|
||||
return new Promise((resolve) => server.listen(0, "127.0.0.1", () => resolve(server)));
|
||||
}
|
||||
|
||||
(async () => {
|
||||
if (!fs.existsSync(path.join(BUILD, "index.html"))) {
|
||||
console.error("build/index.html não encontrado. Rode `make` primeiro.");
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
const server = await startServer();
|
||||
const port = server.address().port;
|
||||
const url = `http://127.0.0.1:${port}/index.html`;
|
||||
|
||||
const browser = await chromium.launch({ headless: true });
|
||||
const page = await browser.newPage({ viewport: { width: 1920, height: 1080 } });
|
||||
page.on("pageerror", (e) => console.log("PAGE EXCEPTION:", e.message));
|
||||
|
||||
await page.goto(url, { waitUntil: "networkidle" });
|
||||
await page.evaluate(() => document.fonts.ready);
|
||||
await page.addStyleTag({ content: PRINT_STATE_CSS });
|
||||
await page.waitForTimeout(300);
|
||||
|
||||
const total = await page.evaluate(() => document.querySelectorAll(".slide").length);
|
||||
|
||||
await page.emulateMedia({ media: "print" });
|
||||
await page.pdf({
|
||||
path: OUT,
|
||||
width: "1920px",
|
||||
height: "1080px",
|
||||
margin: { top: "0", right: "0", bottom: "0", left: "0" },
|
||||
printBackground: true,
|
||||
preferCSSPageSize: false,
|
||||
});
|
||||
|
||||
await browser.close();
|
||||
server.close();
|
||||
|
||||
const size = fs.statSync(OUT).size;
|
||||
console.log(`build/robo-movel.pdf gerado (${total} slides, ${(size / 1024).toFixed(0)} KB)`);
|
||||
})();
|
||||
@@ -0,0 +1,46 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Monta o build autocontido da apresentação.
|
||||
|
||||
- Embuti src/styles.css e src/main.js dentro do HTML.
|
||||
- Copia src/assets/ para build/assets/ (as imagens continuam externas).
|
||||
"""
|
||||
import os
|
||||
import shutil
|
||||
|
||||
ROOT = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
|
||||
SRC = os.path.join(ROOT, "src")
|
||||
BUILD = os.path.join(ROOT, "build")
|
||||
|
||||
os.makedirs(BUILD, exist_ok=True)
|
||||
|
||||
with open(os.path.join(SRC, "index.html"), encoding="utf-8") as f:
|
||||
html = f.read()
|
||||
with open(os.path.join(SRC, "styles.css"), encoding="utf-8") as f:
|
||||
css = f.read()
|
||||
with open(os.path.join(SRC, "main.js"), encoding="utf-8") as f:
|
||||
js = f.read()
|
||||
|
||||
html = html.replace(
|
||||
'<link rel="stylesheet" href="styles.css">',
|
||||
"<style>\n" + css + "</style>",
|
||||
)
|
||||
html = html.replace(
|
||||
'<script src="main.js"></script>',
|
||||
"<script>\n" + js + "</script>",
|
||||
)
|
||||
|
||||
# Confere que não sobrou nenhuma referência externa a CSS/JS
|
||||
assert 'href="styles.css"' not in html, "styles.css não foi embutido"
|
||||
assert 'src="main.js"' not in html, "main.js não foi embutido"
|
||||
|
||||
with open(os.path.join(BUILD, "index.html"), "w", encoding="utf-8") as f:
|
||||
f.write(html)
|
||||
|
||||
# Imagens: build/assets/
|
||||
assets_out = os.path.join(BUILD, "assets")
|
||||
if os.path.isdir(assets_out):
|
||||
shutil.rmtree(assets_out)
|
||||
shutil.copytree(os.path.join(SRC, "assets"), assets_out)
|
||||
|
||||
print("build/index.html gerado ({} bytes)".format(len(html.encode("utf-8"))))
|
||||
print("build/assets/ com {} arquivos".format(len(os.listdir(assets_out))))
|
||||
Reference in new issue
Block a user