Skip to content

Add support for ignoring files when building the book - #3229

Merged
GuillaumeGomez merged 1 commit into
rust-lang:mainfrom
Chocorean:dev_ignore
Oct 29, 2026
Merged

GuillaumeGomez merged 1 commit into
rust-lang:mainfrom
Chocorean:dev_ignore

Conversation

@Chocorean

@Chocorean Chocorean commented Sep 26, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #1187
Fixes #2224
Fixes #1156
Fixes #2246

Hopefully this is not just another duplicate and will act as a summary for the state of the "ignore" feature of mdbook.

This is a merge of #1908 onto main, with conflicts fixed.

As far as I have found, it would:

  1. close:
  1. supersede:

EDIT:

This PR adds the support for a .mdbookignore file, found under src/, which acts as a ignore system to prevent the inclusion of specific files in the output directory.

I believe all the comments from #1908 were addressed

@rustbot ready

@Chocorean Chocorean changed the title Ignore files listed in .mdbookignore during build - #1908 Ignore files listed in .mdbookignore during build Sep 27, 2026

@Chocorean Chocorean Sep 28, 2026 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't .mdbookignore be ignored by default? seems odd to me to include it

View changes since the review

@rustbot rustbot added the S-waiting-on-review Status: waiting on a review label Sep 28, 2026
@Chocorean
Chocorean marked this pull request as ready for review September 28, 2026 01:31

@DanielEScherzer DanielEScherzer left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

community review: some suggestions

View changes since this review

Comment thread crates/mdbook-core/src/utils/fs.rs Resolved
Comment thread crates/mdbook-core/src/utils/fs.rs Resolved
@Chocorean

Copy link
Copy Markdown
Contributor Author

@DanielEScherzer Hello there, thanks for the review! I agree with you on all points. I reverted the unrelated changes and applied your suggestion

@GuillaumeGomez GuillaumeGomez left a comment •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some small nits but otherwise looks good to me. Thanks for the PR and thanks @DanielEScherzer for the review!

View changes since this review

Comment thread Cargo.toml Resolved
@rustbot rustbot added S-waiting-on-author Status: The marked PR is awaiting some action (such as code changes) from the PR author. and removed S-waiting-on-review Status: waiting on a review labels Oct 1, 2026
@rustbot

rustbot commented Oct 1, 2026

Copy link
Copy Markdown
Collaborator

Reminder, once the PR becomes ready for a review, use @rustbot ready.

@Chocorean

Copy link
Copy Markdown
Contributor Author

Comments addressed ! @rustbot ready

@rustbot rustbot added S-waiting-on-review Status: waiting on a review and removed S-waiting-on-author Status: The marked PR is awaiting some action (such as code changes) from the PR author. labels Oct 1, 2026
@GuillaumeGomez

Copy link
Copy Markdown
Member

Time to squash all commits now. :)

@Chocorean

Copy link
Copy Markdown
Contributor Author

@GuillaumeGomez I hope I got this right

@GuillaumeGomez

Copy link
Copy Markdown
Member

Looks all good to me, thanks! Since it's a new feature, let's ping the rest of the team.

@rfcbot fcp merge mdbook

@rust-rfcbot rust-rfcbot added the T-mdbook Necessary for rfcbot to work correctly right now label Oct 1, 2026
@rust-rfcbot

rust-rfcbot commented Oct 1, 2026 •

Copy link
Copy Markdown
Collaborator

@GuillaumeGomez has proposed to merge this. The next step is review by the rest of the tagged team members:

Concerns:

Once a majority of reviewers approve (and at most 2 approvals are outstanding), this will enter its final comment period. If you spot a major issue that hasn't been raised at any point in this process, please speak up!

See this document for info about what commands tagged team members can give me.

@notriddle

notriddle commented Oct 1, 2026 •

Copy link
Copy Markdown
Contributor

Git, and systems like Git, allow you to put an ignore file in a subdirectory, allowing you to apply the rules to a particular scope. It doesn't seem to be working.

$ echo "thunk.txt" > src/misc/.mdbookignore
$ echo "my think" > src/misc/thunk.txt
$ ../target/release/mdbook build
 INFO Book building has started
 INFO Running the html backend
 INFO HTML book written to `/Users/michaelhowell/mdBook/guide/book`
$ ls -a book/misc
.			.mdbookignore		thunk.txt
..			contributors.html

It only works when I put it in the root directory.

