On this page:
get-doc
get-meta
meta-ref
read-source-metas

5.3 Fetch🔗ℹ

 (require punct/fetch) package: punct-lib

procedure

(get-doc src) → document?

  src : path-string?
Returns the doc binding from src. No caching is used; this function is basically a thin wrapper around dynamic-require. If src does not exist, you will get a friendly error message. If any other kind of problem arises, you will get an ugly error.

procedure

(get-meta doc key [default]) → any/c

  doc : document?
  key : symbol?
  default : failure-result/c
   = (lambda () (raise (make-exn:fail ....)))
Returns the value of key in the document-metas of doc. The value of default is used if the key does not exist: if it is a value, that value will be returned instead; if it is a thunk, the thunk will be called.

Changed in version 1.1 of package punct-lib: Removed get-doc-ref and replaced with get-meta

procedure

(meta-ref doc key) → any/c

  doc : document?
  key : symbol?
Equivalent to (get-meta doc key #f). Provided for compatibility.

procedure

(read-source-metas src) → (or/c (and/c hash-eq? immutable?) #f)

  src : path-string?
Reads only the Metadata block of src and returns its keys and values. Nothing in src is compiled, required or evaluated, so this works for sources that would fail to compile, and it is much faster than get-doc for gathering metadata from many sources.

Returns #f if the first line of src is not a #lang punct line. Returns an empty hash table if src is a Punct source with no metadata block.

The result differs from the document-metas of the compiled document in these ways:

If a key appears more than once in the block, the first value is used, as in the compiled document.

This function never raises an error because of a malformed metadata block, even where compiling src would fail. Instead:

  • A line with no :, or with nothing after the :, is skipped.

  • A line whose quoted value cannot be read with read (for example, an unclosed list) is skipped.

  • If the block has no closing line of hyphens, every line to the end of the file is treated as part of the block, so lines in the body that look like key: value will appear in the result.

  • If anything other than whitespace comes between the #lang line and the opening line of hyphens, there is no metadata block, and the result is an empty hash table.

Added in version 1.6 of package punct-lib.