// A link-sharing site: links cleaned of tracking before they are saved, deduplicated by their
// normal form, and a page's relative links made absolute.
//
//   quillo run url_tools.qwe      then open http://localhost:8080/share?url=https://Shop.Example.com:443/a/../shoes?utm_source=x%26color=red%26fbclid=abc%23reviews

use "url_tools.qwer"

route GET /share ? { url: str } {
    let clean = url_strip_tracking(url)?
    { saved: clean, key: url_normalize(url)?, host: url_parse(clean)?.host }
}

route GET /same = {
    same: url_normalize("https://example.com/list?b=2&a=1#top")? == url_normalize("HTTPS://EXAMPLE.com:443/list?a=1&b=2&utm_medium=mail")?,
    joined: url_join("https://example.com/blog/2026/post.html", "../../img/cover.jpg")?,
    next_page: url_with_query("https://example.com/search?q=mugs&page=1&ref=nav", { page: 2, ref: null, sort: "price" })?,
    parts: url_parse("https://ada@example.com:8443/a/b?x=1&x=2&y=%C3%A9#frag")?,
    bad: url_parse("not a url").error,
}