$ rm -rf book
$ echo "thunk.txt" > src/.mdbookignore
$ ../target/release/mdbook build
 INFO Book building has started
 INFO Running the html backend
 INFO HTML book written to `/Users/michaelhowell/mdBook/guide/book`
$ ls -a book/misc
.			.mdbookignore
..			contributors.html

(If we're not going to implement it, then it shouldn't be a hidden file. Just make it a list of rules in book.toml.)

@Chocorean

Copy link
Copy Markdown
Contributor Author

I don't think the point behind this feature request was to have something that mimics exactly what git and other systems do. The point is mdBook has been lacking a simple way to exclude files from its output, for a long time.

I believe that point is addressed here, and the doc explicitly mentions the mdbookignore file lives under src/

@notriddle

Copy link
Copy Markdown
Contributor

If you don't want to copy Git, then please don't copy Git. I'd prefer if this configuration were stored in the toml file.

@camelid

camelid commented Oct 5, 2026

Copy link
Copy Markdown
Member

@rfcbot concern bespoke interface

I would also prefer this to be simplified by just being a normal entry in the config toml.

@Chocorean

Copy link
Copy Markdown
Contributor Author

So be it!
Please allow me a few days, I will move from the .mdbookignore to a config option.
I assume it would live under the [build] configuration ?

@Chocorean
Chocorean marked this pull request as draft October 6, 2026 14:50
@Chocorean Chocorean changed the title Ignore files listed in .mdbookignore during build Add support for ignoring files when building the book Oct 8, 2026
@Chocorean

Copy link
Copy Markdown
Contributor Author

@GuillaumeGomez @notriddle @camelid Ready for review, moved away from .mdbookignore, now uses a list of globs specified in the config file, under build.ignore

@camelid

camelid commented Oct 19, 2026

Copy link
Copy Markdown
Member

The overall idea seems reasonable to me. I'll leave the code review to Guillaume.

@rustbot reviewed
@rfcbot resolve bespoke interface

@rust-rfcbot

Copy link
Copy Markdown
Collaborator

🔔 This is now entering its final comment period, as per the review above. 🔔

@GuillaumeGomez

Copy link
Copy Markdown
Member

@camelid I'm checking your checkbox as the bot command seems to have miss it.

@Chocorean: Looks all good to me, thanks! Please squash your commits.

ensure the original *.md filtering still happens

replace warn by error when cannot load mdbookignore file

revert unrelated changes

Update crates/mdbook-core/src/utils/fs.rs

Co-authored-by: Daniel Scherzer <daniel.e.scherzer@gmail.com>

Update crates/mdbook-html/src/html_handlebars/hbs_renderer.rs

Co-authored-by: Guillaume Gomez <contact@guillaume-gomez.fr>

revert deps order

remove extra bracket

Update crates/mdbook-core/src/utils/fs.rs

Co-authored-by: Daniel Scherzer <daniel.e.scherzer@gmail.com>

revert deps order

replace .mdbookignore by [build].ignore config option

typo

remove directories mention; files work too!
@Chocorean

Copy link
Copy Markdown
Contributor Author

Ready for take off.

@GuillaumeGomez

Copy link
Copy Markdown
Member

Once the FCP period is done, I'll merge. Thanks. :)

@camelid

camelid commented Oct 21, 2026

Copy link
Copy Markdown
Member

@camelid I'm checking your checkbox as the bot command seems to have miss it.

Ah thanks, I used the wrong bot name.

@rust-rfcbot

Copy link
Copy Markdown
Collaborator

The final comment period, with a disposition to merge, as per the review above, is now complete.

As the automated representative of the governance process, I would like to thank the author for their work and everyone else who contributed.

@GuillaumeGomez

Copy link
Copy Markdown
Member

Thanks everyone!

@GuillaumeGomez
GuillaumeGomez added this pull request to the merge queue Oct 29, 2026
@DanielEScherzer

Copy link
Copy Markdown
Contributor

Heads up that CI is probably going to fail, #3250

@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Oct 29, 2026
@GuillaumeGomez

Copy link
Copy Markdown
Member

Let's try again now that #3250 was merged.

@GuillaumeGomez
GuillaumeGomez added this pull request to the merge queue Oct 29, 2026
Merged via the queue into rust-lang:main with commit b21095b Oct 29, 2026
20 checks passed
@rustbot rustbot removed the S-waiting-on-review Status: waiting on a review label Oct 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

8 participants