Skip to content
Brought to you by Allons-y Studio
dashly A standard library of filters, transforms, & shortcodes for Eleventy

urls

In Filters

URL-related filters for Eleventy.

import {
	validateURL,
	absoluteUrl,
} from '@allons-y/dashly/filters/urls';

validateURL(url)

Ensure a URL is safe to render. Passes through mailto:, tel:, fragments, relative paths, and URLs already prefixed with http(s):. Everything else is prefixed with https://. All output is URI-encoded.

Note: pass the full URL string. This filter is not context-aware.

Parameters

Name Type Default Description
url string

Returns

string

absoluteUrl(path, baseUrl?)

Resolve a path or URL against a base, producing an absolute URL. Useful for canonical tags, OpenGraph metadata, JSON-LD, and RSS/Atom feeds — anywhere a fully-qualified URL is required.

Already-absolute URLs are returned unchanged. mailto:, tel:, and fragment-only (#section) inputs pass through as-is. Empty/nullish input returns an empty string.

Parameters

Name Type Default Description
path string A relative path, absolute path, or full URL.
baseUrl (optional) string The site's origin (e.g. https://example.com). Trailing slashes are tolerated. If omitted, the input is returned unchanged — useful during local development.

Returns

string

Examples

// 'https://example.com/posts/hello'
absoluteUrl('/posts/hello', 'https://example.com');
// 'https://example.com/posts/hello'
absoluteUrl('posts/hello', 'https://example.com/');
// 'https://other.com/x' — already absolute, returned as-is
absoluteUrl('https://other.com/x', 'https://example.com');
{# canonical tag #}
<link rel="canonical" href="{{ page.url | absoluteUrl }}">

Allons-y Studio

Let's build something great together

A front-end & design systems studio helping teams ship consistent, accessible UI faster.