## Documentation index

This index lists every available documentation page and its Markdown source.

- [Documentation](https://veta.varavel.com/docs/index.md)
  - [Getting Started](https://veta.varavel.com/docs/getting-started/index.md)
  - [Installation](https://veta.varavel.com/docs/installation/index.md)
  - [Guides](https://veta.varavel.com/docs/guides/index.md)
    - [Project Structure](https://veta.varavel.com/docs/guides/project-structure/index.md)
    - [Configuration](https://veta.varavel.com/docs/guides/configuration/index.md)
    - [Pages](https://veta.varavel.com/docs/guides/pages/index.md)
    - [Data](https://veta.varavel.com/docs/guides/data/index.md)
    - [Markdown](https://veta.varavel.com/docs/guides/markdown/index.md)
    - [Templates](https://veta.varavel.com/docs/guides/templates/index.md)
    - [Components](https://veta.varavel.com/docs/guides/components/index.md)
    - [Filters](https://veta.varavel.com/docs/guides/filters/index.md)
    - [Assets And Tailwind CSS](https://veta.varavel.com/docs/guides/assets-and-tailwind/index.md)
    - [Themes](https://veta.varavel.com/docs/guides/themes/index.md)
    - [Development Server](https://veta.varavel.com/docs/guides/development-server/index.md)
    - [Build And Output](https://veta.varavel.com/docs/guides/build-and-output/index.md)
    - [Deployment](https://veta.varavel.com/docs/guides/deployment/index.md)
  - [Reference](https://veta.varavel.com/docs/reference/index.md)
    - [CLI Reference](https://veta.varavel.com/docs/reference/cli/index.md)
    - [Config Reference](https://veta.varavel.com/docs/reference/config/index.md)
    - [Page Generators Reference](https://veta.varavel.com/docs/reference/page-generators/index.md)
    - [Template Context Reference](https://veta.varavel.com/docs/reference/template-context/index.md)
    - [Troubleshooting](https://veta.varavel.com/docs/reference/troubleshooting/index.md)
  - [API](https://veta.varavel.com/docs/api/index.md)
    - [JavaScript API](https://veta.varavel.com/docs/api/javascript/index.md)
    - [File API](https://veta.varavel.com/docs/api/files/index.md)
    - [HTTP Client](https://veta.varavel.com/docs/api/http-client/index.md)
    - [Parse API](https://veta.varavel.com/docs/api/parse/index.md)
    - [Template Functions](https://veta.varavel.com/docs/api/template-functions/index.md)
    - [Environment And Console](https://veta.varavel.com/docs/api/environment-and-console/index.md)
    - [Markdown Frontmatter](https://veta.varavel.com/docs/api/frontmatter/index.md)


## Documentation content

The documentation for the current page follows, reproduced verbatim.


# JavaScript API

Veta uses JavaScript for three kinds of project files:

```txt
data/*.js       -> global data producers
pages/*.js      -> page generators
filters/*.js    -> template filters
functions/*.js  -> template functions
```

JavaScript files are self-contained and synchronous. They do not use imports, module loading, or asynchronous promises. Each file must export one default function.

## Runtime Context

The default export receives a context object as its first argument.

Common context keys:

```txt
files
httpClient
parse
env
```

Additional context keys depend on where the file runs.

## `data/*.js`

Data files run while global data is being loaded, so they do not receive `data`.

```js
export default function({ env, files, httpClient }) {
  return {
    mode: env.VETA_MODE || "production",
  };
}
```

Return any JSON-compatible value. The value becomes part of `data` using the file path as its key.

Example:

```txt
data/github.js -> data.github
```

## `pages/*.js`

Page generators receive loaded global data:

```js
export default function({ data, parse }) {
  const { html } = parse.markdown("# Home");

  return [
    {
      permalink: "/",
      template: "base",
      title: data.site.name,
      content: html,
    },
  ];
}
```

Return an array of page objects. Templated content is passed unchanged and trusted to its template, while template-less content is written unchanged as raw output. Use `parse.markdown(text)` and `parse.renderComponents(text)` explicitly when a generator needs those transformations.

## `filters/*.js`

Filters receive the runtime context, the input value, and one optional parameter:

```js
export default function({ data }, input, parameter) {
  const prefix = parameter || data.site.name;
  return `${prefix}: ${input}`;
}
```

## `functions/*.js`

Template functions receive the runtime context followed by explicit template arguments:

```js
export default function({ page, data, files, parse }, value, length) {
  return String(value || page.title).slice(0, Number(length));
}
```

Use the file stem as a function in Pongo templates and components:

```html
{{ excerpt(page.content, 120) }}
```

Use it in a template:

```html
{{ page.title|prefix:"Post" }}
```

## No Global `Veta`

Veta does not expose runtime APIs through a global `Veta` object. Always use the context argument:

```js
export default function({ files }) {
  return files.listFiles("content/**/*.md");
}
```

## Console

The `console` object is available as a JavaScript global:

```js
export default function() {
  console.log("Generating pages");
  return [];
}
```

Supported methods are `debug`, `error`, `info`, `log`, and `warn`.

## Execution Model

Veta executes JavaScript synchronously. Promise-like return values are rejected.

Use synchronous calls only:

```js
export default function({ httpClient, parse }) {
  const response = httpClient.get("https://example.com/data.json");
  return parse.json(response.body);
}
```

Do not return a Promise:

```js
export default async function() {
  return [];
}
```

## API Pages

- [File API](/docs/api/files/)
- [HTTP Client](/docs/api/http-client/)
- [Parse API](/docs/api/parse/)
- [Environment And Console](/docs/api/environment-and-console/)
- [Frontmatter](/docs/api/frontmatter/)
