Use a dist
method
This commit is contained in:
parent
0405a90907
commit
4bf647701a
|
@ -2,6 +2,8 @@ import { Observable, from, map, mergeAll } from "rxjs";
|
||||||
import File from "vinyl";
|
import File from "vinyl";
|
||||||
import { Glob } from "glob";
|
import { Glob } from "glob";
|
||||||
import { readFile } from "node:fs/promises";
|
import { readFile } from "node:fs/promises";
|
||||||
|
import { join, dirname } from "node:path";
|
||||||
|
import { existsSync, mkdirSync, writeFileSync } from "node:fs";
|
||||||
|
|
||||||
export function src(glob: string | string[]): Observable<File> {
|
export function src(glob: string | string[]): Observable<File> {
|
||||||
return from(new Glob(glob, {})).pipe(
|
return from(new Glob(glob, {})).pipe(
|
||||||
|
@ -11,6 +13,27 @@ export function src(glob: string | string[]): Observable<File> {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function dist(prefix: string) {
|
||||||
|
return (observable: Observable<File>): Observable<File> =>
|
||||||
|
new Observable((subscriber) =>
|
||||||
|
observable.subscribe({
|
||||||
|
next(value) {
|
||||||
|
const actualPath = join(prefix, value.path);
|
||||||
|
if (!existsSync(dirname(actualPath))) {
|
||||||
|
mkdirSync(dirname(actualPath), { recursive: true });
|
||||||
|
}
|
||||||
|
writeFileSync(actualPath, value.contents as Buffer);
|
||||||
|
console.log("[-] Written", actualPath);
|
||||||
|
|
||||||
|
subscriber.next(value);
|
||||||
|
},
|
||||||
|
complete() {
|
||||||
|
subscriber.complete();
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
export function synchronise<T>() {
|
export function synchronise<T>() {
|
||||||
return (observable: Observable<Promise<T>>): Observable<T> =>
|
return (observable: Observable<Promise<T>>): Observable<T> =>
|
||||||
new Observable<T>((subscriber) => {
|
new Observable<T>((subscriber) => {
|
||||||
|
|
|
@ -12,14 +12,14 @@ import { PRODUCTION, DEFAULT_DATE } from "../environment.js";
|
||||||
import rehypeExternalLinks from "rehype-external-links";
|
import rehypeExternalLinks from "rehype-external-links";
|
||||||
import visit from "unist-util-visit";
|
import visit from "unist-util-visit";
|
||||||
import renderLayout from "../views/layout.js";
|
import renderLayout from "../views/layout.js";
|
||||||
import renderArticleLayout from "../views/article.js";
|
import renderArticleLayout, { Article } from "../views/article.js";
|
||||||
import renderIndex from "../views/index.js";
|
import renderIndex from "../views/index.js";
|
||||||
import { renderToStaticMarkup } from "preact-render-to-string";
|
import { renderToStaticMarkup } from "preact-render-to-string";
|
||||||
import { SITE_TITLE, SITE_DESCRIPTION } from "../constants.js";
|
import { SITE_TITLE, SITE_DESCRIPTION } from "../constants.js";
|
||||||
import { JSX } from "preact/jsx-runtime";
|
import { JSX } from "preact/jsx-runtime";
|
||||||
import { reloadAssets } from "../assets.js";
|
import { reloadAssets } from "../assets.js";
|
||||||
import { map, toArray, lastValueFrom } from "rxjs";
|
import { map, lastValueFrom } from "rxjs";
|
||||||
import { src, synchronise } from "../rx-utils.js";
|
import { src, synchronise, dist } from "../rx-utils.js";
|
||||||
|
|
||||||
const Asciidoctor = asciidoctor();
|
const Asciidoctor = asciidoctor();
|
||||||
const EXTENSION_REGISTRY = Asciidoctor.Extensions.create();
|
const EXTENSION_REGISTRY = Asciidoctor.Extensions.create();
|
||||||
|
@ -70,9 +70,10 @@ const output = (prefix: string) => (file: File) => {
|
||||||
export async function articles(): Promise<void> {
|
export async function articles(): Promise<void> {
|
||||||
reloadAssets();
|
reloadAssets();
|
||||||
const _output = output("dist");
|
const _output = output("dist");
|
||||||
|
const articles: Article[] = [];
|
||||||
const images: File[] = [];
|
const images: File[] = [];
|
||||||
|
|
||||||
const articles = await lastValueFrom(
|
await lastValueFrom(
|
||||||
src("articles/**/*.asciidoc").pipe(
|
src("articles/**/*.asciidoc").pipe(
|
||||||
map(async (file) => {
|
map(async (file) => {
|
||||||
const slug = basename(file.path, ".asciidoc");
|
const slug = basename(file.path, ".asciidoc");
|
||||||
|
@ -116,15 +117,12 @@ export async function articles(): Promise<void> {
|
||||||
file.path = join(slug, "index.html");
|
file.path = join(slug, "index.html");
|
||||||
file.contents = renderDocument(content);
|
file.contents = renderDocument(content);
|
||||||
|
|
||||||
_output(file);
|
return file;
|
||||||
|
|
||||||
return article;
|
|
||||||
}),
|
}),
|
||||||
synchronise(),
|
synchronise(),
|
||||||
toArray(),
|
dist("dist"),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
|
||||||
images.forEach(_output);
|
images.forEach(_output);
|
||||||
|
|
||||||
articles.sort(({ date: a }, { date: b }) => b.diff(a).toMillis());
|
articles.sort(({ date: a }, { date: b }) => b.diff(a).toMillis());
|
||||||
|
@ -135,7 +133,7 @@ export async function articles(): Promise<void> {
|
||||||
"og:type": "website",
|
"og:type": "website",
|
||||||
"og:url": `https://adaedra.eu`,
|
"og:url": `https://adaedra.eu`,
|
||||||
},
|
},
|
||||||
Content: () => renderIndex({ articles }),
|
Content: () => renderIndex({ articles: articles }),
|
||||||
});
|
});
|
||||||
|
|
||||||
_output(
|
_output(
|
||||||
|
|
Loading…
Reference in New Issue
Block a user