aboutsummaryrefslogtreecommitdiff
path: root/src/notion.rs
diff options
context:
space:
mode:
authorFuwn <[email protected]>2026-02-18 05:35:53 -0800
committerFuwn <[email protected]>2026-02-18 05:35:53 -0800
commitf6b7e526352eaa2d7a83423097a4a0927b7b4824 (patch)
tree7ef2a1025ae6b178b80dc5c99c8e5ef7a24d0b2a /src/notion.rs
parentrefactor(modules): Remove skills route (diff)
downloadlocus-f6b7e526352eaa2d7a83423097a4a0927b7b4824.tar.xz
locus-f6b7e526352eaa2d7a83423097a4a0927b7b4824.zip
feat(blog): Add canonical and alias slug routing from Notion Slugs with title fallback
Diffstat (limited to 'src/notion.rs')
-rw-r--r--src/notion.rs28
1 files changed, 26 insertions, 2 deletions
diff --git a/src/notion.rs b/src/notion.rs
index 006466f..4dd7c5e 100644
--- a/src/notion.rs
+++ b/src/notion.rs
@@ -60,11 +60,35 @@ pub fn extract_number(
properties: &serde_json::Value,
field: &str,
) -> Option<u8> {
- properties[field]["number"]
- .as_u64()
+ extract_non_negative_whole_number(properties, field)
.and_then(|number_value| u8::try_from(number_value).ok())
}
+fn extract_non_negative_whole_number(
+ properties: &serde_json::Value,
+ field: &str,
+) -> Option<u64> {
+ let number_value = &properties[field]["number"];
+
+ number_value.as_u64().or_else(|| {
+ number_value.as_f64().and_then(|floating_value| {
+ if !floating_value.is_finite() || floating_value < 0.0 {
+ return None;
+ }
+
+ let rounded_value = floating_value.round();
+ let is_whole_number =
+ (floating_value - rounded_value).abs() <= f64::EPSILON;
+
+ if !is_whole_number {
+ return None;
+ }
+
+ format!("{rounded_value:.0}").parse::<u64>().ok()
+ })
+ })
+}
+
pub fn extract_date(properties: &serde_json::Value, field: &str) -> String {
properties[field]["date"]["start"].as_str().unwrap_or("").to_string()
}