-
Notifications
You must be signed in to change notification settings - Fork 66
Repeat runs with collections adds duplicates #27
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
Comments
Same issue for partial rebuild with metalsmith-watch that is using run() method. |
I'm also getting this issue. Couldn't get the workaround that @Aintaer mentions to work either. Do you have an idea what am I doing wrong? Thanks! var siteBuild = metalsmith(__dirname)
.use(paths())
.use(relative())
.metadata({
site: {
title: 'Site Title'
}
})
.use(markdown())
.use(collections({
apples: {
metadata: {
name: 'Apples',
description: ''
}
},
oranges: {
metadata: {
name: 'Oranges',
description: ''
}
}
})
)
.use(templates( 'jade'))
.use(sass())
.use(watch({
paths: {
"src/**/*": "**/*.md",
"templates/**/*": "**/*.md"
},
livereload: true
})
)
.destination('./build')
.build(function (err) {
if (err) throw err;
}); |
I solved this with a fork that deletes the collections metadata before re-adding articles to collections -- deltamualpha@a3d5db6 -- but I don't know if that's the right answer overall. |
Thanks @deltamualpha ! My current workaround is to just use half the collection when looping through it in the template, but yeah would be nice if this got fixed for real. It's pretty strange not to find more people with the same issue, collections are quite basic functionality. |
@venomgfx I think part of it is that from what I've seen, Segment thinks that watchers as part of the build pipeline are a bad idea, and that the rebuild logic (and serving) should be external to the Metalsmith object. I'm considering re-writing my build path to work this way. Some third-party plugins have logic that handles watchers correctly, but most of the first-party ones don't. |
@deltamualpha Ah that makes sense yes. Perhaps it's worth looking into gulp-metalsmith. So we watch outside of the metalsmith build pipeline. Will try it out. Thanks a lot for your feedback! |
@deltamualpha: that fix works for me. Thanks for your help! Edit: It sort of works. Some pages when saved (e.g. This solution totally deletes the collections data on pages that do NOT cause the duplication issue when saved (e.g. the source files themselves). |
guys, I have the same problem with diff -u index.js ../../blog/node_modules/metalsmith-collections/lib/index.js
--- index.js 2015-08-22 04:53:38.962863606 +0100
+++ ../../blog/node_modules/metalsmith-collections/lib/index.js 2015-08-22 04:51:11.137564810 +0100
@@ -32,8 +32,26 @@
* Find the files in each collection.
*/
+ var in_collections;
Object.keys(files).forEach(function(file){
debug('checking file: %s', file);
+
+ var collections = metadata.collections;
+ if (collections) {
+ in_collections = Object.keys(collections).map(function(collection) {
+ return collections[collection].filter(function(data) {
+ return (file === data.filename);
+ });
+ });
+ in_collections = [].concat.apply([], in_collections);
+ }
+
+ // and from outer body return if file already in collections
+ if (in_collections && in_collections.length === 1) {
+ debug('already in collections, skipping: %s', in_collections[0].filename);
+ return;
+ }
+
var data = files[file];
match(file, data).forEach(function(key){
if (key && keys.indexOf(key) < 0){ maybe someone with more experience can pitch in and let us know if this works? edit1: spoke too soon... I'm also using edit2: it might have just been some weird stuff going on with edit3: damn... after looking at |
@razvanc87: I see the same behavior. Some of the root cause of this problem is that metalsmith-watch only passes documents into the pipeline that have changed. If you have source files set to refresh only themselves, while template files refresh all source files, you will see differences in behavior between the two. |
I've... sopped trying to figure out what's happening and instead am using |
Yeah, |
Well... they are a bad idea because it's hard to deal with mutable state, but as far as efficiency goes... I'd rather have them then not (if it wouldn't interfere and make a mess of the state). Whereas rebuilding from scratch with all the imports, etc. takes about 1-2 seconds, with in-band watch, this can be almost real-time, because you're also rebuilding basically one file at a time instead of the whole directory... which is quite nice. Unfortunately I couldn't make it work with this collections plugin. If I do get a better understanding I definitely will poke at this again :). |
+1 |
1 similar comment
+1 |
I used to have this issue with |
👍 fixed it locally by checking the |
👍 +1 |
Forked this for now and added the https://github.com/spacedawwwg/metalsmith-collections use this forked version by adding "devDependencies": {
"metalsmith-collections": "spacedawwwg/metalsmith-collections"
} to your I've submitted a pull request, but I'll keep the fork updated until this finally gets fixed (it has been a year since this issue was posted) |
Another quickfix is to monkey patch the build method, like: var build = metalsmith.build;
metalsmith.build = function() {
build.apply(ms, arguments)
ms.metadata(originalMeta));
} This whipes it after every build and works with |
Thanks @spacedawwwg that works great. |
Here's another fix to force the metadata to reset every build. Similar idea to @AndyOGo.
|
Did this ever get fixed @spacedawwwg ? BTW - thanks for the temp fix. |
To avoid this issue, install by
This will be install the latest version of plugin, since metalsmith org still does not have permission to push to |
@webketje Why did you close this. |
@AndyOGo please see the commit 891b24c which adds a test for this. In the latest published version, I did quite some refactoring and suspected I incidentally fixed it (I think it was even fixed long ago but just in a messy way and without updating this issue) EDIT: My test should have been sequential, not parallel. Updated locally, but the conclusion remains, yes it's fixed. |
Currently, repeated calls to
metalsmith.build()
is non-idempotent because metalsmith-collections will find the same files that belongs to a collection, and add them to the same array as exists in memory from the previous run.This is due to metalsmith storing collections in the global metadata object. Maybe it should empty out the collections arrays every time it runs?
My workaround right now is essentially
The text was updated successfully, but these errors were encountered: