-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathbuild_site.sh
More file actions
executable file
·74 lines (62 loc) · 2.29 KB
/
build_site.sh
File metadata and controls
executable file
·74 lines (62 loc) · 2.29 KB
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
#!/usr/bin/env bash
set -e
# Directory where all generated HTML (and *_files dirs) will go
BUILD_DIR="_site"
# Clean previous build
rm -rf "$BUILD_DIR"
mkdir -p "$BUILD_DIR"
# Run the R parts
Rscript - <<'RSCRIPT'
# Install any missing packages
needed <- c("rmarkdown","knitr","dcurves","tidyverse","gtsummary",
"here","reticulate","rsample")
missing <- setdiff(needed, rownames(installed.packages()))
if (length(missing)) install.packages(missing, repos = "https://cloud.r-project.org")
# Build language-specific tutorial pages
languages <- c("r","stata","sas","python")
for (lang in languages) {
rmarkdown::render(
input = "dca-tutorial.Rmd",
output_file = sprintf("dca-tutorial-%s.html", lang),
output_dir = "_site",
params = list(language = lang),
quiet = TRUE
)
}
# Render each .Rmd file with output dir set to _site
site_files <- list.files(pattern = "\\.(R|r)md$",
include.dirs = FALSE,
recursive = FALSE)
# Skip dca-tutorial.Rmd (already handled above)
site_files <- site_files[site_files != "dca-tutorial.Rmd"]
# Render each file to _site
for (file in site_files) {
cat("Rendering:", file, "\n")
rmarkdown::render(
input = file,
output_dir = "_site",
quiet = TRUE
)
}
RSCRIPT
# After R is done, clean up any stray files
find . -maxdepth 1 -type f -name "*.html" ! -path "./_site/*" -exec rm -f {} \;
find . -maxdepth 1 -type d -name "*_files" ! -path "./_site" -exec rm -rf {} \;
# Clean up temporary knit files
find . -maxdepth 1 -type f -name "*.knit*.md" -exec rm -f {} \;
find . -maxdepth 1 -type f -name "*.utf8.md" -exec rm -f {} \;
# Create a default tutorial page (copy of R version) to make navigation work
cp "$BUILD_DIR/dca-tutorial-r.html" "$BUILD_DIR/dca-tutorial.html" 2>/dev/null || true
echo -e "\n✅ Local site built in ${BUILD_DIR}/"
# Check for any remaining temporary files
TEMP_FILES=$(find . -maxdepth 1 -type f \( -name "*.knit*" -o -name "*.utf8.md" -o -name "*.md.bak" \))
if [ -n "$TEMP_FILES" ]; then
echo -e "\n⚠️ Warning: These temporary files still exist:"
echo "$TEMP_FILES"
fi
# Open the site
if command -v open &>/dev/null; then
open "${BUILD_DIR}/index.html"
elif command -v xdg-open &>/dev/null; then
xdg-open "${BUILD_DIR}/index.html" &>/dev/null &
fi