Skip to content

Commit

Permalink
need to normalize the output formats when reading _litedown.yml for b…
Browse files Browse the repository at this point in the history
…ooks/sites
  • Loading branch information
yihui committed Jan 8, 2025
1 parent c7a61e5 commit b4890d5
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 8 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Package: litedown
Type: Package
Title: A Lightweight Version of R Markdown
Version: 0.5.2
Version: 0.5.3
Authors@R: c(
person("Yihui", "Xie", role = c("aut", "cre"), email = "[email protected]", comment = c(ORCID = "0000-0003-0645-5666", URL = "https://yihui.org")),
person("Tim", "Taylor", role = "ctb", comment = c(ORCID = "0000-0002-8587-7113")),
Expand Down
17 changes: 11 additions & 6 deletions R/format.R
Original file line number Diff line number Diff line change
Expand Up @@ -99,13 +99,18 @@ map_args = function(
list(meta = meta, options = opts, ...)
}

# split YAML and body from text input, and normalize rmarkdown output formats in
# YAML to litedown's formats
# split YAML and body from text input
yaml_body = function(text, ...) {
res = xfun::yaml_body(text, use_yaml = FALSE, ...)
if (!length(out <- res$yaml[['output']])) {
if (!is.null(yaml <- normalize_yaml(res$yaml))) res$yaml = yaml
res
}

# normalize (rmarkdown) output formats in YAML to litedown's formats
normalize_yaml = function(x) {
if (!length(out <- x[['output']])) {
# if the key 'format' is provided, normalize it to 'output'
if (length(out <- res$yaml[['format']])) res$yaml$format = NULL else return(res)
if (length(out <- x[['format']])) x$format = NULL else return()
}
if (is.character(out)) out = set_names(vector('list', length(out)), out)
if (!is.list(out))
Expand All @@ -117,8 +122,8 @@ yaml_body = function(text, ...) {
}
# normalize format names `(lite|mark)down::*_format` to `*`
names(out) = gsub('^(lite|mark)down::+([^_]+)_.*', '\\2', names(out))
res$yaml$output = out
res
x$output = out
x
}

# get metadata from a certain field under an output format
Expand Down
6 changes: 5 additions & 1 deletion R/site.R
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,11 @@ fuse_book = function(input = '.', output = NULL, envir = parent.frame()) {

# read the config file _litedown.yml
yml_config = function(d) {
if (file_exists(cfg <- file.path(d, '_litedown.yml'))) xfun::taml_file(cfg)
if (file_exists(cfg <- file.path(d, '_litedown.yml'))) {
yaml = xfun::taml_file(cfg)
if (!is.null(yaml2 <- normalize_yaml(yaml))) yaml = yaml2
yaml
}
}

site_pattern = '[.][Rq]?md$'
Expand Down

0 comments on commit b4890d5

Please sign in to comment.