All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.quarkiverse.roq.frontmatter.runtime.model.RootUrl Maven / Gradle / Ivy

package io.quarkiverse.roq.frontmatter.runtime.model;

import jakarta.enterprise.inject.Vetoed;

import io.quarkiverse.roq.util.PathUtils;
import io.quarkus.qute.TemplateData;

/**
 * This represents the site root and allow to resolve other urls.
 */
@TemplateData
@Vetoed
public record RootUrl(
        /**
         * The site url (e.g. "https://example.com")
         */
        String url,

        /**
         * The application root path (e.g. "/my-root")
         */
        String rootPath) {
    public RootUrl(String url, String rootPath) {
        this.url = url;
        this.rootPath = PathUtils.prefixWithSlash(PathUtils.removeTrailingSlash(rootPath));
    }

    /**
     * @return the absolute root url (site url + root path)
     */
    public String absolute() {
        return PathUtils.join(url, rootPath);
    }

    /**
     * @return the relative root path
     */
    public String relative() {
        return rootPath();
    }

    /**
     * Resolve a path from the root url
     *
     * @param path the path to resolve
     * @return the new resolved RoqUrl
     */
    public RoqUrl resolve(String path) {
        return RoqUrl.fromRoot(this, path);
    }

    /**
     * {@see RootUrl.resolve(String path)}
     */
    public RoqUrl join(String path) {
        return resolve(path);
    }

    /**
     * Using a RootUrl as a String will print relative path
     */
    @Override
    public String toString() {
        return rootPath();
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy