#' This file is how I'll build the site.
#'
rm( list=ls() )
# load in and convert any of the markdown stuff in _toImport into
# distill articles.
for( file in list.files("_toImport", pattern = "*.md", full.names = TRUE) ) {
# find previous stuff
<- readLines( file )
raw <- stringr::str_split( file.info(file)$mtime ,
date " ",
simplify = TRUE)[,1]
<- stringr::str_remove( raw[1], "# ")
title <- raw[3]
description <- paste( raw[ -1 ], collapse="\n")
contents
# make new post will create
<- gsub("[[:punct:][:blank:]]+", "-", title )
filetitle <- tolower(filetitle)
filetitle <- paste( "_posts/",
orig_title "-",
date, "/",
filetitle, ".Rmd",
filetitle,sep="" )
::create_post( filetitle,
distilldate = date,
edit = FALSE )
<- readLines( orig_title )
raw_post 2] <- paste( "title: \"", title, "\"" )
raw_post[4] <- paste( " ", description, sep=" ")
raw_post[7] <- " url: https://dyerlab.org\n affiliation: Center for Environmental Studies\n affiliation_url: https://ces.vcu.edu\n orcid_id: 0000-0003-4707-3453"
raw_post[8] <- paste( raw_post[8], "preview: featured.png", sep="\n")
raw_post[<- c( raw_post[1:13], contents )
raw_post <- paste( raw_post, collapse="\n")
raw_post_output
<- paste( "_posts/",
new_file "-",
date, "/",
filetitle, "index.Rmd", sep="" )
writeLines( raw_post_output,
con = new_file )
# clean up the posts
unlink( orig_title )
unlink( file )
::render( new_file )
rmarkdown
}
# clean up any of the crap on the site and render the whole thing.
system( "find . -type f -iname '.DS_Store' -delete")
::render_site(".") rmarkdown
So the first thing to do was to set up a staging place to save raw markdown files. Once I had that, I moved the rendering of this website from the “push the button on the build pane in RStudio to”run this script.”
This script is in the rood directory of the site and does the following steps:
- finds all markdown files in the
_toImport
folder. For each file it:
- Loads in the file
- Uses the first line as the metadata
title:
- Use the first paragraph as the metadata
description:
- Creates a new
distill::create_post()
with title and modification date for the markdown file. - Removes boilerplate stuff form new post and puts in content from the markdown file.
- Adds content to the metadata (extended author info and featured image components).
- Renames post to
index.Rmd
to make it easier to link in (I wish this was an option in distill). - Renders the markdown.
- Deletes original markdown file.
- After finishing up, it then renders the entire site.
Here is the script.
What I do not do is push through all the git actions to upload it. I think I’ll just do that manually.
Here is an example of the first Craft \(\to\) Distill posting.