10
10
# Note: This ensures we always have the most up-to-date DataTables resources
11
11
# while maintaining a consistent structure for our download process.
12
12
13
-
13
+ version = " 2.1.4 " # this must be the same as the version in the html_text
14
14
html_text = r " {
15
15
<link href=" https : // cdn.datatables.net / 2.1.4 / css / dataTables.dataTables.min.css " rel=" stylesheet " >
16
- <link href=" https : // cdn.datatables.net / autofill / 2.7.0 / css / autoFill.dataTables.min. css " rel=" stylesheet " >
16
+ <link href=" https : // cdn.datatables.net / autofill / 2.7.0 / css / autoFill.dataTables.css " rel=" stylesheet " >
17
17
<link href=" https : // cdn.datatables.net / buttons / 3.1.1 / css / buttons.dataTables.min.css " rel=" stylesheet " >
18
18
<link href=" https : // cdn.datatables.net / colreorder / 2.0.4 / css / colReorder.dataTables.min.css " rel=" stylesheet " >
19
19
<link href=" https : // cdn.datatables.net / datetime / 1.5.3 / css / dataTables.dateTime.min.css " rel=" stylesheet " >
@@ -31,7 +31,7 @@ html_text = r"{
31
31
32
32
<script src=" https : // cdnjs.cloudflare.com / ajax / libs / jszip / 3.10.1 / jszip.min.js " ></script>
33
33
<script src=" https : // cdnjs.cloudflare.com / ajax / libs / pdfmake / 0.2.7 / pdfmake.min.js " ></script>
34
- <script src=" https : // cdnjs.cloudflare.com / ajax / libs / pdfmake / 0.2.7 / vfs_fonts.min. js " ></script>
34
+ <script src=" https : // cdnjs.cloudflare.com / ajax / libs / pdfmake / 0.2.7 / vfs_fonts.js " ></script>
35
35
<script src=" https : // cdn.datatables.net / 2.1.4 / js / dataTables.min.js " ></script>
36
36
<script src=" https : // cdn.datatables.net / autofill / 2.7.0 / js / dataTables.autoFill.min.js " ></script>
37
37
<script src=" https : // cdn.datatables.net / buttons / 3.1.1 / js / dataTables.buttons.min.js " ></script>
@@ -52,10 +52,14 @@ html_text = r"{
52
52
<script src=" https : // cdn.datatables.net / select / 2.0.5 / js / dataTables.select.min.js " ></script>
53
53
<script src=" https : // cdn.datatables.net / staterestore / 1.4.1 / js / dataTables.stateRestore.min.js " ></script>
54
54
}"
55
-
56
55
download_datatables_files = function (html_text ) {
57
- # Create the base directory
58
- dir.create(" download/DataTables" , recursive = TRUE , showWarnings = FALSE )
56
+ # Define the base directory as a variable
57
+ base_dir = " download/DataTables"
58
+ # Create the base directory and ensure it's empty
59
+ if (dir.exists(base_dir )) {
60
+ unlink(base_dir , recursive = TRUE )
61
+ }
62
+ dir.create(base_dir , recursive = TRUE , showWarnings = FALSE )
59
63
60
64
# Extract URLs from the HTML text
61
65
urls = unlist(regmatches(html_text , gregexpr(" https://[^\" ]+" , html_text )))
@@ -66,8 +70,8 @@ download_datatables_files = function(html_text) {
66
70
# Use non-minified versions for 'pdfmake.js' and 'vfs_fonts.js'
67
71
# This is due to compatibility issues with pdfmake.min.js on Windows for self-contained HTML pages
68
72
# Reference: https://github.com/rstudio/DT/issues/774#issuecomment-595277726
69
- urls = gsub(" pdfmake\\ .min\\ .js" , " pdfmake.js" , urls , fixed = TRUE )
70
- urls = gsub(" vfs_fonts\\ .min\\ .js" , " vfs_fonts.js" , urls , fixed = TRUE )
73
+ urls = gsub(" pdfmake.min.js" , " pdfmake.js" , urls , fixed = TRUE )
74
+ urls = gsub(" vfs_fonts.min.js" , " vfs_fonts.js" , urls , fixed = TRUE )
71
75
72
76
# Download and save each file
73
77
for (url in urls ) {
@@ -78,7 +82,7 @@ download_datatables_files = function(html_text) {
78
82
rel_path = gsub(" /[0-9.]+/" , " /" , rel_path )
79
83
80
84
# Create the full local path
81
- local_path = file.path(" download/DataTables " , rel_path )
85
+ local_path = file.path(base_dir , rel_path )
82
86
83
87
# Ensure the directory exists
84
88
dir.create(dirname(local_path ), recursive = TRUE , showWarnings = FALSE )
@@ -94,6 +98,11 @@ download_datatables_files = function(html_text) {
94
98
}
95
99
)
96
100
}
101
+ # should change the download/$version$/* to download/datatables/*
102
+ file.rename(
103
+ from = sprintf(" %s/%s" , base_dir , version ),
104
+ to = sprintf(" %s/datatables" , base_dir )
105
+ )
97
106
}
98
107
99
108
# Run
0 commit comments