Skip to content

Conversation

@DipakHalkude
Copy link

@DipakHalkude DipakHalkude commented Oct 8, 2025

What does it do?

Fixes issue #5680 where programmatically created assets in processors were being removed by the asset generator.

The asset generator was checking for physical file existence and removing all assets without corresponding files, including those created programmatically with modified: true flag.

Solution

Modified the asset generator to skip removal for assets marked with modified: true. This allows plugins and processors to create virtual/assets programmatically that persist in the database.

Changes Made

  1. lib/plugins/generator/asset.ts: Added check for asset.modified flag before removing assets
  2. test/scripts/generators/asset.test.js: Added comprehensive tests

Pull request tasks

  • Add test cases for the changes.
  • Passed the CI test.

Testing

Example Usage

hexo.extend.processor.register("_posts/:slug\.md", function(file) {
  const Asset = this.model('Asset');
  const test = Asset.findById("Test");
  if (!test) {
    return Asset.insert({
      _id: "Test",
      path: "Test",
      modified: true  // This prevents removal
    });
  }
});

@github-actions
Copy link

github-actions bot commented Oct 8, 2025

How to test

git clone -b fix-asset-generator-removal https://github.com/DipakHalkude/hexo.git
cd hexo
npm install
npm test

@DipakHalkude
Copy link
Author

@SukkaW @curbengh @D-Sketon Could you please review this fix for #5680? It addresses the issue where programmatic assets weren't persisting in the database.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant