Skip to content

Commit c20ea5f

Browse files
committed
add download src files to support the current website change
1 parent 4e63a46 commit c20ea5f

File tree

2 files changed

+101
-1
lines changed

2 files changed

+101
-1
lines changed

R/package.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,4 @@
55
#' @import stats utils
66
NULL
77

8-
DataTablesVersion = '1.13.6'
8+
DataTablesVersion = "2.1.4"

tools/download_src_files.R

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
# Update the html_text variable with the latest DataTables CDN links
2+
# To update:
3+
# 1. Visit https://datatables.net/download/index
4+
# 2. Select all default options except "Extensions"
5+
# 3. At the bottom of the page, click the "CDN" panel
6+
# 4. Choose "Minified" but not "Concatenated"
7+
# 5. Copy the entire CDN panel content
8+
# 6. Replace the html_text variable below with the copied content
9+
#
10+
# Note: This ensures we always have the most up-to-date DataTables resources
11+
# while maintaining a consistent structure for our download process.
12+
13+
14+
html_text = r"{
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">
17+
<link href="https://cdn.datatables.net/buttons/3.1.1/css/buttons.dataTables.min.css" rel="stylesheet">
18+
<link href="https://cdn.datatables.net/colreorder/2.0.4/css/colReorder.dataTables.min.css" rel="stylesheet">
19+
<link href="https://cdn.datatables.net/datetime/1.5.3/css/dataTables.dateTime.min.css" rel="stylesheet">
20+
<link href="https://cdn.datatables.net/fixedcolumns/5.0.1/css/fixedColumns.dataTables.min.css" rel="stylesheet">
21+
<link href="https://cdn.datatables.net/fixedheader/4.0.1/css/fixedHeader.dataTables.min.css" rel="stylesheet">
22+
<link href="https://cdn.datatables.net/keytable/2.12.1/css/keyTable.dataTables.min.css" rel="stylesheet">
23+
<link href="https://cdn.datatables.net/responsive/3.0.2/css/responsive.dataTables.min.css" rel="stylesheet">
24+
<link href="https://cdn.datatables.net/rowgroup/1.5.0/css/rowGroup.dataTables.min.css" rel="stylesheet">
25+
<link href="https://cdn.datatables.net/rowreorder/1.5.0/css/rowReorder.dataTables.min.css" rel="stylesheet">
26+
<link href="https://cdn.datatables.net/scroller/2.4.3/css/scroller.dataTables.min.css" rel="stylesheet">
27+
<link href="https://cdn.datatables.net/searchbuilder/1.8.0/css/searchBuilder.dataTables.min.css" rel="stylesheet">
28+
<link href="https://cdn.datatables.net/searchpanes/2.3.2/css/searchPanes.dataTables.min.css" rel="stylesheet">
29+
<link href="https://cdn.datatables.net/select/2.0.5/css/select.dataTables.min.css" rel="stylesheet">
30+
<link href="https://cdn.datatables.net/staterestore/1.4.1/css/stateRestore.dataTables.min.css" rel="stylesheet">
31+
32+
<script src="https://cdnjs.cloudflare.com/ajax/libs/jszip/3.10.1/jszip.min.js"></script>
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>
35+
<script src="https://cdn.datatables.net/2.1.4/js/dataTables.min.js"></script>
36+
<script src="https://cdn.datatables.net/autofill/2.7.0/js/dataTables.autoFill.min.js"></script>
37+
<script src="https://cdn.datatables.net/buttons/3.1.1/js/dataTables.buttons.min.js"></script>
38+
<script src="https://cdn.datatables.net/buttons/3.1.1/js/buttons.colVis.min.js"></script>
39+
<script src="https://cdn.datatables.net/buttons/3.1.1/js/buttons.html5.min.js"></script>
40+
<script src="https://cdn.datatables.net/buttons/3.1.1/js/buttons.print.min.js"></script>
41+
<script src="https://cdn.datatables.net/colreorder/2.0.4/js/dataTables.colReorder.min.js"></script>
42+
<script src="https://cdn.datatables.net/datetime/1.5.3/js/dataTables.dateTime.min.js"></script>
43+
<script src="https://cdn.datatables.net/fixedcolumns/5.0.1/js/dataTables.fixedColumns.min.js"></script>
44+
<script src="https://cdn.datatables.net/fixedheader/4.0.1/js/dataTables.fixedHeader.min.js"></script>
45+
<script src="https://cdn.datatables.net/keytable/2.12.1/js/dataTables.keyTable.min.js"></script>
46+
<script src="https://cdn.datatables.net/responsive/3.0.2/js/dataTables.responsive.min.js"></script>
47+
<script src="https://cdn.datatables.net/rowgroup/1.5.0/js/dataTables.rowGroup.min.js"></script>
48+
<script src="https://cdn.datatables.net/rowreorder/1.5.0/js/dataTables.rowReorder.min.js"></script>
49+
<script src="https://cdn.datatables.net/scroller/2.4.3/js/dataTables.scroller.min.js"></script>
50+
<script src="https://cdn.datatables.net/searchbuilder/1.8.0/js/dataTables.searchBuilder.min.js"></script>
51+
<script src="https://cdn.datatables.net/searchpanes/2.3.2/js/dataTables.searchPanes.min.js"></script>
52+
<script src="https://cdn.datatables.net/select/2.0.5/js/dataTables.select.min.js"></script>
53+
<script src="https://cdn.datatables.net/staterestore/1.4.1/js/dataTables.stateRestore.min.js"></script>
54+
}"
55+
56+
download_datatables_files = function(html_text) {
57+
# Create the base directory
58+
dir.create("download/DataTables", recursive = TRUE, showWarnings = FALSE)
59+
60+
# Extract URLs from the HTML text
61+
urls = unlist(regmatches(html_text, gregexpr("https://[^\"]+", html_text)))
62+
63+
# replace all the xxx.js to xxx.min.js, except xxx.min.js
64+
# Replace xxx.js with xxx.min.js, except for already minified files
65+
urls = gsub("(?<!min)\\.js$", ".min.js", urls, perl = TRUE)
66+
# Use non-minified versions for 'pdfmake.js' and 'vfs_fonts.js'
67+
# This is due to compatibility issues with pdfmake.min.js on Windows for self-contained HTML pages
68+
# 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)
71+
72+
# Download and save each file
73+
for (url in urls) {
74+
# Extract the relative path from the URL
75+
rel_path = sub("^https://[^/]+/", "", url)
76+
77+
# Remove version part from the path
78+
rel_path = gsub("/[0-9.]+/", "/", rel_path)
79+
80+
# Create the full local path
81+
local_path = file.path("download/DataTables", rel_path)
82+
83+
# Ensure the directory exists
84+
dir.create(dirname(local_path), recursive = TRUE, showWarnings = FALSE)
85+
86+
# Download the file
87+
tryCatch(
88+
{
89+
utils::download.file(url, local_path, mode = "wb")
90+
cat("Downloaded:", url, "to", local_path, "\n")
91+
},
92+
error = function(e) {
93+
cat("Error downloading:", url, "-", e$message, "\n")
94+
}
95+
)
96+
}
97+
}
98+
99+
# Run
100+
download_datatables_files(html_text)

0 commit comments

Comments
 (0)