Skip to content

Commit 00d768c

Browse files
committed
provide a method to easily force the version of a jsdelivr package, i.e., pass a version number to the force argument of jsd_version()
1 parent c1954a8 commit 00d768c

File tree

4 files changed

+21
-11
lines changed

4 files changed

+21
-11
lines changed

.github/workflows/R-CMD-check.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ jobs:
8484
Rscript -e 'install.packages("xfun", repos="https://yihui.r-universe.dev")'
8585
Rscript -e 'litedown::fuse_book("docs")'
8686
cd docs; cp -r *.html ../gh-pages/; cd ../gh-pages
87-
git config user.name "Yihui Xie"
88-
git config user.email "[email protected]"
87+
git config user.name github-actions
88+
git config user.email [email protected]
8989
git add .
9090
git commit -m "update docs" && git push && curl -X POST ${{secrets.URL_DEPLOY_DOCS}} || true

DESCRIPTION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Package: litedown
22
Type: Package
33
Title: A Lightweight Version of R Markdown
4-
Version: 0.5.4
4+
Version: 0.5.5
55
Authors@R: c(
66
person("Yihui", "Xie", role = c("aut", "cre"), email = "[email protected]", comment = c(ORCID = "0000-0003-0645-5666", URL = "https://yihui.org")),
77
person("Tim", "Taylor", role = "ctb", comment = c(ORCID = "0000-0002-8587-7113")),

R/mark.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -409,7 +409,7 @@ mark = function(input, output = NULL, text = NULL, options = NULL, meta = list()
409409
# for RStudio to capture the output path when previewing the output
410410
if (is_rmd_preview()) message('\nOutput created: ', output)
411411
if (is_pdf) invisible(output) else write_utf8(ret, output)
412-
} else raw_string(ret, lang = format)
412+
} else raw_string(ret) # TODO: (lang = format) with xfun 0.51
413413
}
414414

415415
# insert body and meta variables into a template

R/utils.R

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1089,11 +1089,21 @@ jsd_version = local({
10891089
}
10901090
file.path(d, 'jsd_versions.rds')
10911091
}
1092+
# update cache to a specific version
1093+
u_cache = function(info, pkg, version, file) {
1094+
info[[pkg]] = list(version = version, time = Sys.time())
1095+
saveRDS(info, file)
1096+
}
10921097
# cache expires after one week by default
10931098
v_cache = function(pkg, force, delta = getOption('litedown.jsdelivr.cache', 604800)) {
1094-
if (!force && file.exists(f <- p_cache())) {
1095-
info = readRDS(f)[[pkg]]
1096-
if (!is.null(t <- info$time) && Sys.time() - t <= delta) info$version
1099+
if (!isTRUE(force) && file.exists(f <- p_cache())) {
1100+
info = readRDS(f)
1101+
if (is.character(force)) {
1102+
u_cache(info, pkg, force, f)
1103+
} else {
1104+
info = info[[pkg]]
1105+
if (!is.null(t <- info$time) && Sys.time() - t <= delta) info$version
1106+
}
10971107
}
10981108
}
10991109
# query version from jsdelivr api
@@ -1106,16 +1116,16 @@ jsd_version = local({
11061116
if (length(v)) {
11071117
if (dir_create(dirname(f <- p_cache()))) {
11081118
info = if (file.exists(f)) readRDS(f) else list()
1109-
info[[pkg]] = list(version = v[1], time = Sys.time())
1110-
saveRDS(info, f)
1119+
u_cache(info, pkg, v[1], f)
11111120
}
11121121
v[1]
11131122
}
11141123
}
1124+
# force can be TRUE/FALSE/version number
11151125
function(pkg, force = FALSE) {
1116-
if (!force && is.character(v <- vers[[pkg]])) return(v)
1126+
if (isFALSE(force) && is.character(v <- vers[[pkg]])) return(v)
11171127
v = v_cache(pkg, force) %||% v_api(pkg)
1118-
vers[[pkg]] <<- if (length(v)) v[1] else ''
1128+
(vers[[pkg]] <<- if (length(v)) v[1] else '')
11191129
}
11201130
})
11211131

0 commit comments

Comments
 (0)