-
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
Support content insertion into <head> of a Page #361
Conversation
<head>
of a Page
Update
|
lib/Page.js
Outdated
const userDefinedVariables = this.userDefinedVariablesMap[path.join(this.rootPath, newBaseUrl)]; | ||
const headFileMappedData = nunjucks.renderString(headFileContent, userDefinedVariables); | ||
this.headFileReferences = headFileMappedData.trim(); | ||
return pageData; |
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.
Seems like the pageData
is not used at all in this method, so it is not necessary.
Therefore, we can call this method before the line this.headFileReferences = nunjucks.renderString(this.headFileReferences, { baseUrl, hostBaseUrl });
instead of doing .then(result => this.collectHeadFiles(result))
.
lib/Page.js
Outdated
// Map variables | ||
const newBaseUrl = calculateNewBaseUrl(this.sourcePath, this.rootPath, this.baseUrlMap) || ''; | ||
const userDefinedVariables = this.userDefinedVariablesMap[path.join(this.rootPath, newBaseUrl)]; | ||
const headFileMappedData = nunjucks.renderString(headFileContent, userDefinedVariables); |
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.
Is this rendering necessary? Seems to still work for me when I commented it out. Also the render method seems to be called again below.
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.
It is useful if the user predefined a <style>
or <link>
variable and used it in headFile.md
.
The render method below is specifically for resolving {{baseUrl}}
.
docs/userGuide/contentAuthoring.md
Outdated
@@ -375,6 +375,50 @@ Front matter can also be included from a separate file, just like how content ca | |||
|
|||
This will result in `index.md` having the title `Binary Search Tree` and the specified keywords in order for it to be looked up through the search bar. | |||
|
|||
### Inserting content into a page's head element | |||
|
|||
While authoring your website, you may want to have your own CSS or Javascript file to be included in a page. |
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.
file
-> files
docs/userGuide/contentAuthoring.md
Outdated
- More than one head file can be created for different pages. | ||
|
||
- Author your `<style>` elements for CSS files and `<link>` elements for Javascript files using HTML as shown below. | ||
- Ensure that any url starts from the root directory <code>{<span></span>{baseUrl}}/</code> when you are referencing your files. |
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.
Ensure that any url starts...
-> Ensure that your URLs start...
... from the root directory {{baseUrl}} ...
-> ... from the root directory, by using {{baseUrl}} ...
docs/userGuide/contentAuthoring.md
Outdated
<script src="{{baseUrl}}/yourScriptFolder/myCustomScript.js"></script> | ||
``` | ||
|
||
- Specify the head file in pages that you want it, within the [front matter](#front-matter) `head` attribute. |
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.
...that you want it, within the...
-> ...that uses it, by specifying the...
docs/userGuide/contentAuthoring.md
Outdated
``` | ||
|
||
The head file contents will be placed near the end of the page's head tag. | ||
It will override existing Bootstrap and MarkBind CSS styles if there is an overlap. |
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.
It will...
-> Your head file will...
there is an overlap
-> there is an overlap of classes
.
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.
... overlap of classes -> ... overlap of selectors
Also by any chance, is it possible to support live preview for changes to the |
Update
|
|
||
```html | ||
<!-- In _markbind/head/compiledRef.md --> | ||
<link rel="stylesheet" href="{{baseUrl}}/yourCSSFolder/subfolder/myCustomStyle.css"> |
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.
{{baseUrl}}
is not getting rendered (see Netlify preview).
@Chng-Zhi-Xuan the commits need to be squashed. As discussed with Prof, we can live with the Will merge it as soon as it is squashed. |
d8830c8
to
7c7600f
Compare
Update
|
@Chng-Zhi-Xuan I'm having trouble getting this to work in website-base. Can you try it out?
I got the feature to work in other places. In fact I can include |
To add to the above, full code available in the |
Findings:
This is intended behaviour as A quick fix is to specify |
Indeed that should be the problem. My bad. Sorry. Thanks for the help. |
What is the purpose of this pull request? (put "X" next to an item, remove the rest)
• [x] New feature
Resolves #355
What is the rationale for this request?
User would like to easily insert their own script or css files into the
<head>
of a page.What changes did you make? (Give an overview)
head
folder within the_markbind
folder.head file
infront-matter
page.ejs
template to insert content fromhead file
test_site
Is there anything you'd like reviewers to focus on?
nunjucks.renderString
withincollectHeadFiles
Testing instructions:
test_site
folder.markbind serve
and check console for the success message from inserted scriptmyCustomHead.md
markbind serve
and you should see the<head>
having your newly authored content frommyCustomHead.md
along with the files inSources
tab (in Chrome).