Done
This commit is contained in:
parent
d3de14c2a1
commit
1dad20685e
3 changed files with 16222 additions and 10310 deletions
|
@ -13,7 +13,7 @@
|
||||||
<template v-if="!self">
|
<template v-if="!self">
|
||||||
<span class="schema">{{ schema }}{{ hostname.trim() != '' ? '//' : '' }}</span>
|
<span class="schema">{{ schema }}{{ hostname.trim() != '' ? '//' : '' }}</span>
|
||||||
<span class="hostname">{{ hostname.trim() != '' ? hostname.trim() : pathname }}</span>
|
<span class="hostname">{{ hostname.trim() != '' ? hostname.trim() : pathname }}</span>
|
||||||
<span v-if="port != ''" class="port">:{{ port }}</span>
|
<!-- <span v-if="port != ''" class="port">:{{ port }}</span> -->
|
||||||
</template>
|
</template>
|
||||||
<template v-if="pathname === '/' && self">
|
<template v-if="pathname === '/' && self">
|
||||||
<span class="self">{{ hostname }}</span>
|
<span class="self">{{ hostname }}</span>
|
||||||
|
@ -37,6 +37,7 @@ import { url as local } from "@/config";
|
||||||
import * as os from "@/os";
|
import * as os from "@/os";
|
||||||
import { useTooltip } from "@/scripts/use-tooltip";
|
import { useTooltip } from "@/scripts/use-tooltip";
|
||||||
import { safeURIDecode } from "@/scripts/safe-uri-decode";
|
import { safeURIDecode } from "@/scripts/safe-uri-decode";
|
||||||
|
import { parseUri } from "@/scripts/parse-uri"
|
||||||
|
|
||||||
const props = defineProps<{
|
const props = defineProps<{
|
||||||
url: string;
|
url: string;
|
||||||
|
@ -44,8 +45,8 @@ const props = defineProps<{
|
||||||
}>();
|
}>();
|
||||||
|
|
||||||
const self = props.url.startsWith(local);
|
const self = props.url.startsWith(local);
|
||||||
const url = new URL(props.url);
|
const url = parseUri(props.url);
|
||||||
if (!["http:", "https:", "gopher:", "gemini:", "matrix:", "ipfs:", "ipns:"].includes(url.protocol)) throw new Error("invalid url");
|
if (!["http", "https", "gopher", "gemini", "matrix", "ipfs", "ipns"].includes(url.scheme)) throw new Error("invalid url");
|
||||||
const el = ref();
|
const el = ref();
|
||||||
|
|
||||||
useTooltip(el, (showing) => {
|
useTooltip(el, (showing) => {
|
||||||
|
@ -63,12 +64,12 @@ useTooltip(el, (showing) => {
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
const schema = url.protocol;
|
const schema = url.scheme;
|
||||||
const hostname = decodePunycode(url.hostname);
|
const hostname = decodePunycode(url.authority ?? "");
|
||||||
const port = url.port;
|
// const port = url.port;
|
||||||
const pathname = safeURIDecode(url.pathname);
|
const pathname = safeURIDecode(url.path ?? "");
|
||||||
const query = safeURIDecode(url.search);
|
const query = safeURIDecode(url.query ?? "");
|
||||||
const hash = safeURIDecode(url.hash);
|
const hash = safeURIDecode(url.fragment ?? "");
|
||||||
const attr = self ? "to" : "href";
|
const attr = self ? "to" : "href";
|
||||||
const target = self ? null : "_blank";
|
const target = self ? null : "_blank";
|
||||||
</script>
|
</script>
|
||||||
|
|
26
packages/client/src/scripts/parse-uri.ts
Normal file
26
packages/client/src/scripts/parse-uri.ts
Normal file
|
@ -0,0 +1,26 @@
|
||||||
|
export function parseUri(uri: string): {
|
||||||
|
scheme: string;
|
||||||
|
authority: string | null;
|
||||||
|
path: string | null;
|
||||||
|
query: string | null;
|
||||||
|
fragment: string | null;
|
||||||
|
} {
|
||||||
|
const urlParts = uri.match(
|
||||||
|
/^(\w+):(\/\/)?([^/?#]*)(\/([^?#]*))?(\?([^#]*))?(#(.*))?$/,
|
||||||
|
);
|
||||||
|
|
||||||
|
if (!urlParts) {
|
||||||
|
throw new Error("Invalid URL format");
|
||||||
|
}
|
||||||
|
|
||||||
|
const [, scheme, withAuthority, authority, path, , query, , fragment] =
|
||||||
|
urlParts;
|
||||||
|
|
||||||
|
return {
|
||||||
|
scheme,
|
||||||
|
authority: withAuthority ? authority : null,
|
||||||
|
path: withAuthority ? path ?? null : `${authority}${path ?? ""}`,
|
||||||
|
query: query ?? null,
|
||||||
|
fragment: fragment || null,
|
||||||
|
};
|
||||||
|
}
|
26487
pnpm-lock.yaml
26487
pnpm-lock.yaml
File diff suppressed because it is too large
Load diff
Loading…
Reference in a new issue