Fix broken links and duplicate IDs on fleetdm.com/docs (#2426)
* update heading renderer, fix links to blog.fleetdm.com * inverted conditional, using ensureUniq
This commit is contained in:
+8
-1
@@ -75,8 +75,15 @@ module.exports = {
|
||||
};
|
||||
if (inputs.addIdsToHeadings === true) {
|
||||
var headingRenderer = new marked.Renderer();
|
||||
var headingsRenderedOnThisPage = [];
|
||||
headingRenderer.heading = function (text, level) {
|
||||
var headingID = _.kebabCase(text);
|
||||
var headingID = _.kebabCase(_.unescape(text).replace(/[\’\']/g, ''));
|
||||
if(!_.contains(headingsRenderedOnThisPage, headingID)){
|
||||
headingsRenderedOnThisPage.push(headingID);
|
||||
} else {
|
||||
headingID = sails.helpers.strings.ensureUniq(headingID, headingsRenderedOnThisPage);
|
||||
headingsRenderedOnThisPage.push(headingID);
|
||||
}
|
||||
return '<h'+level+' class="markdown-heading" id="'+headingID+'">'+text+'<a href="#'+headingID+'" class="markdown-link"></a></h'+level+'>\n';
|
||||
};
|
||||
markedOpts.renderer = headingRenderer;
|
||||
|
||||
+3
-1
@@ -229,10 +229,12 @@ module.exports = {
|
||||
// Check if this is an external link (like https://google.com) but that is ALSO not a link
|
||||
// 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()
|
||||
// Note: links to blog.fleetdm.com will be treated as an external link.
|
||||
let isExternal = ! hrefString.match(/^href=\"https?:\/\/([^\.|blog]+\.)*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.
|
||||
|
||||
Reference in New Issue
Block a user