Ray's Knowledge Base
Unlock

rs-web's rs.assets.write_hashed writes relative to the project root and takes text content, so hash a generated binary file with rs.hash.file, rename and register

FactVerified 1 Oct 2026Holds anywhere
Fact. A statement and the evidence for it.

Statement#

  • rs.assets.write_hashed(content, path) hashes the content bytes you pass in Lua and writes relative to the project root, not dist/.
  • The read APIs rs.fs.read and rs.async.read_file are text-only, so Lua cannot feed the bytes of an image to write_hashed without raw io.
  • To give a generated binary file (such as an image variant in dist/) a content-hashed name: hash its bytes with rs.hash.file, rename it with rs.async.rename, and record the stable-to-hashed mapping with rs.assets.register.
  • A template resolves the mapping with the asset Tera filter, such as {{ "/static/avatar-400.avif" | asset }}. Lua code resolves it with rs.assets.get_path.
  • The build order is the before_build hook, then pages(), then rendering. A mapping registered in before_build is thus visible to pages() and to the asset filter.
  • A source change that does not change the decoded pixels (such as a byte in the EXIF segment of a JPEG) leaves the variants byte-identical, so their hashes do not change.

Evidence#

2026-10-01, website repository, commit 9b63fc5: an agent read the rs-web source and reported the write_hashed and read-API limits. The build with rs.hash.file, rs.async.rename and rs.assets.register in before_build produced dist/static/avatar-400.9c2012864fa187c2.avif, and dist/index.html referenced only hashed names through the asset filter. A one-byte change inside the main image data changed the variant hashes; a byte in the EXIF segment changed only the hash of the full-size JPEG.