Skip to content

Commit

Permalink
new afterLoad event
Browse files Browse the repository at this point in the history
  • Loading branch information
oscarotero committed May 9, 2024
1 parent ae0e7df commit e096e36
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ Go to the `v1` branch to see the changelog of Lume 1.
- New middleware `shutdown`.
- Esbuild plugin: support for `jsr:` specifiers.
- New `Lume.Loader` type.
- New `afterLoad` event, triggered just after all files are (re)loaded.

### Changed
- The minimum Deno version supported is `1.43`.
Expand Down
14 changes: 12 additions & 2 deletions core/site.ts
Original file line number Diff line number Diff line change
Expand Up @@ -488,6 +488,10 @@ export default class Site {
// Load source files
this.fs.init();

if (await this.dispatchEvent({ type: "afterLoad" }) === false) {
return;
}

// Get the site content
const showDrafts = env<boolean>("LUME_DRAFTS");
const [_pages, _staticFiles] = await this.source.build(
Expand Down Expand Up @@ -547,6 +551,10 @@ export default class Site {
await this.writer.removeFiles([...pages, ...files]);
}

if (await this.dispatchEvent({ type: "afterLoad" }) === false) {
return;
}

// Get the site content
const showDrafts = env<boolean>("LUME_DRAFTS");
const [_pages, _staticFiles] = await this.source.build(
Expand Down Expand Up @@ -927,6 +935,8 @@ export interface ComponentsOptions {
}

export type SiteEventMap = {
// deno-lint-ignore ban-types
afterLoad: {};
beforeBuild: {
/** the list of pages that have been saved */
pages: Page[];
Expand All @@ -950,11 +960,11 @@ export type SiteEventMap = {
staticFiles: StaticFile[];
};
beforeRender: {
/** the list of pages that have been saved */
/** the list of pages that are about to render */
pages: Page[];
};
afterRender: {
/** the list of pages that have been saved */
/** the list of pages that have been rendered */
pages: Page[];
};
beforeRenderOnDemand: {
Expand Down

0 comments on commit e096e36

Please sign in to comment.