Skip to content

Commit 7b3f5cd

Browse files
use html_fragment and default to full rss
1 parent c9c730c commit 7b3f5cd

1 file changed

Lines changed: 3 additions & 10 deletions

File tree

R/sitemap.R

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -126,16 +126,11 @@ write_feed_xml_html_content <- function(input_path, article, site_config) {
126126

127127
# fix headers
128128
rmd_content <- paste0(readLines(input_path), collapse = "\n")
129-
headers <- stringr::str_locate_all(rmd_content, "---")
130-
if (nrow(headers[[1]]) >= 2) {
131-
rmd_content <- stringr::str_sub(rmd_content, headers[[1]][2,2] + 1)
132-
}
133-
134129
writeLines(rmd_content, rmd_file)
135130

136131
# render doc
137132
rmarkdown::render(rmd_file,
138-
output_format = "html_document",
133+
output_format = "html_fragment",
139134
output_file = html_file,
140135
quiet = TRUE,
141136
output_options = list(
@@ -145,8 +140,6 @@ write_feed_xml_html_content <- function(input_path, article, site_config) {
145140

146141
# extract body
147142
html_contents <- paste(readLines(html_file), collapse = "\n")
148-
html_contents <- gsub(".*<body[^>]*>", "", html_contents)
149-
html_contents <- gsub("</body>.*", "", html_contents)
150143

151144
# fix image paths
152145
html_contents <- gsub(paste0(basename(dirname(rmd_file)), "/"),
@@ -180,7 +173,7 @@ write_feed_xml <- function(feed_xml, site_config, collection, articles) {
180173
"xmlns:dc" = "http://purl.org/dc/elements/1.1/"
181174
)
182175

183-
if (identical(site_config$rss$full_content, TRUE))
176+
if (!identical(site_config$rss$full_content, FALSE))
184177
namespaces <- c(namespaces, list("xmlns:distill" = "https://distill.pub/journal/"))
185178

186179
# create document root
@@ -240,7 +233,7 @@ write_feed_xml <- function(feed_xml, site_config, collection, articles) {
240233
add_child(item, "link", text = article$base_url)
241234

242235
full_content_path <- NULL
243-
if (identical(site_config$rss$full_content, TRUE) && is.character(article$input_file)) {
236+
if (!identical(site_config$rss$full_content, FALSE) && is.character(article$input_file)) {
244237
guess_rmd <- paste0(gsub("\\.utf.*\\.md|\\.md", "", article$input_file), ".Rmd")
245238
full_content_path <- dir(getwd(), pattern = guess_rmd, full.names = TRUE, recursive = TRUE)
246239
}

0 commit comments

Comments
 (0)