Skip to content

Commit

Permalink
Add async check of the page should be compiled. This is needed for th…
Browse files Browse the repository at this point in the history
…e API pages in particular.
  • Loading branch information
Kapelianovych committed Dec 11, 2023
1 parent 51485cf commit 95043f5
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 0 deletions.
4 changes: 4 additions & 0 deletions lib/api-page.js
Original file line number Diff line number Diff line change
Expand Up @@ -306,4 +306,8 @@ export default class ApiPage extends Page {
commentsSourcePath: this.#apiFilePath,
});
}

async shouldCompile() {
return Boolean(await this.#parseApiFile());
}
}
24 changes: 24 additions & 0 deletions lib/collector.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,14 @@ export default class Collector {
AsyncIterable.filter((filePath) => !shouldIgnore(filePath)),
AsyncIterable.map((filePath) => this.#tryCreatingPage(filePath, ApiPage)),
AsyncIterable.filter(Boolean),
AsyncIterable.chain((page) =>
AsyncIterable.from(async function* () {
// We should be sure that the page has at least one comment.
if (await page.shouldCompile()) {
yield page;
}
}),
),
);
}

Expand All @@ -118,6 +126,14 @@ export default class Collector {
this.#tryCreatingPage(filePath, RegularPage, markdownCompiler),
),
AsyncIterable.filter(Boolean),
AsyncIterable.chain((page) =>
AsyncIterable.from(async function* () {
// We should be sure that the page has at least one comment.
if (await page.shouldCompile()) {
yield page;
}
}),
),
);
}

Expand All @@ -135,6 +151,14 @@ export default class Collector {
this.#tryCreatingPage(filePath, LayoutPage),
),
AsyncIterable.filter(Boolean),
AsyncIterable.chain((page) =>
AsyncIterable.from(async function* () {
// We should be sure that the page has at least one comment.
if (await page.shouldCompile()) {
yield page;
}
}),
),
);
}

Expand Down
6 changes: 6 additions & 0 deletions lib/page.js
Original file line number Diff line number Diff line change
Expand Up @@ -132,4 +132,10 @@ export default class Page {

await writeFile(this.#outputFilePath, compiledPage, "utf8");
}

// Override this method if a page has to perform some checks
// after creation to be sure that it is legit.
async shouldCompile() {
return true;
}
}

0 comments on commit 95043f5

Please sign in to comment.