On this page:
9.7.1 Collecting and Building
collect
collect/  call-with-page
build!
site-info
current-site-info
page
9.7.2 Development Server
start-server
9.7.3 Logging
camp-logger
log-camp-fatal
log-camp-error
log-camp-warning
log-camp-info
log-camp-debug
9.3

9.7 Low-Level API🔗ℹ

    9.7.1 Collecting and Building

    9.7.2 Development Server

    9.7.3 Logging

9.7.1 Collecting and Building🔗ℹ

 (require camp/build) package: camp-lib

The camp/build module provides the two-pass build system for Camp sites.

procedure

(collect site) → site-info?

  site : site?
Performs the collect pass over a site. Traverses all documents in each collection, building indexes for cross-reference resolution: a page index mapping slugs to URLs, a term index mapping term names to URL fragments, and taxonomy indexes for each collection.

Source documents are loaded in a way that picks up changes between calls within the same process: if a source file (or a module it depends on) has been modified since a previous collect, the new version is used. This is what makes rebuilds in the GUI app and raco camp serve reflect edits without restarting.

Changed in version 1.1 of package camp-lib: Parses the date and updated metas of every page (see page-link). A value that cannot be parsed, or an updated earlier than the date, raises an exception here, for pages in and out of feeds.

procedure

(collect/call-with-page site slug proc) → any

  site : site?
  slug : string?
  proc : (-> document? context? any)
Collects the site, looks up the page matching slug, and calls proc with the page’s document and render context. The current-site-info parameter is set for the duration of proc, so cross-reference functions like get-collection and get-taxonomy-pages work normally.

This is useful for rendering or processing a single page with full site context without performing a complete build!. The slug is matched case-insensitively. Raises an error if no page with the given slug exists.

(collect/call-with-page my-site "my-post" my-render-function)

procedure

(build! site info) → (hash/c string? string?)

  site : site?
  info : site-info?
Performs the build pass. For each page, calls its collection’s render function with the document and context. Render functions call camp-doc->html-xexpr to render the body (which resolves cross-references). Writes the returned x-expression to the output folder as HTML, then copies the static files.

Returns a table of the static files that were fingerprinted by static-url during the build. Keys and values are paths relative to the static and output folders respectively, with "/" as the separator: for example, "css/style.css" maps to "css/style-a4a3b627.css".

Changed in version 1.1 of package camp-lib: Copies static files after rendering, not before, and returns the table of fingerprinted files instead of #<void>. A static file now replaces a page that has the same output path; before, the page replaced the static file.

struct

(struct site-info (pages term-index page-index taxonomy-index)
    #:extra-constructor-name make-site-info
    #:transparent)
  pages : (listof page?)
  term-index : hash?
  page-index : hash?
  taxonomy-index : hash?
Collected information about a site, built during the collect pass. Contains all processed pages, an index mapping term names to URLs, an index mapping slugs to page-links, and a nested index for taxonomy lookups.

parameter

(current-site-info) → (or/c site-info? #f)

(current-site-info info) → void?
  info : (or/c site-info? #f)
A parameter containing the current site-info during the build phase. Set by build! before rendering pages. Used internally by get-collection, get-taxonomy-terms, and get-taxonomy-pages. Returns #f outside of a build context.

struct

(struct page (source-path output-path doc slug collection-name)
    #:extra-constructor-name make-page
    #:transparent)
  source-path : path?
  output-path : path?
  doc : any/c
  slug : string?
  collection-name : string?
Represents a page during the build process. Contains the source file path, computed output path, the Punct document, URL slug, and the name of the collection it belongs to.

9.7.2 Development Server🔗ℹ

 (require camp/serve) package: camp-lib

The camp/serve module provides a development server for local testing.

procedure

(start-server output-folder    
  [#:port port    
  #:log-format log-format]) → (-> void?)
  output-folder : path-string?
  port : exact-nonnegative-integer? = 8000
  log-format : (or/c 'modern 'apache) = 'modern
Starts a static file server serving files from output-folder. Returns a shutdown procedure that stops the server when called. By default, listens on port 8000.

The log-format parameter controls request logging: 'modern produces a clean HH:MM:SS METHOD PATH STATUS format suitable for colorized terminal output, while 'apache produces traditional Apache combined log format.

Note: This function only starts a static server. File watching and automatic rebuilds are provided by the raco camp serve command, which uses this function internally.

9.7.3 Logging🔗ℹ

 (require camp/log) package: camp-lib

The camp/log module provides structured logging for Camp operations.

The Camp logger instance, using the topic 'camp. Subscribe to this logger to receive Camp-related log messages.

syntax

(log-camp-fatal string-expr arg ...)

syntax

(log-camp-error string-expr arg ...)

syntax

(log-camp-warning string-expr arg ...)

syntax

(log-camp-info string-expr arg ...)

syntax

(log-camp-debug string-expr arg ...)

Log messages of varying severity levels to the Camp logger.