From 9b80cd7f76890e172166c55e41a652ac2a37e10e Mon Sep 17 00:00:00 2001 From: Esther-MacMini Date: Sat, 5 Dec 2026 02:47:16 -0500 Subject: [PATCH] Preserve the public report canonical URL in the final HTML --- tutorials/point-in-time/build-clock-report.R | 14 ++++++++++++-- tutorials/point-in-time/clock-report.Rmd | 4 ++-- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/tutorials/point-in-time/build-clock-report.R b/tutorials/point-in-time/build-clock-report.R index d9c0327..18b8d18 100644 --- a/tutorials/point-in-time/build-clock-report.R +++ b/tutorials/point-in-time/build-clock-report.R @@ -26,7 +26,18 @@ build_report <- function(destination) { length(xml2::xml_find_all(html, "//table/tbody/tr")) == row_count) } render("clock-report.Rmd", destination) - check_render(file.path(destination, "index.html"), "7 seconds of the 12-second window", nrow(csv)) + # Add the public address after Pandoc makes the HTML self-contained. A reader's + # locally rendered report can use a different window and needs no canonical URL. + url <- "https://jacobiusmakes.github.io/parlayapiR/clock-report/" + published <- file.path(destination, "index.html") + lines <- readLines(published, warn = FALSE, encoding = "UTF-8") + close_head <- which(trimws(lines) == "") + stopifnot(length(close_head) == 1L) + canonical <- sprintf('', url) + writeLines(append(lines, canonical, after = close_head - 1L), published, useBytes = TRUE) + links <- xml2::xml_find_all(xml2::read_html(published), "//head/link[@rel='canonical']") + stopifnot(identical(xml2::xml_attr(links, "href"), url)) + check_render(published, "7 seconds of the 12-second window", nrow(csv)) stage <- tempfile() dir.create(stage) on.exit(unlink(stage, recursive = TRUE), add = TRUE) @@ -49,7 +60,6 @@ build_report <- function(destination) { sitemap <- file.path(dirname(destination), "sitemap.xml") xml <- xml2::read_xml(sitemap) - url <- "https://jacobiusmakes.github.io/parlayapiR/clock-report/" locate <- function(x) xml2::xml_text(xml2::xml_find_all(x, "//*[local-name()='loc']")) before <- locate(xml) if (!url %in% before) { diff --git a/tutorials/point-in-time/clock-report.Rmd b/tutorials/point-in-time/clock-report.Rmd index 789068a..ea0dee1 100644 --- a/tutorials/point-in-time/clock-report.Rmd +++ b/tutorials/point-in-time/clock-report.Rmd @@ -7,8 +7,6 @@ output: highlight: null mathjax: null self_contained: true -header-includes: - - '' params: start_second: 0 end_second: 12 @@ -72,6 +70,8 @@ Look at seconds 8–9 in the full log. The source withdrew the quote at second 8 ## Reproduce the report +[Download the ten intervals as CSV](https://jacobiusmakes.github.io/parlayapiR/clock-report/decision-clock-intervals.csv) to inspect both prices and their UTC boundaries in a spreadsheet. + [Download the R Markdown project and the full twelve-second CSV](https://jacobiusmakes.github.io/parlayapiR/clock-report/project.zip). Extract the ZIP and open a terminal in that directory. Run `Rscript replay.R` with base R to see both clocks at eight selected decision times. Three of those eight decisions differ. The elapsed-time table counts how long each difference lasted. To change the report window, run the following in R with **rmarkdown**, **knitr** and **Pandoc** installed. It renders a local HTML file. In the window from second 8 up to second 9, the two histories disagree for the entire second.