-
Notifications
You must be signed in to change notification settings - Fork 133
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Refactor baseUrl into variablePreprocessor #1239
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
const cheerio = require('cheerio'); | ||
const cheerio = require('cheerio'); require('./lib/markbind/src/patches/htmlparser2'); | ||
const fs = require('fs-extra-promise'); | ||
const ghpages = require('gh-pages'); | ||
const ignore = require('ignore'); | ||
|
@@ -11,6 +11,7 @@ const njUtil = require('./lib/markbind/src/utils/nunjuckUtils'); | |
const injectHtmlParser2SpecialTags = require('./lib/markbind/src/patches/htmlparser2'); | ||
const injectMarkdownItSpecialTags = require( | ||
'./lib/markbind/src/lib/markdown-it/markdown-it-escape-special-tags'); | ||
const utils = require('./lib/markbind/src/utils'); | ||
|
||
const _ = {}; | ||
_.difference = require('lodash/difference'); | ||
|
@@ -524,8 +525,6 @@ class Site { | |
* Collects the user defined variables map in the site/subsites | ||
*/ | ||
collectUserDefinedVariablesMap() { | ||
// The key is the base directory of the site/subsites, | ||
// while the value is a mapping of user defined variables | ||
this.variablePreprocessor.resetUserDefinedVariablesMap(); | ||
|
||
this.baseUrlMap.forEach((base) => { | ||
|
@@ -540,13 +539,17 @@ class Site { | |
} | ||
|
||
/* | ||
This is to prevent the first nunjuck call from converting {{baseUrl}} to an empty string | ||
and let the baseUrl value be injected later. | ||
We retrieve the baseUrl of the (sub)site by appending the relative to the configured base url | ||
i.e. We ignore the configured baseUrl of the sub sites. | ||
*/ | ||
this.variablePreprocessor.addUserDefinedVariable(base, 'baseUrl', '{{baseUrl}}'); | ||
const siteRelativePathFromRoot = utils.ensurePosix(path.relative(this.rootPath, base)); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is the main functional change, the rest are just necessary changes due to the tight coupling of We simply add the correct baseUrl for each (sub)site as a variable directly into |
||
const siteBaseUrl = siteRelativePathFromRoot === '' | ||
? this.siteConfig.baseUrl | ||
: path.posix.join(this.siteConfig.baseUrl || '/', siteRelativePathFromRoot); | ||
this.variablePreprocessor.addUserDefinedVariable(base, 'baseUrl', siteBaseUrl); | ||
this.variablePreprocessor.addUserDefinedVariable(base, 'MarkBind', MARKBIND_LINK_HTML); | ||
|
||
const $ = cheerio.load(content); | ||
const $ = cheerio.load(content, { decodeEntities: false }); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
$('variable,span').each((index, element) => { | ||
const name = $(element).attr('name') || $(element).attr('id'); | ||
const variableSource = $(element).attr('from'); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,5 @@ | ||
module.exports = { | ||
// src/lib/markbind/src/parser.js | ||
ATTRIB_INCLUDE_PATH: 'include-path', | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. previously used for |
||
ATTRIB_CWF: 'cwf', | ||
|
||
BOILERPLATE_FOLDER_NAME: '_markbind/boilerplates', | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
added this in all files to ensure unit tests load the patch, which is more than ever important with the extra 2 "patches" for
recognizeSelfClosing
andlowerCaseAttributeNames