fix(processor/post): updated post assets not being copied in hot processing when post_asset_folder is enabled#5704
Merged
yoshinorin merged 5 commits intomasterfrom Oct 25, 2025
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 |
yoshinorin
commented
Oct 11, 2025
|
|
||
| Examples that didn't work: | ||
| - `Post.findOne(p => p.asset_dir === absoluteAssetDirPath)` // returned wrong post | ||
| - `Post.findOne({asset_dir: absoluteAssetDirPath})` // returned null |
Member
Author
There was a problem hiding this comment.
I have not investigated why Post.findOne() does not work as expected.
post_asset_folder is enabled
Member
|
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++);
}
} |
leafbird
added a commit
to leafbird/devnote
that referenced
this pull request
Mar 1, 2026
Fix draft post asset images mapped to wrong post due to warehouse findOne bug (hexojs/hexo#5704) Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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