Skip to content
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

Cache doesn't honor "force" option during generate #2700

Closed
CITguy opened this issue Aug 10, 2017 · 3 comments
Closed

Cache doesn't honor "force" option during generate #2700

CITguy opened this issue Aug 10, 2017 · 3 comments
Labels

Comments

@CITguy
Copy link

CITguy commented Aug 10, 2017

I have an external script to watch for changes to ANY file in source/ (including skipped, underscore files) and force a Hexo generate when that happens.

hexo.call('generate', { force: true })

I've also got a custom renderer defined for LESS compilation.

hexo.extend.renderer.register('less', 'css', function() { 
    /* ... */
});

Given the following setup:

// source/styles/myStyles.less
@import '_partial';

// source/styles/_partial.less
.foo { 
  content: 'bar';
}

I would expect public/styles/myStyles.css to be regenerated with updated content any time _partial.less changes.


When I save _partial.less, my script triggers a forced generation. However, the Cache model seems to skip myStyles.less because neither its contents, nor its modified time have changed.

Please update so that Cache will honor the force option passed to the generateConsole() function.

Currently, the only way around this is to restart my development script so that it generates all files as if it were the first generate.


hexo/lib/models/cache.js

Lines 36 to 41 in 5234c4a

// Skip the file if the modified time is unchanged
if (cache.modified === mtime) {
return {
type: 'skip'
};
}

hexo/lib/models/cache.js

Lines 52 to 57 in 5234c4a

// Skip the file if the hash is unchanged
if (cache.hash === hash) {
return {
type: 'skip'
};
}

@tea3
Copy link
Member

tea3 commented Aug 11, 2017

@CITguy
Cache in hexo watching content (e.g. source/_posts/**/*.md ) updates. Also, general usage don't include style sheets including LESS etc in the source directory.

Normally it is recommended to put the LESS file in the theme directory (e.g. theme/your-theme/source/less ) . In this usage, I think that it will monitor files update with hexo-renderer-less etc.


If that is inevitable, I suggest that you create a plugin to edit Cache data like my Plugin.

  • Plugin monitoring the markdown change with the following code. I think this can also be applied to LESS file.

https://github.com/tea3/hexo-include-markdown/blob/master/lib/orverwriteCache.js#L52

  • After finding the file's change, it will edit the cache to determine the update.

https://github.com/tea3/hexo-include-markdown/blob/master/lib/orverwriteCache.js#L161

@CITguy
Copy link
Author

CITguy commented Aug 11, 2017

The fun thing about my setup is that I'm using Hexo to build out documentation for a design system. I've got Pages documenting each component and I'm using the Posts for release notes. Each component directory (source/components/myComponent/) contains all of the source files and documentation needed to consume that component (this is where my _partial.less files exist).

My script doesn't use the Hexo server, but uses Browsersync to serve up the public/ directory. This is because the Hexo server doesn't watch for changes to all files (_partial.less) to automatically generate assets. So I have Browsersync watch for changes and call a forced generate from Hexo.

Hexo correctly generates content on deploy, but this Cache issue is frustrating while I'm trying to develop locally.


My scripts: https://gist.github.com/CITguy/94d1d33a5e36901e402a2cf8fbd27fd3

@stale
Copy link

stale bot commented Aug 16, 2020

This issue has been automatically marked as stale because lack of recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the stale label Aug 16, 2020
@stale stale bot closed this as completed Aug 23, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants