From 23af3b21257a944714bf13149473ea1721516abb Mon Sep 17 00:00:00 2001 From: Milos Djermanovic Date: Wed, 18 May 2022 18:58:46 +0200 Subject: [PATCH] chore: keep `#` fragments in Further Reading links on new docs site --- docs/.eleventy.js | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/docs/.eleventy.js b/docs/.eleventy.js index b9e27c8fd7b..deeecd4fbc8 100644 --- a/docs/.eleventy.js +++ b/docs/.eleventy.js @@ -129,13 +129,27 @@ module.exports = function(eleventyConfig) { const the_url = (new URL(link)); // same as url const domain = the_url.hostname; + let href = metadata.url; + + /* + * Restore `#` fragment from the original link. At this point, the fragment may have been lost + * during the process if `got` encountered redirects or if `metascraper` has found URL in the HTML document. + */ + if (!href.includes("#")) { + const originalFragmentMatch = /#(?:.)+/u.exec(link); + + if (originalFragmentMatch) { + href += originalFragmentMatch[0]; + } + } + return `
Avatar image for ${domain}