-
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 always-on plugins #714
Conversation
src/plugins/default/anchors.js
Outdated
* Adds anchor links to headers | ||
*/ | ||
module.exports = { | ||
postRender: (content, pluginContext, frontMatter, 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.
I needed access to Page.headingIndexingLevel,
so I added a 4th parameter, page which is the Page
object itself... Other plugins might need access to page config so this could be helpful
I'm thinking we can use this for internal plugins, but don't document it in user docs, since we don't want to expose authors to the implementation
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.
I'm just thinking it might be dangerous to pass the entire Page
object down to plugins, since that would allow the plugin to modify or invoke the variables and methods of Page
which could be dangerous. 😅
What do you think about passing down a copy of the pageConfig
object instead? Or maybe having a helper method getDefaultPluginsContext
which constructs the context for default plugins and appends it to the other pluginsContext
?
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.
Sure, I think I'll do the page config method, I think getDefaultPluginsContext
might end up growing pretty large if we have a lot of default plugins =P
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.
This part doesn't seem to be addressed?
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.
Just a couple of questions 🙂
src/Site.js
Outdated
.filter(plugin => !_.includes(defaultPlugins, plugin)) | ||
.forEach(plugin => this.loadPlugin(plugin, false)); | ||
defaultPlugins | ||
.filter(plugin => !this.siteConfig.pluginsContext |
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.
Just wondering - would using lodash's get
method make this more readable? 🙂
Possibly something like this:
_.get(this.siteConfig, ["pluginsContext", plugin, "off"], false)
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.
TIL, thanks
src/plugins/default/anchors.js
Outdated
* Adds anchor links to headers | ||
*/ | ||
module.exports = { | ||
postRender: (content, pluginContext, frontMatter, 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.
I'm just thinking it might be dangerous to pass the entire Page
object down to plugins, since that would allow the plugin to modify or invoke the variables and methods of Page
which could be dangerous. 😅
What do you think about passing down a copy of the pageConfig
object instead? Or maybe having a helper method getDefaultPluginsContext
which constructs the context for default plugins and appends it to the other pluginsContext
?
f3b37b0
to
331d1a2
Compare
Rebased and updated |
src/plugins/default/anchors.js
Outdated
* Adds anchor links to headers | ||
*/ | ||
module.exports = { | ||
postRender: (content, pluginContext, frontMatter, 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.
This part doesn't seem to be addressed?
src/Site.js
Outdated
* Finds plugins in the site's default plugin folder | ||
*/ | ||
function findDefaultPlugins() { | ||
const globPath = path.join(__dirname, BUILT_IN_PLUGIN_DEFAULT_FOLDER_NAME); |
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.
This assumes all built-in plugins are default plugins (i.e. turned on by default), which is not true.
For example, Algolia search plugin loads unnecessary files in the site if not used, so it should be turned off by default.
Also, this is known at MarkBind dev time. Shall we use a constant as a whitelist?
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.
Currently there's a separate folder for plugins that are always on (BUILT_IN_PLUGIN_FOLDER_NAME vs BUILT_IN_PLUGIN_DEFAULT_FOLDER_NAME)
src/
plugins/
default/
always-on.js
... other default plugins
must-be-turned-on.js
... other normal plugins
Plugins that should be off can be placed outside the default folder, where they are treated like normal plugins
I think this might be better than using a whitelist as that has to be hardcoded...
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.
Ah. BUILT_IN_PLUGIN_DEFAULT_FOLDER_NAME
→ BUILT_IN_DEFAULT_PLUGIN_FOLDER_NAME
?
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.
Ah.
BUILT_IN_PLUGIN_DEFAULT_FOLDER_NAME
→BUILT_IN_DEFAULT_PLUGIN_FOLDER_NAME
?
Sounds better 👍.
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.
Sure no problem
331d1a2
to
1a4b7f0
Compare
Updated and rebased |
f1722b8
to
e537c54
Compare
Updated, rebased |
Updated |
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.
I think you forgot to remove the prefix when obtaining the names of the default plugins, because the example in the documentation no longer works, and I have to do this instead:
"pluginsContext": {
"markbind-plugin-anchors": {
"off": true
}
}
d498a4c
to
7c8dfbb
Compare
Sorry for the delay, rebased and updated |
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.
@nicholaschuayunzhi has some additional comments for this PR, let me post my minor nit first:
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.
Sorry for my late comments. Perhaps the tests could be done in separate PR?
0aa5e66
to
f919f03
Compare
Sorry for lateness, updated |
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.
Apologies for the late reply.
f919f03
to
37e89e8
Compare
Updated |
Travis is currently borked, don't really know why, the builds are all getting stuck. I will return to this PR and merge it when I have the next free time. Meanwhile the proposed commit message:
|
What is the purpose of this pull request? (put "X" next to an item, remove the rest)
• [X] Enhancement to an existing feature
Fixes #702
What is the rationale for this request?
Certain plugins are unlikely to be excluded from every project
Support for plugins that are always on by default for every project
What changes did you make? (Give an overview)
Added support for default plugins:
src/plugins/default
folderoff
to pluginsContext:Also: