added serve.js section
This commit is contained in:
@@ -33,6 +33,35 @@ node engine/gen.mjs [--src <dir>] [--target <file>]
|
||||
5. **Manifest Emission**: Generates static ES module imports for every markdown card, maps out metadata items (slug, id, imported content reference), serializes the sorted tag list, and writes the complete bundle to the target path.
|
||||
|
||||
|
||||
# worker handler
|
||||
|
||||
This module acts as the edge runtime request handler, injecting application data and metadata into an HTML shell to serve the client-side application.
|
||||
|
||||
## Usage
|
||||
|
||||
```javascript
|
||||
import { handler } from "./handler.mjs";
|
||||
// Called within an edge worker / serverless fetch event handler
|
||||
return handler(CARDS, TAGS, TITLE);
|
||||
```
|
||||
|
||||
* **`CARDS`**: The compiled array of card objects, serialized and injected into the global scope.
|
||||
* **`TAGS`**: The sorted array of tag vocabulary strings, serialized and injected alongside cards.
|
||||
* **`TITLE`**: The site or page title string injected into the HTML title placeholder.
|
||||
|
||||
## Core Principles
|
||||
|
||||
* **Data Injection**: Serializes the `CARDS` collection and `TAGS` vocabulary into JavaScript assignment statements (`window.__CARDS__` and `window.__TAGS__`) to hydrate the client-side environment on load.
|
||||
* **Safe String Replacement**: Utilizes functional replacement patterns (`() => ...`) within string replacement methods to prevent unintended `$` pattern or special character interpretation.
|
||||
* **Response Generation**: Constructs and returns a standard HTTP `Response` object containing the fully assembled HTML payload with the proper UTF-8 content-type header.
|
||||
|
||||
## Workflow Execution
|
||||
|
||||
1. **Payload Construction**: Generates global window assignment strings containing the JSON stringified representations of the card collection and tag vocabulary.
|
||||
2. **Template Hydration**: Imports the raw HTML template (`app.html`), safely replacing the `__TITLE__` token with the provided title value and the `/*__DATA__*/` comment placeholder with the injected data script.
|
||||
3. **HTTP Response Dispatch**: Wraps the finalized HTML string in a `Response` instance with `text/html; charset=utf-8` headers ready for edge delivery.
|
||||
4.
|
||||
|
||||
# emit.mjs
|
||||
|
||||
`emit.mjs` is the deployment adapter projection engine. It reconciles engine-level deployment templates with target-specific instance directories, preserving user configuration while propagating structural template updates.
|
||||
|
||||
Reference in New Issue
Block a user