Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3,070 changes: 2,937 additions & 133 deletions package-lock.json

Large diffs are not rendered by default.

5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@
},
"dependencies": {
"@adobe/fetch": "4.3.0",
"@adobe/helix-html-pipeline": "6.29.6",
"@adobe/helix-html2md": "2.2.2",
"@adobe/helix-log": "7.0.0",
"@adobe/helix-shared-config": "11.1.28",
"@adobe/helix-shared-git": "3.0.25",
Expand All @@ -62,7 +64,6 @@
"faye-websocket": "0.11.4",
"fs-extra": "11.3.5",
"glob": "13.0.6",
"glob-to-regexp": "0.4.1",
"hast-util-select": "6.0.4",
"hast-util-to-html": "9.0.5",
"http-proxy-agent": "9.1.0",
Expand All @@ -71,8 +72,8 @@
"ini": "7.0.0",
"isomorphic-git": "1.38.5",
"jose": "6.2.3",
"mime": "4.1.0",
"livereload-js": "4.0.2",
"mime": "4.1.0",
"node-diff3": "3.2.1",
"node-fetch": "3.3.2",
"open": "11.0.0",
Expand Down
135 changes: 135 additions & 0 deletions src/content/content-html-pipeline.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
/*
* Copyright 2026 Adobe. All rights reserved.
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. You may obtain a copy
* of the License at http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
* OF ANY KIND, either express or implied. See the License for the specific language
* governing permissions and limitations under the License.
*/

/**
* Renders da.live-authored content HTML from `content/` through the
* `html2md` -> `helix-html-pipeline` markdown-rendering chain, run locally by calling
* `htmlPipe()` (the same entry point production uses) against a hand-built minimal pipeline
* state and a fake in-memory content-bus loader.
*/

import { html2md } from '@adobe/helix-html2md';
import {
PipelineState, PipelineRequest, PipelineResponse, htmlPipe,
} from '@adobe/helix-html-pipeline';

/**
* `htmlPipe` treats a literal `.html` path (no selector) as a code-bus (statically deployed)
* resource and skips markdown rendering entirely -- production only ever requests pages at
* extension-less paths (`/foo`), reserving `.html` for real static files. `.plain.html` is
* exempt: its `plain` selector already routes through the content-bus/markdown branch.
* @param {string} path
* @returns {string}
*/
function toContentPath(path) {
if (path.endsWith('.plain.html')) {
return path;
}
const clean = path.endsWith('.html') ? path.slice(0, -'.html'.length) : path;
// a literal "index" path segment is a reserved internal artifact -- fetchContent rejects it
// outright, so an index document maps back to its containing directory, same as "/".
if (clean.endsWith('/index')) {
return clean.slice(0, -'index'.length) || '/';
}
return clean;
}

/**
* A minimal `s3Loader` stand-in. With no folder mapping configured, `htmlPipe` only ever
* makes two content-bus lookups: the page's own markdown, and (if configured) the
* metadata.json sheet for the `fetchSourcedMetadata` step.
* @param {string} md
* @param {object[]} metadataSheetRows
* @returns {object}
*/
function createLocalLoader(md, metadataSheetRows) {
return {
async getObject(bucketId, key) {
if (bucketId === 'helix-content-bus' && key.endsWith('/metadata.json')) {
if (metadataSheetRows.length > 0) {
return new PipelineResponse(JSON.stringify({ data: metadataSheetRows }));
}
return new PipelineResponse('', { status: 404 });
}
if (bucketId === 'helix-content-bus') {
return new PipelineResponse(md);
}
return new PipelineResponse('', { status: 404 });
},
async headObject() {
return new PipelineResponse('', { status: 404 });
},
};
}

/**
* @param {string} rawHtml body-only or partial HTML from content/, as stored by da.live
* @param {object} [options]
* @param {string} [options.path] request path, e.g. `/foo.html` or `/foo.plain.html`
* @param {Console} [options.log]
* @param {string} [options.headHtml] local head.html content, injected into <head>
* @param {object[]} [options.metadataSheetRows] raw rows from the site's /metadata.json, fed
* through the same `fetchSourcedMetadata` step production uses to build sheet-based
* metadata overrides
* @param {object} [options.headers] incoming request headers (e.g. `req.headers`), used to
* resolve a real host for canonical/og:url instead of a placeholder
* @param {string} [options.org] the AEM org this content belongs to, if known
* @param {string} [options.site] the AEM site this content belongs to, if known
* @returns {Promise<string | null>} the rendered HTML (full document, or a bare fragment for
* `.plain.html` paths), or `null` if rendering failed and the caller should fall back to
* serving the raw file
*/
export async function renderContentHtml(rawHtml, {
path = '/index.html',
log = console,
headHtml = '',
metadataSheetRows = [],
headers = {},
org = 'local',
site = 'local',
} = {}) {
try {
const md = await html2md(rawHtml, { log, url: new URL(path, 'http://localhost').href });

const contentPath = toContentPath(path);
const state = new PipelineState({
path: contentPath,
log,
org: org || 'local',
site: site || 'local',
ref: 'local',
partition: 'preview',
s3Loader: createLocalLoader(md, metadataSheetRows),
config: {
contentBusId: 'local',
owner: 'local',
repo: 'local',
cdn: {},
metadata: { source: ['metadata.json'] },
headers: {},
features: { rendering: { version: 2 } },
head: { html: headHtml },
},
});

const req = new PipelineRequest(new URL(contentPath, 'http://localhost'), { headers });
const res = await htmlPipe(state, req);
if (res.error) {
log.warn?.(`content-html-pipeline: failed to render ${path}: ${res.error}`);
return null;
}
return res.body;
} catch (e) {
log.warn?.(`content-html-pipeline: failed to render ${path}: ${e.message}`);
return null;
}
}
Loading
Loading