-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.qmd
136 lines (115 loc) · 2.79 KB
/
index.qmd
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
---
# title: My Slides
author: ""
format: html
# format: native
# filters:
# - generate_table.lua
# https://quarto.org/docs/websites/website-listings-custom.html
# listing:
# contents:
# - slides
# sort: "date desc"
# type: default
---
## My Slides
```{r}
#| echo: false
#| output: asis
# 設定資料夾路徑
folder_path <- "slides"
# 找出所有的 index.qmd 檔案
qmd_files <- list.files(path = folder_path, pattern = "index\\.qmd$", recursive = TRUE, full.names = TRUE)
# 篩選出同資料夾內有 index.html 的 index.qmd 檔案
qmd_files_with_html <- qmd_files[sapply(qmd_files, function(file) {
html_file <- gsub("index\\.qmd$", "index.html", file)
file.exists(html_file)
})]
is_null <- function(d) {
if (is.null(d)) {
return("3000-01-01")
} else {
return(d)
}
}
df <- data.frame("Date" = numeric(0), "Title" = numeric(0))
for (i in qmd_files_with_html) {
file_content <- rmarkdown:::read_utf8(i)
yaml_content <- rmarkdown:::parse_yaml_front_matter(file_content)
new_row <- data.frame(
"Date" = is_null(yaml_content$date),
"Title" = paste0("[", yaml_content$title, "](", dirname(i), ")")
)
df <- rbind(df, new_row)
}
# 將 'date' column 的型態轉換為日期
df$Date <- as.Date(df$Date)
# 根據 'date' 進行升序排序
sorted_df <- df[order(df$Date), ]
# 顯示排序後的 dataframe
cat("Date | Title\n")
cat("------- | -------\n")
result <- ""
for (i in 1:nrow(sorted_df)) {
result <- paste0(
result,
as.character(sorted_df[i, 1]),
" | ",
as.character(sorted_df[i, 2]),
"\n"
)
}
cat(result)
```
```{r}
#| echo: false
content1 <- paste0(
"## My Slides
Date | Title
------- | -------\n", result
)
# writeLines(content, "README.md")
```
### Note
```{r}
#| echo: false
#| output: asis
# 設定資料夾路徑
folder_path <- "note"
# 找出所有的 index.qmd 檔案
qmd_files <- list.files(path = folder_path, pattern = "index\\.qmd$", recursive = TRUE, full.names = TRUE)
# 篩選出同資料夾內有 index.html 的 index.qmd 檔案
qmd_files_with_html <- qmd_files[sapply(qmd_files, function(file) {
html_file <- gsub("index\\.qmd$", "index.html", file)
file.exists(html_file)
})]
df <- data.frame("Title" = numeric(0))
for (i in qmd_files_with_html) {
file_content <- rmarkdown:::read_utf8(i)
yaml_content <- rmarkdown:::parse_yaml_front_matter(file_content)
new_row <- data.frame(
# "Date" = is_null(yaml_content$date),
"Title" = paste0("- [", yaml_content$title, "](", dirname(i), ")")
)
df <- rbind(df, new_row)
}
result <- ""
for (i in 1:nrow(df)) {
result <- paste0(
result,
as.character(df[i, 1]),
"\n"
)
}
cat(result)
```
```{r}
#| echo: false
content2 <- paste0(
"## Note
", result
)
# concat content1 and content2
content <- paste0(content1 ,'\n\n', content2)
writeLines(content, "README.md")
```