Skip to content
lsdocs-protocol API

lsdocs_config #

Project configuration (lsdocs.toml) and plugin manifest types.

ConfigFile mirrors lsdocs.toml as written. Config::from_toml parses and validates it into a Config, reporting every problem at once. Overrides then layer environment variables and CLI flags on top:

let mut config = Config::from_toml("[site]\ntitle = \"Docs\"\n").unwrap();
config.apply(Overrides::from_env([("LSDOCS_OUTPUT_DIR", "public")]));
config.apply(Overrides { base_url: Some("/docs/".into()), ..Overrides::default() });
assert_eq!(config.output_dir, "public");

This crate does no I/O; the caller reads the file and passes the environment in.

type alias Value #

pub type Value = Value;

An arbitrary structured value.

constant DEFAULT_SOURCE_DIR #

pub const DEFAULT_SOURCE_DIR: &str = "docs";

Default for Config::source_dir.

constant DEFAULT_OUTPUT_DIR #

pub const DEFAULT_OUTPUT_DIR: &str = "site";

Default for Config::output_dir.

struct ConfigFile #

pub struct ConfigFile

The contents of lsdocs.toml, as written. Unknown keys are rejected so typos are caught.

Trait implementations

field site #

pub site: SiteSection

The [site] settings: what the website is (title, base URL).

field build #

pub build: BuildSection

Build settings.

field plugins #

pub plugins: Vec<PluginEntry>

Plugins, in pipeline order within each phase.

struct SiteSection #

pub struct SiteSection

The [site] table.

Trait implementations

field title #

pub title: Option<String>

Site title.

field base_url #

pub base_url: Option<String>

URL or path prefix the site is served from, e.g. "/docs/".

field theme #

pub theme: Option<Value>

No longer supported, and an error: the theme is chosen in the HTML renderer's settings (theme in render-html's .config/lsdocs/<name>/settings.toml). Kept so the error can say so.

struct BuildSection #

pub struct BuildSection

The [build] table.

Trait implementations

field source_dir #

pub source_dir: Option<String>

Directory holding source documents. Defaults to "docs".

field output_dir #

pub output_dir: Option<String>

Directory the output is written to. Defaults to "site".

struct PluginEntry #

pub struct PluginEntry

One [[plugins]] entry. Exactly one of builtin, command or runtime says how to run the plugin.

Trait implementations

field name #

pub name: String

Unique name used in logs and diagnostics.

field builtin #

pub builtin: Option<String>

Name of a first-party plugin to run in-process, e.g. "parser-myst".

field command #

pub command: Option<Vec<String>>

Program and arguments to launch.

field runtime #

pub runtime: Option<Runtime>

Runtime to launch a script plugin with; needs module (Python) or entry (Node).

field module #

pub module: Option<String>

Python module to run with python -m.

field entry #

pub entry: Option<String>

Node.js entry script.

field transport #

pub transport: Option<Transport>

How to talk to an out-of-process plugin. Defaults to "stdio".

field files #

pub files: Option<Vec<String>>

Glob patterns limiting which source files this plugin handles.

field options #

pub options: Option<Value>

No longer supported, and an error: a plugin's settings are its own files under .config/, next to lsdocs.toml. Kept so the error can say so.

enum Runtime #

pub enum Runtime

Runtime for script plugins.

Trait implementations

variant Python #

Python

Run with python -m <module>.

variant Node #

Node

Run with node <entry>.

enum Transport #

pub enum Transport

Transport for out-of-process plugins.

Trait implementations

variant Stdio #

Stdio

The plugin's stdin and stdout.

variant Pipe #

Pipe

A named pipe (Windows) or unix socket whose path is passed to the plugin in the LSDOCS_PIPE environment variable.

struct Config #

pub struct Config

Validated project configuration.

Trait implementations

field title #

pub title: Option<String>

Site title.

field base_url #

pub base_url: Option<String>

URL or path prefix the site is served from.

field source_dir #

pub source_dir: String

Directory holding source documents, relative to the config file.

field output_dir #

pub output_dir: String

Directory the output is written to, relative to the config file.

field plugins #

pub plugins: Vec<Plugin>

Plugins, in the order they were declared.

function from_toml #

pub fn from_toml(source: &str) -> Result<Self, ConfigError>

Parses and validates the contents of lsdocs.toml.

function from_file #

pub fn from_file(file: ConfigFile) -> Result<Self, ConfigError>

Validates an already-parsed config file.

method apply #

pub fn apply(&mut self, overrides: Overrides)

Applies overrides on top of this configuration. Call once per layer, lowest priority first (environment, then CLI).

struct Plugin #

pub struct Plugin

A validated plugin entry.

Trait implementations

field name #

pub name: String

Unique name.

field launch #

pub launch: Launch

How the plugin is run.

field files #

pub files: Vec<String>

Glob patterns limiting which source files this plugin handles; empty means no limit beyond the plugin's own capabilities.

enum Launch #

pub enum Launch

How a plugin is run.

Trait implementations

variant Builtin #

Builtin { name: String }

A first-party plugin linked into the host and run in-process.

field name #

name: String

First-party plugin name.

variant External #

External { command: Command, transport: Transport }

A separate process.

field command #

command: Command

What to launch.

field transport #

transport: Transport

How to talk to it.

enum Command #

pub enum Command

What to launch for an out-of-process plugin.

Trait implementations

variant Program #

Program { program: String, args: Vec<String> }

A program and its arguments.

field program #

program: String

Program name or path.

field args #

args: Vec<String>

Arguments.

variant Python #

Python { module: String }

python -m <module>.

field module #

module: String

Module name.

variant Node #

Node { entry: String }

node <entry>.

field entry #

entry: String

Entry script path.

struct Overrides #

pub struct Overrides

Settings that can be overridden by environment variables or CLI flags.

Trait implementations

field source_dir #

pub source_dir: Option<String>

Overrides Config::source_dir (LSDOCS_SOURCE_DIR).

field output_dir #

pub output_dir: Option<String>

Overrides Config::output_dir (LSDOCS_OUTPUT_DIR).

field base_url #

pub base_url: Option<String>

Overrides Config::base_url (LSDOCS_BASE_URL).

function from_env #

pub fn from_env<K, V>(vars: impl IntoIterator<Item = (K, V)>) -> Self
where
    K: AsRef<str>,
    V: Into<String>,

Reads overrides from LSDOCS_* variables. Pass std::env::vars().

enum ConfigError #

pub enum ConfigError

Why a configuration could not be loaded.

Trait implementations

variant Syntax #

Syntax(String)

The file is not valid TOML, or does not match the expected shape (including unknown keys). Holds the parser's message.

variant Invalid #

Invalid(Vec<Problem>)

The file parsed but has one or more invalid settings.

struct Problem #

pub struct Problem

One invalid setting.

Trait implementations

field at #

pub at: String

Where the problem is, e.g. plugins[2].

field message #

pub message: String

What is wrong.