-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
Ignore files listed in .mdbookignore
during build
#1908
base: master
Are you sure you want to change the base?
Conversation
7f6adc7
to
92b89b5
Compare
Thanks for the PR! Per the comment at #1187 (comment), can this be a setting in |
I can add this to the config too, but I would like to have this feature as ignore file. |
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. |
Just realized, that the
|
The |
I've pushed a new version that uses the With the
|
74fb51e
to
f144b57
Compare
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 Can you add some documentation and tests? |
Any remarks? Or can we merge this? :) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Overall I'm finding the difference between .gitignore and .mdbookignore a little confusing.
I'm guessing that watch
does not ignore .mdbookignore files for a reason? Can you say more about why that choice was made?
@@ -94,13 +95,13 @@ pub fn copy_files_except_ext( | |||
to: &Path, | |||
recursive: bool, | |||
avoid_dir: Option<&PathBuf>, | |||
ext_blacklist: &[&str], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since this is a public API, the API can't change. I think you will need to create a new function. Also, the naming would no longer be appropriate (_ext
was filtering on extensions, and this is now filtering on ignore).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done. I've added a new public function copy_files_except_ignored
that is called by copy_files_except_ext
to not have code duplication.
src/book/mod.rs
Outdated
@@ -856,4 +857,21 @@ mod tests { | |||
let got = preprocessor_should_run(&BoolPreprocessor(should_be), &html, &cfg); | |||
assert_eq!(got, should_be); | |||
} | |||
|
|||
#[test] | |||
fn build_test_book() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since this test's intent is to validating the mdbookingore behavior, I think it is good to make sure the name reflects that.
fn build_test_book() { | |
fn mdbookignore_ignores_file() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed.
src/utils/fs.rs
Outdated
if let Some(ignore) = ignore { | ||
let path = entry.path(); | ||
if ignore.matched(&path, path.is_dir()).is_ignore() { | ||
continue; | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since this clause is identical to the one below, can it be moved up out of the if
clause and unified?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed.
@@ -279,6 +279,16 @@ The value can be any valid URI the browser should navigate to (e.g. `https://rus | |||
This will generate an HTML page which will automatically redirect to the given location. | |||
Note that the source location does not support `#` anchor redirects. | |||
|
|||
### `[.mdbookignore]` | |||
|
|||
You can use a `.mdbookignore` file to exclude files from the build process. The file is places in the `src` directory of your book and has the format known from [`.gitignore`](https://git-scm.com/docs/gitignore) files. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can use a `.mdbookignore` file to exclude files from the build process. The file is places in the `src` directory of your book and has the format known from [`.gitignore`](https://git-scm.com/docs/gitignore) files. | |
You can use a `.mdbookignore` file to exclude files from the build process. The file is placed in the `src` directory of your book and has the same format as [`.gitignore`](https://git-scm.com/docs/gitignore) files. |
Also, can you split it to one sentence per line to make diffs easier to manage?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed.
@@ -279,6 +279,16 @@ The value can be any valid URI the browser should navigate to (e.g. `https://rus | |||
This will generate an HTML page which will automatically redirect to the given location. | |||
Note that the source location does not support `#` anchor redirects. | |||
|
|||
### `[.mdbookignore]` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure why this is in square brackets. The other sections are like that because they are describing TOML sections of book.toml
.
### `[.mdbookignore]` | |
### `.mdbookignore` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed.
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.
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, |
There is a subtle difference between them (as indicated by the confusion around 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. |
Any news of this? Would be happy to help |
Sorry, I had no time to make this ready yet. Feel free to fix the findings above :) |
79829cd
to
3d838ef
Compare
@ehuss I (finally) had some time to resolve the findings and rebased to the current master. Might there be some time for another review? :) |
Implementation according to issue #1187 and #1156