Fix broken link in markdown compilation (#2162)

* handle links to fleetdm.com

* Update build-static-content.js

* Update build-static-content.js

* update comment
This commit is contained in:
eashaw 2021-09-21 13:52:37 -05:00 committed by GitHub
parent 0b7ff6cd38
commit c1a795cff8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -226,13 +226,19 @@ module.exports = {
// to some page on the destination site where this will be hosted, like `(*.)?fleetdm.com`.
// If external, add target="_blank" so the link will open in a new tab.
let isExternal = ! hrefString.match(/^href=\"https?:\/\/([^\.]+\.)*fleetdm\.com/g);// « FUTURE: make this smarter with sails.config.baseUrl + _.escapeRegExp()
// Check if this link is to fleetdm.com or www.fleetdm.com.
let isBaseUrl = hrefString.match(/^(href="https?:\/\/)([^\.]+\.)*fleetdm\.com"$/g);
if (isExternal) {
return hrefString.replace(/(href="https?:\/\/([^"]+)")/g, '$1 target="_blank"');
} else {
// Otherwise, change the link to be web root relative.
// (e.g. 'href="http://sailsjs.com/documentation/concepts"'' becomes simply 'href="/documentation/concepts"'')
// > Note: See the Git version history of "compile-markdown-content.js" in the sailsjs.com website repo for examples of ways this can work across versioned subdomains.
return hrefString.replace(/href="https?:\/\//, '').replace(/^fleetdm\.com/, 'href="');
if (isBaseUrl) {
return hrefString.replace(/href="https?:\/\//, '').replace(/([^\.]+\.)*fleetdm\.com/, 'href="/');
} else {
return hrefString.replace(/href="https?:\/\//, '').replace(/^fleetdm\.com/, 'href="');
}
}
});//∞