Skip to content

Commit

Permalink
Use regex groups
Browse files Browse the repository at this point in the history
  • Loading branch information
amad-person committed Mar 26, 2019
1 parent e49f2b2 commit faeab48
Showing 1 changed file with 5 additions and 8 deletions.
13 changes: 5 additions & 8 deletions src/Site.js
Original file line number Diff line number Diff line change
Expand Up @@ -520,19 +520,16 @@ Site.prototype.addSiteNavToDefaultLayout = function () {
*/
Site.prototype.parseSidebarFileContent = function (rawSiteNavContent) {
let siteNavContent = '';
const doubleSquareBracketsFormatRegex = /\[\[.+\|{0,1}.?\]\]/g;
const doubleSquareBracketsFormatRegex = /\[\[([\w-]*)(\|)?([\w-]*)?\]\]/g;
const markdownLinkFormatRegex = /(?:__|[*#])|\[(.*?)\]\(.*?\)/g;
const baseUrlSubst = '{{baseUrl}}';
if (rawSiteNavContent.match(doubleSquareBracketsFormatRegex)) {
rawSiteNavContent.split('\n').forEach((navLine) => {
const nameStartIdx = navLine.indexOf('[[');
const linkStartIdx = navLine.indexOf('|');
const endIdx = navLine.indexOf(']]');
const name = linkStartIdx === -1
? navLine.substring(nameStartIdx + 2, endIdx) : navLine.substring(nameStartIdx + 2, linkStartIdx);
const link = linkStartIdx === -1 ? '' : navLine.substring(linkStartIdx + 1, endIdx);
const navLineGroups = doubleSquareBracketsFormatRegex.exec(navLine);
const name = navLineGroups[1];
const link = navLineGroups[2] === undefined ? '' : navLineGroups[3];
const newNavLine = link === ''
? `[${name}](${baseUrlSubst}/${name}.html)` : `[${baseUrlSubst}/${name}](${link}.html)`;
? `[${name}](${baseUrlSubst}/${name}.html)` : `[${name}](${baseUrlSubst}/${link}.html)`;
const finalNavLine = navLine.replace(doubleSquareBracketsFormatRegex, newNavLine);
siteNavContent += `${finalNavLine}\n`;
});
Expand Down

0 comments on commit faeab48

Please sign in to comment.