Compare commits
No commits in common. "3aaceb90803084c90aea8e48acfd6560741c464a" and "647f77b26606e53ca8491b41d25985b5bfe96ec5" have entirely different histories.
3aaceb9080
...
647f77b266
4 changed files with 23 additions and 134 deletions
142
compilar.ts
142
compilar.ts
|
@ -19,10 +19,6 @@ import {
|
||||||
ul,
|
ul,
|
||||||
h2,
|
h2,
|
||||||
raw,
|
raw,
|
||||||
p,
|
|
||||||
VirtualElement,
|
|
||||||
time,
|
|
||||||
article,
|
|
||||||
} from "@nulo/html.js";
|
} from "@nulo/html.js";
|
||||||
|
|
||||||
const execFile = promisify(execFileCallback);
|
const execFile = promisify(execFileCallback);
|
||||||
|
@ -30,13 +26,6 @@ const execFile = promisify(execFileCallback);
|
||||||
const reader = new commonmark.Parser({ smart: true });
|
const reader = new commonmark.Parser({ smart: true });
|
||||||
const writer = new commonmark.HtmlRenderer({ safe: false, smart: true });
|
const writer = new commonmark.HtmlRenderer({ safe: false, smart: true });
|
||||||
|
|
||||||
const dateFormatter = new Intl.DateTimeFormat("es-AR", {
|
|
||||||
weekday: "long",
|
|
||||||
day: "numeric",
|
|
||||||
month: "long",
|
|
||||||
year: "numeric",
|
|
||||||
});
|
|
||||||
|
|
||||||
const wikilinkExp = /\[\[(.+?)\]\]/giu;
|
const wikilinkExp = /\[\[(.+?)\]\]/giu;
|
||||||
|
|
||||||
const compilers: {
|
const compilers: {
|
||||||
|
@ -96,21 +85,18 @@ async function compileFile(name: string) {
|
||||||
async function compilePage(config: Config, sourceFileName: string) {
|
async function compilePage(config: Config, sourceFileName: string) {
|
||||||
const name = basename(sourceFileName, extname(sourceFileName));
|
const name = basename(sourceFileName, extname(sourceFileName));
|
||||||
const isIndex = name === "index";
|
const isIndex = name === "index";
|
||||||
const title = isIndex ? "nulo.in" : formatNameToPlainText(name);
|
const title = isIndex ? "nulo.in" : name;
|
||||||
const fileConnections = connections.filter(({ linked }) => linked === name);
|
const fileConnections = connections.filter(({ linked }) => linked === name);
|
||||||
|
|
||||||
const contentHtml = await compileContentHtml(config, sourceFileName);
|
const contentHtml = await compileContentHtml(config, sourceFileName);
|
||||||
|
|
||||||
const html = render(
|
const html = render(
|
||||||
...generateHead(title, name),
|
...generateHead(title, name),
|
||||||
article(
|
...(isIndex
|
||||||
{ itemscope: "", itemtype: "https://schema.org/CreativeWork" },
|
? []
|
||||||
...(isIndex
|
: generateHeader(title, sourceFileName, fileConnections.length > 0)),
|
||||||
? []
|
raw(contentHtml),
|
||||||
: generateHeader(name, sourceFileName, fileConnections.length > 0)),
|
...generateConnectionsSection(fileConnections)
|
||||||
raw(contentHtml),
|
|
||||||
...generateConnectionsSection(fileConnections)
|
|
||||||
)
|
|
||||||
);
|
);
|
||||||
|
|
||||||
const outputPath = join(config.buildPath, name + ".html");
|
const outputPath = join(config.buildPath, name + ".html");
|
||||||
|
@ -199,112 +185,15 @@ function generateHead(titlee: string, outputName: string): Renderable[] {
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
function formatDate(dateish: Dateish, upper: boolean = false): string {
|
|
||||||
const date = new Date(dateish.year, dateish.month - 1, dateish.day);
|
|
||||||
const formatted = dateFormatter.format(date);
|
|
||||||
if (upper) {
|
|
||||||
// no le digan a la policía del unicode!
|
|
||||||
return formatted[0].toUpperCase() + formatted.slice(1);
|
|
||||||
} else return formatted;
|
|
||||||
}
|
|
||||||
|
|
||||||
interface Dateish {
|
|
||||||
year: number;
|
|
||||||
month: number;
|
|
||||||
day: number;
|
|
||||||
}
|
|
||||||
function dateishToString({ year, month, day }: Dateish): string {
|
|
||||||
return `${year}-${String(month).padStart(2, "0")}-${String(day).padStart(
|
|
||||||
2,
|
|
||||||
"0"
|
|
||||||
)}`;
|
|
||||||
}
|
|
||||||
|
|
||||||
type TitleMetadata =
|
|
||||||
| {
|
|
||||||
// title puede tener length == 0 y por lo tanto ser falseish
|
|
||||||
title: string;
|
|
||||||
date?: Dateish;
|
|
||||||
}
|
|
||||||
| { date: Dateish };
|
|
||||||
function parseName(name: string): TitleMetadata {
|
|
||||||
const titleWithDate =
|
|
||||||
/^((?<year>\d{4})-(?<month>\d{2})-(?<day>\d{2}))? ?(?<title>.*)$/;
|
|
||||||
|
|
||||||
const found = name.match(titleWithDate);
|
|
||||||
if (!found || !found.groups) throw new Error("Algo raro pasó");
|
|
||||||
const { title } = found.groups;
|
|
||||||
|
|
||||||
const date =
|
|
||||||
(found.groups.year && {
|
|
||||||
year: parseInt(found.groups.year),
|
|
||||||
month: parseInt(found.groups.month),
|
|
||||||
day: parseInt(found.groups.day),
|
|
||||||
}) ||
|
|
||||||
undefined;
|
|
||||||
// no definir title si es length == 0
|
|
||||||
if (!title && date) return { date };
|
|
||||||
return { title, date };
|
|
||||||
}
|
|
||||||
|
|
||||||
function dateishToElement(
|
|
||||||
dateish: Dateish,
|
|
||||||
{ itemprop, upper }: { itemprop?: string; upper?: boolean } = {}
|
|
||||||
): VirtualElement {
|
|
||||||
return time(
|
|
||||||
{ datetime: dateishToString(dateish), ...(itemprop ? { itemprop } : {}) },
|
|
||||||
formatDate(dateish, upper)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
function formatNameToInline(name: string): Renderable[] {
|
|
||||||
const parsed = parseName(name);
|
|
||||||
if ("title" in parsed) {
|
|
||||||
const { title, date } = parsed;
|
|
||||||
return [title, ...(date ? [` (`, dateishToElement(date), `)`] : [])];
|
|
||||||
} else {
|
|
||||||
return [dateishToElement(parsed.date, { upper: true })];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
function formatNameToPlainText(name: string): string {
|
|
||||||
const parsed = parseName(name);
|
|
||||||
if ("title" in parsed) {
|
|
||||||
const { title, date } = parsed;
|
|
||||||
return title + (date ? ` (${formatDate(date)})` : "");
|
|
||||||
} else {
|
|
||||||
return formatDate(parsed.date, true);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function generateHeader(
|
function generateHeader(
|
||||||
name: string,
|
title: string,
|
||||||
sourceCodePath: string,
|
sourceCodePath: string,
|
||||||
linkConexiones = false
|
linkConexiones = false
|
||||||
): Renderable[] {
|
): Renderable[] {
|
||||||
const parsedTitle = parseName(name);
|
|
||||||
return [
|
return [
|
||||||
a({ href: "." }, "☚ Volver al inicio"),
|
a({ href: "." }, "☚ Volver al inicio"),
|
||||||
header(
|
header(
|
||||||
...("title" in parsedTitle
|
h1(title),
|
||||||
? [
|
|
||||||
h1(parsedTitle.title),
|
|
||||||
...(parsedTitle.date
|
|
||||||
? [
|
|
||||||
dateishToElement(parsedTitle.date, {
|
|
||||||
itemprop: "datePublished",
|
|
||||||
}),
|
|
||||||
" / ",
|
|
||||||
]
|
|
||||||
: []),
|
|
||||||
]
|
|
||||||
: [
|
|
||||||
h1(
|
|
||||||
dateishToElement(parsedTitle.date, {
|
|
||||||
itemprop: "datePublished",
|
|
||||||
upper: true,
|
|
||||||
})
|
|
||||||
),
|
|
||||||
]),
|
|
||||||
a(
|
a(
|
||||||
{
|
{
|
||||||
href: `https://gitea.nulo.in/Nulo/sitio/commits/branch/ANTIFASCISTA/${sourceCodePath}`,
|
href: `https://gitea.nulo.in/Nulo/sitio/commits/branch/ANTIFASCISTA/${sourceCodePath}`,
|
||||||
|
@ -326,7 +215,11 @@ function generateConnectionsSection(
|
||||||
section(
|
section(
|
||||||
{ id: "conexiones" },
|
{ id: "conexiones" },
|
||||||
h2(`⥆ Conexiones (${fileConnections.length})`),
|
h2(`⥆ Conexiones (${fileConnections.length})`),
|
||||||
ul(...fileConnections.map(({ linker }) => li(internalLink(linker))))
|
ul(
|
||||||
|
...fileConnections.map(({ linker }) =>
|
||||||
|
li(a({ href: internalLink(linker) }, linker))
|
||||||
|
)
|
||||||
|
)
|
||||||
),
|
),
|
||||||
]
|
]
|
||||||
: [];
|
: [];
|
||||||
|
@ -341,7 +234,7 @@ async function compilePageList(config: Config, pageList: string[]) {
|
||||||
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(internalLink(name)))
|
.map((name) => li(a({ href: internalLink(name) }, name)))
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
await writeFile(outputPath, html);
|
await writeFile(outputPath, html);
|
||||||
|
@ -384,7 +277,7 @@ function renderMarkdown(markdown: string) {
|
||||||
async function hackilyTransformHtml(html: string): Promise<string> {
|
async function hackilyTransformHtml(html: string): Promise<string> {
|
||||||
html = html
|
html = html
|
||||||
.replaceAll("<a h", '<a rel="noopener noreferrer" h')
|
.replaceAll("<a h", '<a rel="noopener noreferrer" h')
|
||||||
.replaceAll(wikilinkExp, (_, l) => render(internalLink(l)));
|
.replaceAll(wikilinkExp, (_, l) => render(a({ href: internalLink(l) }, l)));
|
||||||
for (const [match, archivo] of html.matchAll(
|
for (const [match, archivo] of html.matchAll(
|
||||||
/<nulo-sitio-reemplazar-con archivo="(.+?)" \/>/g
|
/<nulo-sitio-reemplazar-con archivo="(.+?)" \/>/g
|
||||||
)) {
|
)) {
|
||||||
|
@ -397,7 +290,6 @@ async function hackilyTransformHtml(html: string): Promise<string> {
|
||||||
// Linking
|
// Linking
|
||||||
// ==============================================
|
// ==============================================
|
||||||
|
|
||||||
function internalLink(path: string): VirtualElement {
|
function internalLink(path: string) {
|
||||||
const href = encodeURI(`./${path}.html`);
|
return encodeURI(`./${path}.html`);
|
||||||
return a({ href }, ...formatNameToInline(path));
|
|
||||||
}
|
}
|
||||||
|
|
5
drip.css
5
drip.css
|
@ -15,13 +15,10 @@ body {
|
||||||
padding: 1rem;
|
padding: 1rem;
|
||||||
}
|
}
|
||||||
|
|
||||||
article header {
|
header {
|
||||||
margin: 2rem 0;
|
margin: 2rem 0;
|
||||||
text-align: center;
|
text-align: center;
|
||||||
}
|
}
|
||||||
article h1 {
|
|
||||||
font-size: 32px;
|
|
||||||
}
|
|
||||||
|
|
||||||
h2 {
|
h2 {
|
||||||
border-bottom: var(--foreground) solid 1px;
|
border-bottom: var(--foreground) solid 1px;
|
||||||
|
|
|
@ -19,7 +19,7 @@
|
||||||
"typescript": "^4.9.4"
|
"typescript": "^4.9.4"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@nulo/html.js": "^0.0.8",
|
"@nulo/html.js": "^0.0.7",
|
||||||
"commonmark": "^0.30.0"
|
"commonmark": "^0.30.0"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
lockfileVersion: 5.4
|
lockfileVersion: 5.4
|
||||||
|
|
||||||
specifiers:
|
specifiers:
|
||||||
'@nulo/html.js': ^0.0.8
|
'@nulo/html.js': ^0.0.7
|
||||||
'@types/commonmark': ^0.27.5
|
'@types/commonmark': ^0.27.5
|
||||||
'@types/node': ^18.11.18
|
'@types/node': ^18.11.18
|
||||||
commonmark: ^0.30.0
|
commonmark: ^0.30.0
|
||||||
|
@ -9,7 +9,7 @@ specifiers:
|
||||||
typescript: ^4.9.4
|
typescript: ^4.9.4
|
||||||
|
|
||||||
dependencies:
|
dependencies:
|
||||||
'@nulo/html.js': 0.0.8
|
'@nulo/html.js': 0.0.7
|
||||||
commonmark: 0.30.0
|
commonmark: 0.30.0
|
||||||
|
|
||||||
devDependencies:
|
devDependencies:
|
||||||
|
@ -218,8 +218,8 @@ packages:
|
||||||
dev: true
|
dev: true
|
||||||
optional: true
|
optional: true
|
||||||
|
|
||||||
/@nulo/html.js/0.0.8:
|
/@nulo/html.js/0.0.7:
|
||||||
resolution: {integrity: sha512-fi2VrrdTx2ivWPyUuZpnuBxelGoxWzbvyo/iki222AfYlPa9/xMwAXz+9q8vdtHOP5/3E/z30YDp+Sq5TkRZhg==, tarball: https://gitea.nulo.in/api/packages/Nulo/npm/%40nulo%2Fhtml.js/-/0.0.8/html.js-0.0.8.tgz}
|
resolution: {integrity: sha512-4xzxbrovLRlS36RrQx9AtEc6OQZSIOK1cWuda7AYQFv3aQSkGAIuEgJK3FvvtgHMIi9AOcQuD/T9c9VpK4NAkA==, tarball: https://gitea.nulo.in/api/packages/Nulo/npm/%40nulo%2Fhtml.js/-/0.0.7/html.js-0.0.7.tgz}
|
||||||
dev: false
|
dev: false
|
||||||
|
|
||||||
/@types/commonmark/0.27.5:
|
/@types/commonmark/0.27.5:
|
||||||
|
|
Reference in a new issue