@p10i/flowmatter 0.1.2 → 0.1.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/index.mjs +4 -3
- package/src/serve.mjs +9 -7
package/package.json
CHANGED
package/src/index.mjs
CHANGED
|
@@ -287,8 +287,8 @@ export async function resolveMarkdownInputs(input, cwd) {
|
|
|
287
287
|
return {baseDir, markdownFiles};
|
|
288
288
|
}
|
|
289
289
|
|
|
290
|
-
async function readDocuments(input, cwd) {
|
|
291
|
-
const {baseDir, markdownFiles} = await resolveMarkdownInputs(input, cwd);
|
|
290
|
+
async function readDocuments(input, cwd, resolvedInputs) {
|
|
291
|
+
const {baseDir, markdownFiles} = resolvedInputs ?? await resolveMarkdownInputs(input, cwd);
|
|
292
292
|
|
|
293
293
|
const sources = await Promise.all(markdownFiles.map(async (sourcePath) => {
|
|
294
294
|
const relativePath = toPosix(path.relative(baseDir, sourcePath));
|
|
@@ -536,6 +536,7 @@ function renderPage(document, documents, byId) {
|
|
|
536
536
|
|
|
537
537
|
export async function renderSite({
|
|
538
538
|
input,
|
|
539
|
+
resolvedInputs,
|
|
539
540
|
outputDir = "flowmatter-dist",
|
|
540
541
|
flowFile = "flow.html",
|
|
541
542
|
title,
|
|
@@ -549,7 +550,7 @@ export async function renderSite({
|
|
|
549
550
|
throw new FlowmatterError("The title must be a non-empty string");
|
|
550
551
|
}
|
|
551
552
|
|
|
552
|
-
const { baseDir, documents, relationTypes, moduleTypes } = await readDocuments(input, path.resolve(cwd));
|
|
553
|
+
const { baseDir, documents, relationTypes, moduleTypes } = await readDocuments(input, path.resolve(cwd), resolvedInputs);
|
|
553
554
|
const outputRoot = path.resolve(cwd, outputDir);
|
|
554
555
|
const flowPath = path.join(outputRoot, flowFile);
|
|
555
556
|
for (const document of documents) {
|
package/src/serve.mjs
CHANGED
|
@@ -7,24 +7,26 @@ import {renderSite, resolveMarkdownInputs} from './index.mjs';
|
|
|
7
7
|
// work for globs as well as directories on bind-mounted filesystems.
|
|
8
8
|
export async function serveSite({input, cwd = process.cwd(), title, flowFile = 'flow.html', port = 4173,
|
|
9
9
|
interval = 500, log = console.error}) {
|
|
10
|
-
async function fingerprint() {
|
|
11
|
-
const {markdownFiles} = await resolveMarkdownInputs(input, cwd);
|
|
10
|
+
async function fingerprint({markdownFiles}) {
|
|
12
11
|
return JSON.stringify(await Promise.all(markdownFiles.map(async file => {
|
|
13
12
|
const s = await stat(file, {bigint:true});
|
|
14
13
|
return [file, String(s.ino), String(s.size), String(s.ctimeNs), String(s.mtimeNs)];
|
|
15
14
|
})));
|
|
16
15
|
}
|
|
17
|
-
async function render() {
|
|
18
|
-
const site = await renderSite({
|
|
16
|
+
async function render(resolvedInputs) {
|
|
17
|
+
const site = await renderSite({resolvedInputs,cwd,title,flowFile});
|
|
19
18
|
return new Map(site.outputs.map(({path:file,content}) => ['/' + path.relative(site.outputDir,file).split(path.sep).join('/'),content]));
|
|
20
19
|
}
|
|
21
|
-
|
|
20
|
+
// The fingerprint and rendered pages must describe the same set of files.
|
|
21
|
+
const initial = await resolveMarkdownInputs(input, cwd);
|
|
22
|
+
let seen = await fingerprint(initial), pages = await render(initial), stopped = false, timer, lastError;
|
|
22
23
|
async function poll() {
|
|
23
24
|
try {
|
|
24
|
-
const
|
|
25
|
+
const inputs = await resolveMarkdownInputs(input, cwd);
|
|
26
|
+
const next = await fingerprint(inputs);
|
|
25
27
|
if (next !== seen) {
|
|
26
28
|
seen = next;
|
|
27
|
-
pages = await render(); // Publish the entire new generation together.
|
|
29
|
+
pages = await render(inputs); // Publish the entire new generation together.
|
|
28
30
|
log(`Rebuilt ${pages.size - 1} pages`);
|
|
29
31
|
}
|
|
30
32
|
lastError = undefined;
|