-
Notifications
You must be signed in to change notification settings - Fork 2
/
create_qmd_file.R
65 lines (60 loc) · 2.67 KB
/
create_qmd_file.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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
create_qmd_file <- function(filename = "index.qmd", title = "", date = Sys.Date(),
categories = c("code", "rtip"),
keywords = c("Programming")) {
# Define the base path
base_path <- paste0(getwd(),"/posts")
# Convert date to string and create the full directory path
date_str <- as.character(date)
full_path <- file.path(base_path, date_str)
# Create the directory if it doesn't exist
if (!dir.exists(full_path)) {
dir.create(full_path, recursive = TRUE)
message("Directory created: ", full_path)
}
# Define the full file path
file_path <- file.path(full_path, filename)
# Create the content to be written in the file
content <- paste0(
"---\n",
'title: "', title, '"\n',
'author: "Steven P. Sanderson II, MPH"\n',
'date: "', date_str, '"\n',
"categories: [", paste(categories, collapse = ", "), "]\n",
"toc: TRUE\n",
"description: ''\n",
"keywords: [", paste(keywords, collapse = ", "), "]\n",
"---\n\n",
'---\n\n',
'Happy Coding! 🚀\n\n',
'---\n\n',
'*You can connect with me at any one of the below*:\n\n',
'*Telegram Channel here*: [https://t.me/steveondata](https://t.me/steveondata)\n\n',
'*LinkedIn Network here*: [https://www.linkedin.com/in/spsanderson/](https://www.linkedin.com/in/spsanderson/)\n\n',
'*Mastadon Social here*: [https://mstdn.social/@stevensanderson](https://mstdn.social/@stevensanderson)\n\n',
'*RStats Network here*: [https://rstats.me/@spsanderson](https://rstats.me/@spsanderson)\n\n',
'*GitHub Network here*: [https://github.com/spsanderson](https://github.com/spsanderson)\n\n',
'*Bluesky Network here*: [https://bsky.app/profile/spsanderson.com](https://bsky.app/profile/spsanderson.com)\n\n',
'*My Book: _Extending Excel with Python and R_ here*: [https://packt.link/oTyZJ](https://packt.link/oTyZJ)\n\n',
'---\n\n',
'<script src="https://giscus.app/client.js"\n',
' data-repo="spsanderson/steveondata"\n',
' data-repo-id="R_kgDOIIxnLw"\n',
' data-category="Comments"\n',
' data-category-id="DIC_kwDOIIxnL84ChTk8"\n',
' data-mapping="url"\n',
' data-strict="0"\n',
' data-reactions-enabled="1"\n',
' data-emit-metadata="0"\n',
' data-input-position="top"\n',
' data-theme="dark"\n',
' data-lang="en"\n',
' data-loading="lazy"\n',
' crossorigin="anonymous"\n',
' async>\n',
'</script>\n'
)
# Write the content to the file
writeLines(content, file_path)
message("QMD file created: ", file_path, " - Opening File.")
file.edit(file_path)
}