forked from yutannihilation/rmarkdown-website-template
-
Notifications
You must be signed in to change notification settings - Fork 0
/
generateIndexPage.R
27 lines (22 loc) · 688 Bytes
/
generateIndexPage.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# generate index.html
#
# 1) If index.md exists, knit it.
# 2) Otherwise, generate index.html from an index file which contains the list of pages.
local({
if(file.exists("index.md")) {
rmarkdown::render("index.md", output_file = "index.html")
return()
}
md_tmp <- tempfile(tmpdir = ".", fileext = ".md")
on.exit(file.remove(md_tmp))
cat('---
title: "Index"
output: html_document
---
', file = md_tmp)
index <- jsonlite::fromJSON("index.json")
page_list <- sort(sprintf("* %s [%s](%s)", index$date, index$title, index$url))
cat(paste0(page_list, collapse = "\n"),
file = md_tmp, append = TRUE)
rmarkdown::render(md_tmp, output_file = "index.html")
})