-
Notifications
You must be signed in to change notification settings - Fork 124
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
Fix plugin live reloading for relative file paths #974
Conversation
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.
Tried it out and seems to be working, nice job. 👍
test/unit/Page.test.js
Outdated
const Page = require('../../src/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.
Remove the extra blank line
docs/userGuide/usingPlugins.md
Outdated
- **Parameters:** | ||
- `content`: The raw Markdown of the current Markdown file (`.md`, `.mbd`, etc.). | ||
- `pluginContext`: User provided parameters for the plugin. This can be specified in the `site.json`. | ||
- `frontMatter`: The frontMatter of the page being processed, in case any frontMatter data is required. |
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.
Any reason for deviating from the original ordering that the others follow (i.e. parameters, then what it returns)? Seems like the existing format can still be used here, even if it has more information compared to the rest like getLinks()
and getScripts()
.
test/unit/Page.test.js
Outdated
path.resolve('/root/subdir/images/sample2.png'))).toEqual(true); | ||
expect(page.pluginSourceFiles.has( | ||
path.resolve('/root/images/sample3.png'))).toEqual(true); | ||
expect(page.pluginSourceFiles.has( |
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 that the pluginSourceFiles
variable should just be a Set
.
ace11a2
to
43d6f5e
Compare
Updated, thanks for looking through it! |
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.
Ok, now just nits in documentations.
docs/userGuide/usingPlugins.md
Outdated
- For relative file paths, _if the tag is part of some included content_ ( eg. `<include />` tags ), it will be resolved against the included page. | ||
Otherwise, it is resolved against the page being processed. | ||
- `sources`: An array of source file paths to watch, where relative file paths are resolved only against the page being processed. | ||
- You can also directly return an array of source file paths to watch ( ie. the `sources` field ) ___(deprecated)___ |
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.
In fact the use case here and the one above seems to be the same, do we need this line in that case?
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.
Hmm, I actually meant only to deprecate the old syntax, not the functionality of returning some manually specified file paths (where relative ones are resolved according to the file processed).
This can be useful if a plugin needs live reload for a file that isn't specified as some src
attribute in the dom. E.g. a plugin where you can have file_name
+_page_extension
that adds some dynamic content to the relavant page based on that file's contents.
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.
Hmm ok, the sentence standalone feels a bit difficult to comprehend without your additional explanation (because of the (ie. the sources field)
portion), but I am fine with leaving it as it is for the moment.
docs/userGuide/usingPlugins.md
Outdated
- `pluginContext`: User provided parameters for the plugin. This can be specified in the `site.json`. | ||
- `frontMatter`: The frontMatter of the page being processed, in case any frontMatter data is required. | ||
|
||
`getSources(content, pluginContext, frontMatter)`: called _before_ a Markdown file's `preRender` function is called. |
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.
Minor nit: called
-> Called
docs/userGuide/usingPlugins.md
Outdated
- `tagMap`: An array consisting of `['tag name', 'source attribute name']` key value pairs. | ||
- MarkBind will automatically search for matching tags with the source attributes, and watch them. | ||
- For relative file paths, _if the tag is part of some included content_ ( eg. `<include />` tags ), it will be resolved against the included page. | ||
Otherwise, it is resolved against the page being processed. |
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.
Minor nit: join this line with the previous line?
docs/userGuide/usingPlugins.md
Outdated
- For relative file paths, _if the tag is part of some included content_ ( eg. `<include />` tags ), it will be resolved against the included page. | ||
Otherwise, it is resolved against the page being processed. | ||
- `sources`: An array of source file paths to watch, where relative file paths are resolved only against the page being processed. | ||
- You can also directly return an array of source file paths to watch ( ie. the `sources` field ) ___(deprecated)___ | ||
|
||
Example usage of `getSources` from the PlantUML plugin: |
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 feel that the reader might have a bit of difficulty understanding the example without context. Maybe an addition like this will make it clearer?
"Example usage of getSources
from the PlantUML plugin, which will watch files from tags such as <puml src="..." />
:"
Relative file paths provided by plugins are not resolved against the processed page or included file. This results in live reloading failing for pages not in the root directory. Let's fix this, and also rewrite plugin source collection, allowing plugins to simply define tags and corresponding source attributes to watch. This moves the logic for checking whether the source is part of an included file to the main markbind repo, reducing potential code duplication and simplifying the api.
43d6f5e
to
6ab3341
Compare
Updated, save for the deprecated syntax parts |
What is the purpose of this pull request? (put "X" next to an item, remove the rest)
• [x] Documentation update
• [x] Bug fix
• [x] Enhancement to an existing feature
Fixes #913
What is the rationale for this request?
As mentioned in #913, relative file paths for sources defined by plugins are not correctly resolved
against the page being processed. If the source is also part of an included file, then it should be resolved against the included file.
Urls are also added to the page's
pluginSourceFiles
, which has no effect, but is incorrectWhat changes did you make? (Give an overview)
Let's fix this and simplify the api for defining sources.
getSources
now returnsFrom a plugin author's perspective, resolving said sources against the page being processed
/ the included file is tricky. This moves all such logic to
Page.js
, exposing a simpler api.The old return syntax is deprecated, but still supported as well.
Provide some example code that this change will affect:
Testing instructions:
Simply use
npm run test
to run the new unit tests,For manual testing of live reloading, the test_site has some
sample pumls at the bottom.
Proposed commit message: (wrap lines at 72 characters)
Fix plugin live reloading for relative file paths
Relative file paths provided by plugins are not resolved against the
processed page or included file.
This results in live reloading failing for pages not in the root
directory.
Let's fix this, and also rewrite plugin source collection, allowing
plugins to simply define tags and corresponding source attributes
to watch.