From c20ea5fda9ec82161cd8ec73363471bf460d8f47 Mon Sep 17 00:00:00 2001 From: shrektan Date: Sat, 17 Aug 2024 18:03:28 +0800 Subject: [PATCH 1/2] add download src files to support the current website change --- R/package.R | 2 +- tools/download_src_files.R | 100 +++++++++++++++++++++++++++++++++++++ 2 files changed, 101 insertions(+), 1 deletion(-) create mode 100644 tools/download_src_files.R diff --git a/R/package.R b/R/package.R index 9a113d7c..53530d8d 100644 --- a/R/package.R +++ b/R/package.R @@ -5,4 +5,4 @@ #' @import stats utils NULL -DataTablesVersion = '1.13.6' +DataTablesVersion = "2.1.4" diff --git a/tools/download_src_files.R b/tools/download_src_files.R new file mode 100644 index 00000000..af8cf3fc --- /dev/null +++ b/tools/download_src_files.R @@ -0,0 +1,100 @@ +# Update the html_text variable with the latest DataTables CDN links +# To update: +# 1. Visit https://datatables.net/download/index +# 2. Select all default options except "Extensions" +# 3. At the bottom of the page, click the "CDN" panel +# 4. Choose "Minified" but not "Concatenated" +# 5. Copy the entire CDN panel content +# 6. Replace the html_text variable below with the copied content +# +# Note: This ensures we always have the most up-to-date DataTables resources +# while maintaining a consistent structure for our download process. + + +html_text = r"{ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +}" + +download_datatables_files = function(html_text) { + # Create the base directory + dir.create("download/DataTables", recursive = TRUE, showWarnings = FALSE) + + # Extract URLs from the HTML text + urls = unlist(regmatches(html_text, gregexpr("https://[^\"]+", html_text))) + + # replace all the xxx.js to xxx.min.js, except xxx.min.js + # Replace xxx.js with xxx.min.js, except for already minified files + urls = gsub("(? Date: Sat, 17 Aug 2024 18:11:23 +0800 Subject: [PATCH 2/2] tweak the download script --- tools/download_src_files.R | 27 ++++++++++++++++++--------- 1 file changed, 18 insertions(+), 9 deletions(-) diff --git a/tools/download_src_files.R b/tools/download_src_files.R index af8cf3fc..46e9eb5e 100644 --- a/tools/download_src_files.R +++ b/tools/download_src_files.R @@ -10,10 +10,10 @@ # Note: This ensures we always have the most up-to-date DataTables resources # while maintaining a consistent structure for our download process. - +version = "2.1.4" # this must be the same as the version in the html_text html_text = r"{ - + @@ -31,7 +31,7 @@ html_text = r"{ - + @@ -52,10 +52,14 @@ html_text = r"{ }" - download_datatables_files = function(html_text) { - # Create the base directory - dir.create("download/DataTables", recursive = TRUE, showWarnings = FALSE) + # Define the base directory as a variable + base_dir = "download/DataTables" + # Create the base directory and ensure it's empty + if (dir.exists(base_dir)) { + unlink(base_dir, recursive = TRUE) + } + dir.create(base_dir, recursive = TRUE, showWarnings = FALSE) # Extract URLs from the HTML text urls = unlist(regmatches(html_text, gregexpr("https://[^\"]+", html_text))) @@ -66,8 +70,8 @@ download_datatables_files = function(html_text) { # Use non-minified versions for 'pdfmake.js' and 'vfs_fonts.js' # This is due to compatibility issues with pdfmake.min.js on Windows for self-contained HTML pages # Reference: https://github.com/rstudio/DT/issues/774#issuecomment-595277726 - urls = gsub("pdfmake\\.min\\.js", "pdfmake.js", urls, fixed = TRUE) - urls = gsub("vfs_fonts\\.min\\.js", "vfs_fonts.js", urls, fixed = TRUE) + urls = gsub("pdfmake.min.js", "pdfmake.js", urls, fixed = TRUE) + urls = gsub("vfs_fonts.min.js", "vfs_fonts.js", urls, fixed = TRUE) # Download and save each file for (url in urls) { @@ -78,7 +82,7 @@ download_datatables_files = function(html_text) { rel_path = gsub("/[0-9.]+/", "/", rel_path) # Create the full local path - local_path = file.path("download/DataTables", rel_path) + local_path = file.path(base_dir, rel_path) # Ensure the directory exists dir.create(dirname(local_path), recursive = TRUE, showWarnings = FALSE) @@ -94,6 +98,11 @@ download_datatables_files = function(html_text) { } ) } + # should change the download/$version$/* to download/datatables/* + file.rename( + from = sprintf("%s/%s", base_dir, version), + to = sprintf("%s/datatables", base_dir) + ) } # Run