From c9c730c07f676aa07f33028478ba8e0eb26c0db2 Mon Sep 17 00:00:00 2001 From: Javier Luraschi Date: Thu, 24 Sep 2020 18:43:29 -0700 Subject: [PATCH 1/3] avoid cutoff rss in posts with tables --- R/sitemap.R | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/R/sitemap.R b/R/sitemap.R index 73dc284e..2d5174b9 100644 --- a/R/sitemap.R +++ b/R/sitemap.R @@ -126,7 +126,11 @@ write_feed_xml_html_content <- function(input_path, article, site_config) { # fix headers rmd_content <- paste0(readLines(input_path), collapse = "\n") - rmd_content <- gsub("---.*---", "", rmd_content) + headers <- stringr::str_locate_all(rmd_content, "---") + if (nrow(headers[[1]]) >= 2) { + rmd_content <- stringr::str_sub(rmd_content, headers[[1]][2,2] + 1) + } + writeLines(rmd_content, rmd_file) # render doc From e982b240ad08566eea0409d438b22dcf10a45284 Mon Sep 17 00:00:00 2001 From: Javier Luraschi Date: Fri, 25 Sep 2020 09:31:13 -0700 Subject: [PATCH 2/3] use html_fragment and default to full rss --- R/sitemap.R | 17 +++-------------- distill-r.Rproj | 2 -- 2 files changed, 3 insertions(+), 16 deletions(-) diff --git a/R/sitemap.R b/R/sitemap.R index 2d5174b9..bc5fa7e7 100644 --- a/R/sitemap.R +++ b/R/sitemap.R @@ -124,18 +124,9 @@ write_feed_xml_html_content <- function(input_path, article, site_config) { to = rmd_dir, recursive = TRUE) - # fix headers - rmd_content <- paste0(readLines(input_path), collapse = "\n") - headers <- stringr::str_locate_all(rmd_content, "---") - if (nrow(headers[[1]]) >= 2) { - rmd_content <- stringr::str_sub(rmd_content, headers[[1]][2,2] + 1) - } - - writeLines(rmd_content, rmd_file) - # render doc rmarkdown::render(rmd_file, - output_format = "html_document", + output_format = "html_fragment", output_file = html_file, quiet = TRUE, output_options = list( @@ -145,8 +136,6 @@ write_feed_xml_html_content <- function(input_path, article, site_config) { # extract body html_contents <- paste(readLines(html_file), collapse = "\n") - html_contents <- gsub(".*]*>", "", html_contents) - html_contents <- gsub(".*", "", html_contents) # fix image paths html_contents <- gsub(paste0(basename(dirname(rmd_file)), "/"), @@ -180,7 +169,7 @@ write_feed_xml <- function(feed_xml, site_config, collection, articles) { "xmlns:dc" = "http://purl.org/dc/elements/1.1/" ) - if (identical(site_config$rss$full_content, TRUE)) + if (!identical(site_config$rss$full_content, FALSE)) namespaces <- c(namespaces, list("xmlns:distill" = "https://distill.pub/journal/")) # create document root @@ -240,7 +229,7 @@ write_feed_xml <- function(feed_xml, site_config, collection, articles) { add_child(item, "link", text = article$base_url) full_content_path <- NULL - if (identical(site_config$rss$full_content, TRUE) && is.character(article$input_file)) { + if (!identical(site_config$rss$full_content, FALSE) && is.character(article$input_file)) { guess_rmd <- paste0(gsub("\\.utf.*\\.md|\\.md", "", article$input_file), ".Rmd") full_content_path <- dir(getwd(), pattern = guess_rmd, full.names = TRUE, recursive = TRUE) } diff --git a/distill-r.Rproj b/distill-r.Rproj index e48c6589..270314b8 100644 --- a/distill-r.Rproj +++ b/distill-r.Rproj @@ -19,5 +19,3 @@ BuildType: Package PackageUseDevtools: Yes PackageInstallArgs: --no-multiarch --with-keep.source PackageRoxygenize: rd,collate,namespace - -MarkdownCanonical: Yes From 12e2b423b58c6926dae51707f102f6a6008ba1b2 Mon Sep 17 00:00:00 2001 From: Javier Luraschi Date: Fri, 25 Sep 2020 09:45:16 -0700 Subject: [PATCH 3/3] revert rproj change --- distill-r.Rproj | 2 ++ 1 file changed, 2 insertions(+) diff --git a/distill-r.Rproj b/distill-r.Rproj index 270314b8..e48c6589 100644 --- a/distill-r.Rproj +++ b/distill-r.Rproj @@ -19,3 +19,5 @@ BuildType: Package PackageUseDevtools: Yes PackageInstallArgs: --no-multiarch --with-keep.source PackageRoxygenize: rd,collate,namespace + +MarkdownCanonical: Yes