Skip to content

Clear site directory before build - #154

Merged
d0ugal merged 16 commits into
mkdocs:masterfrom
devbliss:feature/clear-site-directory-option
Oct 21, 2014
Merged

d0ugal merged 16 commits into
mkdocs:masterfrom
devbliss:feature/clear-site-directory-option

Conversation

@mdio

@mdio mdio commented Oct 13, 2014

Copy link
Copy Markdown
Contributor

Remove the content of site_dir to remove old files which dropped out of the documentation.

@d0ugal

d0ugal commented Oct 13, 2014

Copy link
Copy Markdown
Contributor

I had been thinking about this, and I tend to manually nuke the site directory so I think it makes sense. However, I feel like this should be the default and I can't see why anyone would want to disable it and thus I don't think we need the config option.

@mdio

mdio commented Oct 13, 2014

Copy link
Copy Markdown
Contributor Author

I found issue #16 which is pretty similar.
This raises the question how to handle hidden directories as well as if this should be a config value, a command line switch or (as you suggested) the default behaviour.

Sorry for the code. It's my first stab at python.

@d0ugal

d0ugal commented Oct 13, 2014

Copy link
Copy Markdown
Contributor

Why do we need to think about hidden files? Anything in the output directory should be deletable IMO.

@lovelydinosaur

Copy link
Copy Markdown
Collaborator

Agree re not wanting to add config if poss. Do we need to think about safety checks, eg what if someone's trying out 'site_dir = .' without knowing that it'll clean up?

@mdio

mdio commented Oct 14, 2014

Copy link
Copy Markdown
Contributor Author

@tomchristie

what if someone's trying out 'site_dir = .' without knowing that it'll clean up?

For me it would be enough to mention it in the documentation.
I mean the first time I read that there is a config option site_dir was at http://www.mkdocs.org/user-guide/configuration/#site_dir
So maybe put the warning there in bold but that should suffice, don't you think?

In the meantime I'll be changing the code to be the default without the option.

@mdio mdio changed the title Added clear site directory option Clear site directory before build Oct 14, 2014
Comment thread mkdocs/build.py Outdated

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.

I think we should clear the directory for an html build or a JSON build.

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.

Sorry, my mistake. I thought dump_json=True means dump the output to the console (as json).

@d0ugal

d0ugal commented Oct 14, 2014

Copy link
Copy Markdown
Contributor

I think this would be the safest/best default.

  1. site/ directory is empty - we build as normal.
  2. site/ directory contains files - we output a warning to tell the user to add --clean and build as normal.
  3. site directory contains files and the user passes --clean - we delete the files then build as normal.

I think this covers most of the cases we need to worry about. It is safe and also warns the user they may have stale files in the output directory.

@lovelydinosaur

Copy link
Copy Markdown
Collaborator

The ideal for me would be as @d0ugal notes, but that (2) would only warn if there were any files that wouldn't otherwise be overwritten. That way --clean would actually only be used/warned when the user really does have stale build files. Failing that would be happy to go with the above as an incremental step toward that.

@mdio

mdio commented Oct 14, 2014

Copy link
Copy Markdown
Contributor Author

I can try to accomplish the version outlined by @d0ugal but I don't think that I can come up with a clever solution for a staleness check as suggested by @tomchristie.
Even though the feature would be much more useful that way. :/

What about the live server mode? Should the site directory be cleaned before rebuilding or should that stay the way it is now?

@d0ugal

d0ugal commented Oct 16, 2014

Copy link
Copy Markdown
Contributor

The live server mode builds in a temp directory anyway, so you don't need to worry about it for this.

@d0ugal

d0ugal commented Oct 16, 2014

Copy link
Copy Markdown
Contributor

Updates look good - will try to review fully tomorrow.

@tomchristie do you have a preference when it comes to squashing vs keeping pull request history?

@lovelydinosaur

Copy link
Copy Markdown
Collaborator

@d0ugal No preference.

@d0ugal d0ugal added this to the 0.10.0 milestone Oct 19, 2014
Comment thread mkdocs/main.py Outdated

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.

I think we want to support the clean flag for json building too.

@d0ugal

d0ugal commented Oct 19, 2014

Copy link
Copy Markdown
Contributor

One minor comment inline.

If possible could you also mention this in the release notes under 0.10.X which I plan to include this change.
https://github.com/tomchristie/mkdocs/blob/master/docs/about/release-notes.md

And possibly a note in the documentation too here: https://github.com/tomchristie/mkdocs/blob/master/docs/index.md#building-the-site - it is almost selt documenting with the print output, but it wouldn't hurt.

Then I'm happy to merge.

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.

Thanks for these fixes!

@d0ugal

d0ugal commented Oct 21, 2014

Copy link
Copy Markdown
Contributor

This looks great - just waiting for Travis to verify and then I'll hit merge.

@mdio

mdio commented Oct 21, 2014

Copy link
Copy Markdown
Contributor Author

I enabled the --clean switch for all commands that call build().
That includes json (as you suggested) but gh-deploy as well.
But I think this makes sense since the notification about stale files and the --clean switch will also be printed for gh-deploy.

I hope my documentation attempt is sufficient. ;)
If not I'm open for suggestions.

Oh and if this is merged, #16 can be closed. :)

d0ugal added a commit that referenced this pull request Oct 21, 2014
@d0ugal
d0ugal merged commit b6c4ead into mkdocs:master Oct 21, 2014
@d0ugal d0ugal mentioned this pull request Oct 21, 2014
@d0ugal

d0ugal commented Oct 21, 2014

Copy link
Copy Markdown
Contributor

Thanks @mdio!

@mdio

mdio commented Oct 21, 2014

Copy link
Copy Markdown
Contributor Author

Likewise, it was a pleasure to work with you.

@mdio
mdio deleted the feature/clear-site-directory-option branch October 21, 2014 08:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants