Fix calendar activity heatmap in preview and generation
This commit is contained in:
@@ -592,16 +592,16 @@ fn serve_scoped_file(
|
||||
let Some(relative) = path.strip_prefix(prefix) else {
|
||||
return Ok(None);
|
||||
};
|
||||
let bundled_path = format!("{scope_dir}/{relative}");
|
||||
if let Some(bytes) = crate::engine::site_assets::bundled_site_asset(&bundled_path) {
|
||||
let mime = guess_content_type(Path::new(&bundled_path));
|
||||
return Ok(Some(
|
||||
(StatusCode::OK, [(header::CONTENT_TYPE, mime)], bytes).into_response(),
|
||||
));
|
||||
}
|
||||
let scope_root = data_dir.join(scope_dir);
|
||||
let candidate = scope_root.join(relative);
|
||||
if !candidate.exists() || !candidate.is_file() {
|
||||
let bundled_path = format!("{scope_dir}/{relative}");
|
||||
if let Some(bytes) = crate::engine::site_assets::bundled_site_asset(&bundled_path) {
|
||||
let mime = guess_content_type(Path::new(&bundled_path));
|
||||
return Ok(Some(
|
||||
(StatusCode::OK, [(header::CONTENT_TYPE, mime)], bytes).into_response(),
|
||||
));
|
||||
}
|
||||
return Ok(Some(error_response(
|
||||
StatusCode::NOT_FOUND,
|
||||
"preview asset not found",
|
||||
@@ -1167,6 +1167,11 @@ mod tests {
|
||||
std::fs::create_dir_all(dir.path().join("html/pagefind")).unwrap();
|
||||
std::fs::write(dir.path().join("media/ok.txt"), "ok").unwrap();
|
||||
std::fs::write(dir.path().join("assets/site.css"), "body { color: red; }").unwrap();
|
||||
std::fs::write(
|
||||
dir.path().join("assets/calendar-runtime.js"),
|
||||
"window.staleCalendarRuntime = true;",
|
||||
)
|
||||
.unwrap();
|
||||
std::fs::write(dir.path().join("images/custom.svg"), "<svg></svg>").unwrap();
|
||||
std::fs::write(
|
||||
dir.path().join("html/pagefind/pagefind-ui.js"),
|
||||
@@ -1194,6 +1199,14 @@ mod tests {
|
||||
.unwrap();
|
||||
let media_body = media.text().unwrap();
|
||||
let asset_body = asset.text().unwrap();
|
||||
let calendar_runtime_body = client
|
||||
.get(format!(
|
||||
"http://{PREVIEW_HOST}:{PREVIEW_PORT}/assets/calendar-runtime.js"
|
||||
))
|
||||
.send()
|
||||
.unwrap()
|
||||
.text()
|
||||
.unwrap();
|
||||
let image_body = client
|
||||
.get(format!(
|
||||
"http://{PREVIEW_HOST}:{PREVIEW_PORT}/images/custom.svg"
|
||||
@@ -1214,6 +1227,8 @@ mod tests {
|
||||
|
||||
assert_eq!(media_body, "ok");
|
||||
assert!(asset_body.contains("color: red"));
|
||||
assert!(calendar_runtime_body.contains("--blog-calendar-heat-strength"));
|
||||
assert!(!calendar_runtime_body.contains("staleCalendarRuntime"));
|
||||
assert!(image_body.contains("<svg>"));
|
||||
assert!(pagefind_body.contains("window.pagefind"));
|
||||
}
|
||||
|
||||
@@ -278,3 +278,30 @@ pub(crate) fn write_bundled_site_assets(
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::bundled_site_asset;
|
||||
|
||||
fn bundled_text(path: &str) -> &'static str {
|
||||
std::str::from_utf8(bundled_site_asset(path).unwrap()).unwrap()
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn calendar_heatmap_marks_only_populated_periods_with_one_accent() {
|
||||
let runtime = bundled_text("assets/calendar-runtime.js");
|
||||
let styles = bundled_text("assets/bds.css");
|
||||
|
||||
assert!(runtime.contains("--blog-calendar-heat-strength"));
|
||||
assert!(!runtime.contains("--blog-calendar-heat-hue"));
|
||||
assert!(styles.contains(
|
||||
"[data-vc-date]:not([data-blog-calendar-has-posts='true']) [data-vc-date-btn]"
|
||||
));
|
||||
assert!(styles.contains("background-color: transparent !important;"));
|
||||
assert!(styles.contains("border-color: transparent !important;"));
|
||||
assert!(styles.contains("color-mix(in srgb, var(--pico-primary"));
|
||||
assert!(styles.contains("var(--blog-calendar-heat-strength"));
|
||||
assert!(styles.contains("transparent) !important;"));
|
||||
assert!(!styles.contains("hsl(var(--blog-calendar-heat-hue"));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user