1

Im trying to version control a website generated with R-Markdown's render_site function by pushing it directly from the output directory, the default _site folder. Problem is, every time i call the render_site function it clears most of the content of the .git folder (save for the objects folder within) and breaks the link between the local and remote directory. Is there any way to stop this from happening? Curiously, the clean_site function clears the exact same folders and files from the .git folder so im guessing the problem is related to some post build cleanup.

The webpage directory looks something like this:

_site/
├── /.git
├── /index_files
├── /about_files
├── intex.html
├── about.html
└── styles.css

The .git folder before rendering the site looks like:

.git/
├── /hooks
├── /info
├── /logs
├── /objects
├── /refs
├── COMMIT_EDITMSG
├── config
├── description
├── FETCH_HEAD
├── HEAD
└── index

And after building only the objects folder is left:

.git/
└── /objects

I should also note that rendering each .Rmd file into htmls individually does not cause the same problem.

pdebem
  • 13
  • 3
  • It's easier to help you if you include a simple [reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example). Can you make it more clear exactly how your project is laid out? – MrFlick Sep 27 '19 at 16:31
  • 1
    You should put version control in the root directory of your project and not inside the sites folder. – Sada93 Sep 27 '19 at 17:22

1 Answers1

1

The default clean function for the site generator doesn't exclude anything. You can replace it fairly easily, using a scheme something like this:

Choose a name for your new generator, and put it in the YAML for the index.Rmd file, e.g.

site:  my_site

Write my_site to modify the default generator (or the original custom one, if you already had one):

my_site <- function(...) {
  site <- rmarkdown:::default_site(...) # or bookdown::bookdown_site(...), etc.
  # Modify the clean function
  oldclean <- site$clean
  site$clean <- function(...) {
    files <- oldclean(...)
    # leave out any filename containing .git
    grep("[.]git", files, value = TRUE, invert = TRUE)
  }
  site
}

I haven't tested this and might have the pattern wrong in the new clean function, but it should be close to working.

You might also want to suggest to the rmarkdown authors (on their Github site) that it would be nice to have a way to mark certain files to exclude from cleaning.

user2554330
  • 37,248
  • 4
  • 43
  • 90
  • Thanks! I was trying to look into the default_site and render_site functions but didn't have a clear idea on what to do about it. I'm going to try something with your suggestion! – pdebem Sep 28 '19 at 13:07