diff --git a/.npmrc b/.npmrc
new file mode 100644
index 0000000..97c56e9
--- /dev/null
+++ b/.npmrc
@@ -0,0 +1 @@
+@nulo:registry=https://gitea.nulo.in/api/packages/nulo/npm/
diff --git a/compilar.ts b/compilar.ts
index 350f3f0..ce7d754 100644
--- a/compilar.ts
+++ b/compilar.ts
@@ -3,6 +3,23 @@ import { basename, extname, join } from "path";
import { execFile as execFileCallback } from "child_process";
import { promisify } from "util";
import * as commonmark from "commonmark";
+import {
+ a,
+ doctype,
+ h1,
+ header,
+ section,
+ li,
+ link,
+ meta,
+ metaUtf8,
+ render,
+ Renderable,
+ title,
+ ul,
+ h2,
+ raw,
+} from "@nulo/html.js";
const execFile = promisify(execFileCallback);
@@ -65,13 +82,14 @@ async function compilePage(config: Config, sourceFileName: string) {
const contentHtml = await compileContentHtml(config, sourceFileName);
- const html =
- generateHead(title, name) +
- (isIndex
- ? ""
- : generateHeader(title, sourceFileName, fileConnections.length > 0)) +
- contentHtml +
- generateConnectionsSection(fileConnections);
+ const html = render(
+ ...generateHead(title, name),
+ ...(isIndex
+ ? []
+ : generateHeader(title, sourceFileName, fileConnections.length > 0)),
+ raw(contentHtml),
+ ...generateConnectionsSection(fileConnections)
+ );
const outputPath = join(config.buildPath, name + ".html");
await writeFile(outputPath, html);
@@ -118,65 +136,97 @@ async function compileExecutableHtml(
// Generated HTML
// ==============================================
-function generateHead(title: string, outputName: string) {
+function generateHead(titlee: string, outputName: string): Renderable[] {
// TODO: deshardcodear og:url
- return `
-
-
-
-
-
-
-
-
-
-
${title}
-`;
+ return [
+ doctype(),
+ metaUtf8,
+ meta({
+ name: "viewport",
+ content: "width=device-width, initial-scale=1.0",
+ }),
+ meta({
+ name: "author",
+ content: "Nulo",
+ }),
+ meta({
+ property: "og:title",
+ content: titlee,
+ }),
+ meta({
+ property: "og:type",
+ content: "website",
+ }),
+ meta({
+ property: "og:url",
+ content: `https://nulo.in/${outputName}.html`,
+ }),
+ meta({
+ property: "og:image",
+ content: "cowboy.svg",
+ }),
+ link({
+ rel: "stylesheet",
+ href: "drip.css",
+ }),
+ link({
+ rel: "icon",
+ href: "cowboy.svg",
+ }),
+ title(titlee),
+ ];
}
function generateHeader(
title: string,
sourceCodePath: string,
linkConexiones = false
-) {
- return `☚ Volver al inicio`;
+): Renderable[] {
+ return [
+ a({ href: "." }, "☚ Volver al inicio"),
+ header(
+ h1(title),
+ a(
+ {
+ href: `https://gitea.nulo.in/Nulo/sitio/commits/branch/ANTIFASCISTA/${sourceCodePath}`,
+ },
+ "Historial"
+ ),
+ ...(linkConexiones ? [a({ href: "#conexiones" }, "Conexiones")] : [])
+ ),
+ ];
}
-function generateConnectionsSection(fileConnections: Connection[]): string {
+function generateConnectionsSection(
+ fileConnections: Connection[]
+): Renderable[] {
return fileConnections.length > 0
- ? `
-
- ⥆ Conexiones (${fileConnections.length})
-
- ${fileConnections
- .map(({ linker }) => `- ${linker}
`)
- .join("\n")}
-
-`
- : "";
+ ? [
+ section(
+ { id: "conexiones" },
+ h2(`⥆ Conexiones (${fileConnections.length})`),
+ ul(
+ ...fileConnections.map(({ linker }) =>
+ li(a({ href: `${linker}.html` }, linker))
+ )
+ )
+ ),
+ ]
+ : [];
}
async function compilePageList(config: Config, pageList: string[]) {
const name = "Lista de páginas";
const outputPath = join(config.buildPath, name + ".html");
- const html =
- generateHead(name, name) +
- generateHeader(name, "compilar.ts") +
- `
- ${pageList
- .sort((a, b) => a.localeCompare(b, "es", { sensitivity: "base" }))
- .map((name) => `- ${name}
`)
- .join("\n")}
-
-`;
+ const html = render(
+ ...generateHead(name, name),
+ ...generateHeader(name, "compilar.ts"),
+ ul(
+ ...pageList
+ .sort((a, b) => a.localeCompare(b, "es", { sensitivity: "base" }))
+ .map((name) => li(a({ href: `${name}.html` }, name)))
+ )
+ );
await writeFile(outputPath, html);
}
diff --git a/package.json b/package.json
index dbf0297..7e5d915 100644
--- a/package.json
+++ b/package.json
@@ -19,6 +19,7 @@
"typescript": "^4.9.4"
},
"dependencies": {
+ "@nulo/html.js": "^0.0.2",
"commonmark": "^0.30.0"
}
}
diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml
index 3839301..f7d8cb8 100644
--- a/pnpm-lock.yaml
+++ b/pnpm-lock.yaml
@@ -1,6 +1,7 @@
lockfileVersion: 5.4
specifiers:
+ '@nulo/html.js': ^0.0.2
'@types/commonmark': ^0.27.5
'@types/node': ^18.11.17
commonmark: ^0.30.0
@@ -8,6 +9,7 @@ specifiers:
typescript: ^4.9.4
dependencies:
+ '@nulo/html.js': link:../html.js
commonmark: 0.30.0
devDependencies: