How to create a new quarto blog post

how_to
Author

Haky Im

Published

January 1, 2023

---
title: "Your Title"
author: "Your Name"
date: "2023-02-28"
date-modified: last-modified
categories: [analysis,how_to]
format:
  html:
    code-fold: true
    code-summary: "Show the code"
    code-tools: true
    code-overflow: wrap
editor_options: 
  chunk_output_type: console
---
Code
## - [ ] clean up this part. Create function that creates the folder
suppressMessages(library(tidyverse))
suppressMessages(library(glue))
PRE = "/Users/haekyungim/Library/CloudStorage/Box-Box/LargeFiles/imlab-data/data-Github/web-data"
##PRE="/Users/margaretperry/Library/CloudStorage/Box-Box/imlab-data/data-Github/web-data "
##PRE="/Users/temi/Library/CloudStorage/Box-Box/imlab-data/data-Github/web-data"
## COPY THE DATE AND SLUG fields FROM THE HEADER
SLUG="predictdb-weight-distribution" ## copy the slug from the header
bDATE='2023-02-28' ## copy the date from the blog's header here
DATA = glue("{PRE}/{bDATE}-{SLUG}")
if(!file.exists(DATA)) system(glue::glue("mkdir {DATA}"))
WORK=DATA

## move data to DATA
#tempodata=("~/Downloads/tempo/gwas_catalog_v1.0.2-associations_e105_r2022-04-07.tsv")
#system(glue::glue("cp {tempodata} {DATA}/"))

#system(glue("open {DATA}")) ## this will open the folder 

functions

Code
## input: date, title, slug
REPO="/Users/haekyungim/Github/web-lab-notes-quarto"
bDATE=format(Sys.time(),"%Y-%m-%d")
SLUG="test 1 lsdkf"

new_post = function(repo=REPO,slug=SLUG,bdate=bDATE)
{ 
  slug =  tolower(gsub(" ", "-", slug) )
  FOLDERNAME = glue::glue("{repo}/posts/{bdate}-{slug}")
  if(!file.exists(FOLDERNAME))
  {
  system(glue::glue("mkdir {FOLDERNAME}"))
  system(glue::glue("touch {FOLDERNAME}/index.qmd"))
  system(glue::glue("echo --- >>  {FOLDERNAME}/index.qmd"))
  system(glue::glue("echo 'title: {slug}' >>  {FOLDERNAME}/index.qmd"))
  system(glue::glue("echo 'author: AUTHOR NAME HERE' >>  {FOLDERNAME}/index.qmd"))
  system(glue::glue("echo 'date: {bdate}' >>  {FOLDERNAME}/index.qmd"))
  system(glue::glue("echo --- >>  {FOLDERNAME}/index.qmd"))
  } else
  {warning("{bdate}-{slug} already exists; you may want to change the slug")}
}

Reuse

© HakyImLab and Listed Authors - CC BY 4.0 for Text and figures - MIT for code