mdBook icon indicating copy to clipboard operation
mdBook copied to clipboard

Ignore files listed in `.mdbookignore` during build

Open Bergmann89 opened this issue 3 years ago • 14 comments

Implementation according to issue #1187 and #1156

Bergmann89 avatar Oct 13 '22 14:10 Bergmann89

Thanks for the PR! Per the comment at https://github.com/rust-lang/mdBook/issues/1187#issuecomment-612970155, can this be a setting in book.toml instead?

ehuss avatar Oct 13 '22 23:10 ehuss

I can add this to the config too, but I would like to have this feature as ignore file.

Bergmann89 avatar Oct 14 '22 07:10 Bergmann89

An ignore file has the benefit of not polluting the main config file and so it can really be done on a user-by-user basis.

The pitfall is... of course... yet another file.

schungx avatar Oct 14 '22 07:10 schungx

Just realized, that the gitignore crate has a bug :/ The following patterns will not ignore any file, but it should ignore everything except the mdbook-plantuml-img directory:

/*
!mdbook-plantuml-img

gitignore was not maintained since two years. Maybe it's better to have an own implementation for the ignore files or use the config only. If we add this to the config, it would be nice to have a setting for include and a exclude.

Bergmann89 avatar Oct 14 '22 09:10 Bergmann89

The ignore crate work as expected.

Bergmann89 avatar Oct 14 '22 10:10 Bergmann89

I've pushed a new version that uses the ignore crate instead of gitignore.

With the ignore crate we can do some further improvements:

  • Remove the custom implementation of file walk copy_files_except_ext with ignore::Walk which will have the benefit, that also ignore files in the sub directories will be evaluated.
  • Use ignore::Walk to evaluate all .gitignore files (not only in the root directory) to filter files in the watch command.

Bergmann89 avatar Oct 14 '22 11:10 Bergmann89

Ok, seems fair to have a separate file. I personally prefer to keep things in one place, and to not have too many files, just to keep things simple (there's one place to describe the config).

I think switching to ignore sounds great.

Can you add some documentation and tests?

ehuss avatar Oct 15 '22 21:10 ehuss

Any remarks? Or can we merge this? :)

Bergmann89 avatar Nov 03 '22 16:11 Bergmann89

Overall I'm finding the difference between .gitignore and .mdbookignore a little confusing.

What exactly? We can also add this to the config if you want to, but I need any solution to ignore specific files processed by mdbook.

I'm guessing that watch does not ignore .mdbookignore files for a reason? Can you say more about why that choice was made?

Should not. If this is the case, this is a mistake on my side. I will check this.

I'm currently really busy in my own projects. I will resolve all of your findings once I have some more time for this. This may take a couple of weeks.

Greetings, Bergmann89.

Bergmann89 avatar Jan 18 '23 07:01 Bergmann89

What exactly? We can also add this to the config if you want to, but I need any solution to ignore specific files processed by mdbook.

There is a subtle difference between them (as indicated by the confusion around watch). gitignore files are copied, but not watched. mdbookignore files are not copied but are watched. The documentation doesn't make the differences clear to me, or explain why one would use one over the other. I might suggest in places where gitignore is mentioned in the documentation to make links to the mdbookignore section ("gitignore will only affect which files are watched for changes. To avoid copying certain source files to the output, see [mdbookignore]" or something like that).

I'm also wondering if copying should also avoid git ignored files. However, I think that will require opening the git repo and verifying which files are actually ignored similar to how Cargo itself works, but that is a pretty big hairy mess.

ehuss avatar Jan 18 '23 14:01 ehuss

Any news of this? Would be happy to help

egasimus avatar Aug 23 '23 04:08 egasimus

Sorry, I had no time to make this ready yet. Feel free to fix the findings above :)

Bergmann89 avatar Aug 23 '23 06:08 Bergmann89

@ehuss I (finally) had some time to resolve the findings and rebased to the current master. Might there be some time for another review? :)

Bergmann89 avatar Jul 26 '24 06:07 Bergmann89