Skip to content

Commit

Permalink
close #769: throw a clearer error when using "Update Metadata" in the…
Browse files Browse the repository at this point in the history
… visual editor
  • Loading branch information
yihui committed Mar 3, 2025
1 parent 0be2202 commit d5de188
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 4 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Type: Package
Package: blogdown
Title: Create Blogs and Websites with R Markdown
Version: 1.20.2
Version: 1.20.3
Authors@R: c(
person("Yihui", "Xie", role = c("aut", "cre"), email = "[email protected]", comment = c(ORCID = "0000-0003-0645-5666")),
person("Christophe", "Dervieux", role = "aut", email = "[email protected]", comment = c(ORCID = "0000-0003-4474-2498")),
Expand Down
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

- Use the `--renderToMemory` flag by default for Hugo >= 0.123.0 when starting `hugo server` (thanks, @drmowinckels, #772). If you do not wish to use this flag by default, please see https://bookdown.org/yihui/blogdown/livereload.html on how to configure your own default flags for `hugo server`.

- Throw a clearer error when using the RStudio addin "Update Metadata" in the visual editor (thanks, @setgree, #769).

# CHANGES IN blogdown VERSION 1.20

- Redirect the wowchemy themes to HugoBlox.
Expand Down
8 changes: 5 additions & 3 deletions inst/scripts/update_meta.R
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@ sel_input = function(...) shiny::selectizeInput(
meta = blogdown:::collect_yaml()

ctxt = rstudioapi::getSourceEditorContext(); txt = ctxt$contents
res = blogdown:::split_yaml_body(txt); yml = res$yaml_list; rng = res$yaml_range
if (length(yml) == 0) return(
warning("The current document does not seem to contain YAML metadata", call. = FALSE)
if (length(ctxt$selection) == 0) stop(
'The document seems to be in the visual editor. Please put the cursor in YAML ',
'or switch to the source editor.', call. = FALSE
)
res = blogdown:::split_yaml_body(txt); yml = res$yaml_list; rng = res$yaml_range
if (length(rng) != 2) stop('Cannot find YAML metadata in the current document.', call. = FALSE)
rstudioapi::setSelectionRanges(list(c(rng[1] + 1, 1, rng[2], 1)))
slct = rstudioapi::getSourceEditorContext()$selection[[1]]

Expand Down

0 comments on commit d5de188

Please sign in to comment.