html.js
This commit is contained in:
parent
9447af6a3a
commit
4f0fdc352c
4 changed files with 105 additions and 51 deletions
1
.npmrc
Normal file
1
.npmrc
Normal file
|
@ -0,0 +1 @@
|
||||||
|
@nulo:registry=https://gitea.nulo.in/api/packages/nulo/npm/
|
152
compilar.ts
152
compilar.ts
|
@ -3,6 +3,23 @@ import { basename, extname, join } from "path";
|
||||||
import { execFile as execFileCallback } from "child_process";
|
import { execFile as execFileCallback } from "child_process";
|
||||||
import { promisify } from "util";
|
import { promisify } from "util";
|
||||||
import * as commonmark from "commonmark";
|
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);
|
const execFile = promisify(execFileCallback);
|
||||||
|
|
||||||
|
@ -65,13 +82,14 @@ async function compilePage(config: Config, sourceFileName: string) {
|
||||||
|
|
||||||
const contentHtml = await compileContentHtml(config, sourceFileName);
|
const contentHtml = await compileContentHtml(config, sourceFileName);
|
||||||
|
|
||||||
const html =
|
const html = render(
|
||||||
generateHead(title, name) +
|
...generateHead(title, name),
|
||||||
(isIndex
|
...(isIndex
|
||||||
? ""
|
? []
|
||||||
: generateHeader(title, sourceFileName, fileConnections.length > 0)) +
|
: generateHeader(title, sourceFileName, fileConnections.length > 0)),
|
||||||
contentHtml +
|
raw(contentHtml),
|
||||||
generateConnectionsSection(fileConnections);
|
...generateConnectionsSection(fileConnections)
|
||||||
|
);
|
||||||
|
|
||||||
const outputPath = join(config.buildPath, name + ".html");
|
const outputPath = join(config.buildPath, name + ".html");
|
||||||
await writeFile(outputPath, html);
|
await writeFile(outputPath, html);
|
||||||
|
@ -118,65 +136,97 @@ async function compileExecutableHtml(
|
||||||
// Generated HTML
|
// Generated HTML
|
||||||
// ==============================================
|
// ==============================================
|
||||||
|
|
||||||
function generateHead(title: string, outputName: string) {
|
function generateHead(titlee: string, outputName: string): Renderable[] {
|
||||||
// TODO: deshardcodear og:url
|
// TODO: deshardcodear og:url
|
||||||
return `<!doctype html>
|
return [
|
||||||
<meta charset=utf-8>
|
doctype(),
|
||||||
<meta name=viewport content="width=device-width, initial-scale=1.0">
|
metaUtf8,
|
||||||
<meta name=author content=Nulo>
|
meta({
|
||||||
<meta property=og:title content="${title}">
|
name: "viewport",
|
||||||
<meta property=og:type content=website>
|
content: "width=device-width, initial-scale=1.0",
|
||||||
<meta property=og:url content="https://nulo.in/${outputName}.html">
|
}),
|
||||||
<meta property=og:image content=cowboy.svg>
|
meta({
|
||||||
<link rel=stylesheet href=drip.css>
|
name: "author",
|
||||||
<link rel=icon href=cowboy.svg>
|
content: "Nulo",
|
||||||
<title>${title}</title>
|
}),
|
||||||
`;
|
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(
|
function generateHeader(
|
||||||
title: string,
|
title: string,
|
||||||
sourceCodePath: string,
|
sourceCodePath: string,
|
||||||
linkConexiones = false
|
linkConexiones = false
|
||||||
) {
|
): Renderable[] {
|
||||||
return `<a href=.>☚ Volver al inicio</a><header>
|
return [
|
||||||
<h1>${title}</h1>
|
a({ href: "." }, "☚ Volver al inicio"),
|
||||||
<a href="https://gitea.nulo.in/Nulo/sitio/commits/branch/ANTIFASCISTA/${sourceCodePath}">Historial</a>${
|
header(
|
||||||
linkConexiones
|
h1(title),
|
||||||
? ` /
|
a(
|
||||||
<a href="#conexiones">Conexiones</a>`
|
{
|
||||||
: ""
|
href: `https://gitea.nulo.in/Nulo/sitio/commits/branch/ANTIFASCISTA/${sourceCodePath}`,
|
||||||
}
|
},
|
||||||
</header>`;
|
"Historial"
|
||||||
|
),
|
||||||
|
...(linkConexiones ? [a({ href: "#conexiones" }, "Conexiones")] : [])
|
||||||
|
),
|
||||||
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
function generateConnectionsSection(fileConnections: Connection[]): string {
|
function generateConnectionsSection(
|
||||||
|
fileConnections: Connection[]
|
||||||
|
): Renderable[] {
|
||||||
return fileConnections.length > 0
|
return fileConnections.length > 0
|
||||||
? `
|
? [
|
||||||
<section id=conexiones>
|
section(
|
||||||
<h2>⥆ Conexiones (${fileConnections.length})</h2>
|
{ id: "conexiones" },
|
||||||
<ul>
|
h2(`⥆ Conexiones (${fileConnections.length})`),
|
||||||
${fileConnections
|
ul(
|
||||||
.map(({ linker }) => `<li><a href="${linker}.html">${linker}</a></li>`)
|
...fileConnections.map(({ linker }) =>
|
||||||
.join("\n")}
|
li(a({ href: `${linker}.html` }, linker))
|
||||||
</ul>
|
)
|
||||||
</section>`
|
)
|
||||||
: "";
|
),
|
||||||
|
]
|
||||||
|
: [];
|
||||||
}
|
}
|
||||||
|
|
||||||
async function compilePageList(config: Config, pageList: string[]) {
|
async function compilePageList(config: Config, pageList: string[]) {
|
||||||
const name = "Lista de páginas";
|
const name = "Lista de páginas";
|
||||||
const outputPath = join(config.buildPath, name + ".html");
|
const outputPath = join(config.buildPath, name + ".html");
|
||||||
const html =
|
const html = render(
|
||||||
generateHead(name, name) +
|
...generateHead(name, name),
|
||||||
generateHeader(name, "compilar.ts") +
|
...generateHeader(name, "compilar.ts"),
|
||||||
`<ul>
|
ul(
|
||||||
${pageList
|
...pageList
|
||||||
.sort((a, b) => a.localeCompare(b, "es", { sensitivity: "base" }))
|
.sort((a, b) => a.localeCompare(b, "es", { sensitivity: "base" }))
|
||||||
.map((name) => `<li><a href="${name}.html">${name}</a></li>`)
|
.map((name) => li(a({ href: `${name}.html` }, name)))
|
||||||
.join("\n")}
|
)
|
||||||
</ul>
|
);
|
||||||
`;
|
|
||||||
await writeFile(outputPath, html);
|
await writeFile(outputPath, html);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -19,6 +19,7 @@
|
||||||
"typescript": "^4.9.4"
|
"typescript": "^4.9.4"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
"@nulo/html.js": "^0.0.2",
|
||||||
"commonmark": "^0.30.0"
|
"commonmark": "^0.30.0"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
lockfileVersion: 5.4
|
lockfileVersion: 5.4
|
||||||
|
|
||||||
specifiers:
|
specifiers:
|
||||||
|
'@nulo/html.js': ^0.0.2
|
||||||
'@types/commonmark': ^0.27.5
|
'@types/commonmark': ^0.27.5
|
||||||
'@types/node': ^18.11.17
|
'@types/node': ^18.11.17
|
||||||
commonmark: ^0.30.0
|
commonmark: ^0.30.0
|
||||||
|
@ -8,6 +9,7 @@ specifiers:
|
||||||
typescript: ^4.9.4
|
typescript: ^4.9.4
|
||||||
|
|
||||||
dependencies:
|
dependencies:
|
||||||
|
'@nulo/html.js': link:../html.js
|
||||||
commonmark: 0.30.0
|
commonmark: 0.30.0
|
||||||
|
|
||||||
devDependencies:
|
devDependencies:
|
||||||
|
|
Reference in a new issue