-
-
Notifications
You must be signed in to change notification settings - Fork 5k
fix(processor/post): updated post assets not being copied in hot processing when post_asset_folder is enabled
#5704
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
Conversation
How to testgit clone -b fix/generate-asset-when-hotreload https://github.com/hexojs/hexo.git
cd hexo
npm install
npm test |
Pull Request Test Coverage Report for Build 18782179721Details
💛 - Coveralls |
| Examples that didn't work: | ||
| - `Post.findOne(p => p.asset_dir === absoluteAssetDirPath)` // returned wrong post | ||
| - `Post.findOne({asset_dir: absoluteAssetDirPath})` // returned null |
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 have not investigated why Post.findOne() does not work as expected.
post_asset_folder is enabled
|
Q: Why does A: The parameter of the Q: Why does A: find(query: object, options: Partial<Options> = {}): Query<T> | T[] {
const filter = this.schema._execQuery(query);
// ...
for (let i = 0; limit && i < len; i++) {
const key = keys[i];
const item = data[key]; // ⚠️ This is the raw stored data, without virtual fields
if (item && filter(item)) { // ⚠️ filter runs on raw data, so asset_dir cannot be found
arr.push(this.findById(key, options) as any);
limit--;
}
}
}Whereas in the forEach(iterator: ..., options?: Partial<Options>): void {
const keys = this.dataKeys;
let num = 0;
for (let i = 0, len = keys.length; i < len; i++) {
const data = this.findById(keys[i], options); // ✅ Returns a Document object, on which virtual getters exist
if (data) iterator(data as any, num++);
}
} |
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.
works well on my windows
The following issues will likely be fixed:
What does it do?
This PR fixes an issue where updated post assets were not being copied in hot processing. This issue introduced in #5473.
Cause
The
processAssetfunction had three issues.1. Path separator mismatch:
As @D-Sketon pointed out in PR #5473 comment, the original code used OS-specific
sep(backslash\on Windows) when extracting the asset directory path. This caused the path matching to fail on Windows.2. Path format inconsistency:
The extracted asset directory path was in relative format with forward slashes (e.g.,
source/_posts/bar), butpost.asset_diris an OS-specificabsolute path (e.g.,
C:\Users\...\source\_posts\bar\on Windows). This format mismatch prevented retrieving the correct post.3. Incorrect
Post.findOne()usagePost.findOne()with both query function and object syntax returned incorrect results. It either returned the wrong post ornull, preventingassets from being associated with the correct post. I have not investigated why
Post.findOne()doesn't work correctly here.Solution
posix.sep(/) consistently when extracting the asset directory from the normalizedidpost.asset_dirPost.findOne()withPost.filter()to ensure correct post lookupScreenshots
N/A
Pull request tasks