Skip to content

Instantly share code, notes, and snippets.

@aammd
Created March 13, 2015 18:37
Show Gist options
  • Save aammd/75ff5272a277f23b3fc5 to your computer and use it in GitHub Desktop.
Save aammd/75ff5272a277f23b3fc5 to your computer and use it in GitHub Desktop.
Automatically create a file with the correct header and filename for SWC teacher instruction.
require("yaml")
require("lubridate")
#' Make a correct SWC blog post
#'
#' Automatically formats the necessary YAML header for a
#' Software Carpentry Teacher training blog post. Writes
#' this header to a file with the correct name. The file is
#' created in your current working directory.
#'
#' @param firstname Your first name, capitalized as you
#' prefer
#' @param surname Your surname, capitalized as you prefer
#' @theme_code Short character string, supplied by Greg
#' Wilson, indicating the theme of the posts. e.g. "mcq"
#' @title Your blog post title.
#' @tags character vector of tags
swc_post <- function(firstname, surname, theme_code, title, tags){
today <- Sys.Date()
today_char <- as.character(today)
mo <- month(today)
yr <- year(today)
dy <- day(today)
#/yyyy/mm/forename-surname-mcq/
my_post <- paste(tolower(firstname),
tolower(surname),
theme_code,
sep = "-")
link <- paste(yr, mo, my_post, sep = "/")
frntmatter <- list(data = today_char,
round = "Round 12",
title = title,
author = paste(firstname, surname),
permalink = link,
tags = tags)
header <- paste("---", as.yaml(frntmatter), "---",
"Markdown text goes here", sep = "\n")
#yyyy-mm-dd-forename-surname.md
filename <- paste(yr, mo, dy, tolower(firstname), tolower(surname),sep = "-")
writeLines(header, paste0(filename, ".md"))
}
swc_post(firstname = "Andrew",
surname = "MacDonald",
theme_code = "mcq",
title = "TITLE", tags = c("foo", "bar"))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment