Skip to content

Commit

Permalink
Fix: Fix rule links
Browse files Browse the repository at this point in the history
  • Loading branch information
qzhou1607-zz committed Feb 20, 2018
1 parent fab9134 commit 1964a11
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/sonarwhal-theme/scripts/link-filter.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,16 @@ hexo.extend.filter.register('before_post_render', (data) => {
matchHtmlUrl = matchHtmlUrl.replace(/\((.*?)\)/g, '(../$1)');
}

// ../../../../rule-axe/README/ => rule-axe
// ../../../../rule-axe/README/ => rule-axe/
const matchRuleUrl = matchHtmlUrl.match(ruleUrlRegex);
const newUrl = isRulePage && matchRuleUrl ? `(${matchRuleUrl.pop()}/)` : matchHtmlUrl;

data.content = data.content.replace(matchMdUrl, newUrl);
// Offset `lastIndex` due to the length change after string replacement:
// Before replacement: ... (../../../../rule-amp-validator/README.md)...
// The index to start next match (lastIndex): 619
// After replacement: ... (rule-amp-validator/) ...
// The actual index to start the next match: 619 - (before.length - after.length) = 598
mdUrlRegex.lastIndex -= matchMdUrl.length - newUrl.length;
}
});

0 comments on commit 1964a11

Please sign in to comment.