## 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.


# Template Functions

Veta registers template functions for Pongo templates and components.

Built-in functions are always available:

- `url`
- `regex_replace`
- `load_data`

Custom functions live in `functions/*.js` and use the file stem as the template function name.

## `url`

`url` returns a portable URL for an internal root-relative path from the current page.

```html
<link rel="stylesheet" href="{{ url("/styles.css") }}">
<img src="{{ url("/images/logo.svg") }}" alt="Logo">
<a href="{{ url(page.permalink) }}">Current page</a>
```

From `/docs/intro/`, `url("/styles.css")` returns `../../styles.css`. From `/`, it returns `styles.css`.

External URLs, fragment-only URLs, and already-relative URLs are returned unchanged.

## `regex_replace`

`regex_replace` replaces text with a Go regular expression:

```html
{{ regex_replace("World Hello", "(\\w+) (\\w+)", "$2 $1") }}
```

The result can be rendered directly or assigned with `set`:

```html
{% set slug = regex_replace(page.title, "[^a-zA-Z0-9]+", "-") %}
<h1 id="{{ slug }}">{{ page.title }}</h1>
```

Invalid regular expressions fail the build.

## `load_data`

`load_data` reads a local project file or a remote URL as text from a template, include, or component.

Use `load_data` inside native Pongo expressions. Assign values with Pongo's built-in `set` tag:

```html
{% set navigation = load_data("data/navigation.yaml")|parse_yaml %}
{% for item in navigation.items %}
  <a href="{{ item.href }}">{{ item.label }}</a>
{% endfor %}
```

Without a parse filter, `load_data` returns a string:

```html
{% set readme = load_data("content/readme.md") %}
{{ readme|markdown }}
```

### Local Files

Local paths are project-relative and can read files from the composed project and theme filesystem:

```html
{% set badge = load_data("data/badge.toml")|parse_toml %}
{{ badge.label }}
```

Local paths must be relative. Absolute paths, Windows drive paths, empty paths, and paths containing `..` are rejected.

### Remote URLs

Remote URLs use HTTP `GET`:

```html
{% set repo = load_data("https://api.github.com/repos/varavelio/veta")|parse_json %}
{{ repo.stargazers_count }}
```

Only `http` and `https` URLs are allowed. Non-2xx responses fail the build.

### Parse Filters

Use parse filters to convert loaded text into structured values:

- `parse_json`
- `parse_yaml`
- `parse_toml`
- `parse_markdown`

```html
{% set message = load_data("content/message.txt") %}
{% set site = load_data("data/site.json")|parse_json %}
{% set navigation = load_data("data/navigation.yaml")|parse_yaml %}
{% set theme = load_data("data/theme.toml")|parse_toml %}
```

Parsed values return normal template values:

```html
{{ site.title }} {{ navigation.items.0.label }} {{ theme.colors.primary }}
```

## Custom Functions

Custom functions are synchronous JavaScript files in `functions/`. Each file must export one default function:

```js
// functions/excerpt.js
export default function({ page }, value, length) {
  console.log("excerpt", page.permalink);
  return String(value).slice(0, Number(length));
}
```

Use the file stem as the function name:

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

The first argument is the JavaScript runtime context. Template functions receive `data`, `pages`, `page`, `props`, `files`, `httpClient`, `parse`, and `env`. `console` is available as a JavaScript global, not as `context.console`.

If a template function calls `parse.renderComponents(text)`, its context-bound `data`, `page`, and `pages` values can flow into component templates. Each component tag still supplies its own attributes and slot content through `props`. This differs from page-generator calls, where `page` and `pages` are not available because the generator is still creating the page list.

Function files are flat. Nested directories under `functions/` are not supported. A custom function can override a built-in function by using the same file stem.
