public static function url($input, $domain = false)
    {
        if (!trim((string)$input)) {
            $input = '/';
        }

        if (Grav::instance()['config']->get('system.absolute_urls', false)) {
            $domain = true;
        }

        if (Grav::instance()['uri']->isExternal($input)) {
            return $input;
        }

        /** @var Uri $uri */
        $uri = Grav::instance()['uri'];

        $root = $uri->rootUrl();
        $input = Utils::replaceFirstOccurrence($root, '', $input);

        $input = ltrim((string)$input, '/');

        if (Utils::contains((string)$input, '://')) {
            /** @var UniformResourceLocator $locator */
            $locator = Grav::instance()['locator'];

            $parts = Uri::parseUrl($input);

            if ($parts) {
                $resource = $locator->findResource("{$parts['scheme']}://{$parts['host']}{$parts['path']}", false);

                if (isset($parts['query'])) {
                    $resource = $resource . '?' . $parts['query'];
                }
            } else {
                // Not a valid URL (can still be a stream).
                $resource = $locator->findResource($input, false);
            }


        } else {
            $resource = $input;
        }



        return rtrim($uri->rootUrl($domain), '/') . '/' . ($resource ?? '');
    }