diff --git a/src/utils/embed-handler.js b/src/utils/embed-handler.js index bd30a72ed..a8926597d 100644 --- a/src/utils/embed-handler.js +++ b/src/utils/embed-handler.js @@ -13,11 +13,14 @@ * Handles `embed` MDAST nodes by converting them into `` tags * @param {string} EMBED_SERVICE the URL of an embedding service compatible with https://github.com/adobe/helix-embed that returns HTML */ +const URI = require('uri-js'); + function embed({ EMBED_SERVICE }) { return function handler(h, node) { const { url } = node; const props = { - src: EMBED_SERVICE + url, + // prepend the embed service for absolute URLs + src: (URI.parse(url).reference === 'absolute' ? EMBED_SERVICE : '') + url, }; const retval = h(node, 'esi:include', props); return retval; diff --git a/test/testEmbedHandler.js b/test/testEmbedHandler.js index b1a87195c..60293c6c4 100644 --- a/test/testEmbedHandler.js +++ b/test/testEmbedHandler.js @@ -122,6 +122,36 @@ https://www.youtube.com/watch?v=KOxbO0EI4MA assert.equal(result.response.body, `

Hello World Here comes an embed.

+

Easy!

`); + }); + + it('html.pipe processes internal embeds', async () => { + const result = await pipe( + ({ content }) => ({ response: { status: 201, body: content.document.body.innerHTML } }), + { + request: crequest, + content: { + body: `Hello World +Here comes an embed. + +./foo.md + +![Easy!](easy.png) +`, + }, + }, + { + request: { params }, + secrets, + logger, + }, + ); + + assert.equal(result.response.status, 201); + assert.equal(result.response.headers['Content-Type'], 'text/html'); + assert.equal(result.response.body, `

Hello World +Here comes an embed.

+

Easy!

`); }); });