Pre-computed record keys for my blog posts 0 ▲ Panagiotis Vryonis 109 days ago · Tech · hide · Fediverse post For every one of my blog posts, my static site generator1 pre-computes an atproto TID defined by the post date time and its slug: const TID_ALPHA: &[u8; 32] = b"234567abcdefghijklmnopqrstuvwxyz"; fn atproto_tid(date_rfc3339: &str, slug: &str) -> Result<String, minijinja::Error> { let dt = OffsetDateTime::parse(date_rfc3339, &Rfc3339).map_err(|err| { minijinja::Error::new( ErrorKind::InvalidOperation, format!( "atproto_tid(): first argument must be an RFC3339 date (e.g. post.date_iso); got '{date_rfc3339}': {err}" ), ) })?; let micros = (dt.unix_timestamp_nanos() / 1_000) as u64 & 0x1F_FFFF_FFFF_FFFF; let digest = blake3::hash(slug.as_bytes()); let clock = u16::from_be_bytes([digest.as_bytes()[0], digest.as_bytes()[1]]) as u64 & 0x3FF; let mut v = ((micros << 10) | clock) & 0x7FFF_FFFF_FFFF_FFFF; let mut out = [0u8; 13]; for slot in out.iter_mut().rev() { *slot = TID_ALPHA[(v & 0x1F) as usize]; v >>= 5; } // Every byte comes from TID_ALPHA (ASCII), so no UTF-8 validation needed.… Commenting on Bubbles has been removed. Why? If you want to talk about this post, write to the author, use the comments on their blog if it has them, or reply with a "RE:" post on your own blog. Suggestions? feedback@bubbles.town