sigildocs

(sigil resources)

(sigil resources) - Unified resource resolution for Sigil

Provides access to library, documentation, and asset files with automatic resolution across project builds, bundled archives, and filesystem.

Resolution order:

  1. Project build output (if package.sgl found in cwd or parents)
  2. Bundled archive (if running from a bundled executable)
  3. Executable-relative (assets/ folder next to binary, for 'assets only)
  4. Filesystem (library-paths for 'lib only)

Resource categories determine the base path:

  • 'lib -> project: build/dev/lib/ | bundle: lib/ | system: library-paths
  • 'docs -> project: docs/ | bundle: docs/
  • 'assets -> project: assets/ | bundle: assets/ | exe-relative: assets/

Example:

(import (sigil resources))

;; Read module JSON docs
(read-resource 'lib "sigil/string.json")

;; Read language reference markdown
(read-resource 'docs "reference/language/syntax.md")

;; Read an asset file
(read-resource-bytes 'assets "images/logo.png")

Exports

Clear the resource resolution cache.

Resets the cached project root so the next resource lookup re-scans the filesystem. Call this after changing the working directory or modifying the project layout.

(clear-resource-cache)
project-rootprocedure

Get the project root directory, or #f if not in a project.

A project is detected by finding package.sgl in the current directory or any parent directory. The result is cached; call clear-resource-cache to reset.

(project-root)  ; => "/home/user/my-project" or #f
in-project?procedure

Check if currently running within a Sigil project.

Returns #t if package.sgl is found in the current directory or any parent directory.

(in-project?)  ; => #t

Get the current resource resolution context.

Returns a symbol indicating where resources are resolved from:

  • project — loaded from a project build directory
  • bundle — loaded from a bundled executable archive
  • system — loaded from filesystem library paths
(resource-context)  ; => project

Check if a resource exists.

Category is one of: 'lib, 'docs, 'assets. Path is relative within that category (e.g., "sigil/string.json").

(resource-exists? 'lib "sigil/string.json")  ; => #t
read-resourceprocedure

Read a resource as a string.

Returns the file contents as a string, or #f if not found. Category is one of: 'lib, 'docs, 'assets.

(read-resource 'docs "reference/language/syntax.md")
; => "# Syntax\n..."

Read a resource as a bytevector.

Returns the file contents as a bytevector, or #f if not found. Useful for binary assets like images.

(read-resource-bytes 'assets "images/logo.png")
; => #u8(137 80 78 71 ...)