diff --git a/packages/mastodon/lib/replace.js b/packages/mastodon/lib/replace.js index 17f9a24..f6c2339 100644 --- a/packages/mastodon/lib/replace.js +++ b/packages/mastodon/lib/replace.js @@ -28,7 +28,7 @@ module.exports = async function(match, config) { /** If getting the oEmbed failed, just return the original match unchanged */ if (!oembedHtml) { - return match; + return match[0]; } return `
${oembedHtml}
`; @@ -41,7 +41,6 @@ module.exports = async function(match, config) { * @param {string} id - Status ID. * @returns {string|null} - URL of the status. * @see https://docs.joinmastodon.org/methods/statuses/#get - * @todo Better error handling. */ async function _getFederatedStatus(hostname, id) { if (!hostname || !id) { @@ -69,7 +68,6 @@ async function _getFederatedStatus(hostname, id) { * @param {object} config - Configuration object for the Mastodon embed. * @returns {string|null} - HTML to embed the status. * @see https://docs.joinmastodon.org/methods/oembed/ - * @todo Better error handling. */ async function _getOriginOembed(hostname, url) { if(!hostname || !url) { diff --git a/packages/mastodon/test/replace.test.mjs b/packages/mastodon/test/replace.test.mjs index 1f98c3b..afc5a5c 100644 --- a/packages/mastodon/test/replace.test.mjs +++ b/packages/mastodon/test/replace.test.mjs @@ -99,7 +99,16 @@ describe('Returns expected HTML', () => { const expectedOEmbed = "
Post by @eleventy@fosstodon.org
View on Mastodon
" - it('Base case', async () => { + it('Origin server status', async () => { + const config = merge(defaults, {server: 'fosstodon.org'}); + const pattern = patternGenerator(config.server); + const content = "

https://fosstodon.org/@eleventy/113198584376721364

"; + + const output = await asyncReplace(content, pattern, (...match) => replace(match, config)); + expect(output).toBe(expectedOEmbed); + }); + + it('Federated server status', async () => { const config = merge(defaults, {server: 'social.vivaldi.net'}); const pattern = patternGenerator(config.server); const content = "

https://social.vivaldi.net/@eleventy@fosstodon.org/113198584572922516

";