Re-implement domain normalization
This commit is contained in:
parent
a5314e5923
commit
23fdf5ab07
2 changed files with 10 additions and 5 deletions
|
@ -65,7 +65,7 @@ const { prefilledInstance } = Astro.props;
|
|||
</style>
|
||||
|
||||
<script>
|
||||
import { extractHost, normalizeURL } from "@scripts/util";
|
||||
import { getUrlDomain, normalizeURL } from "@scripts/util";
|
||||
import {
|
||||
savedInstances as instanceStore,
|
||||
saveInstance,
|
||||
|
@ -88,7 +88,7 @@ const { prefilledInstance } = Astro.props;
|
|||
return [];
|
||||
}
|
||||
|
||||
const host = extractHost(instance);
|
||||
const host = getUrlDomain(instance);
|
||||
if (index == 0 && !$instance.value) {
|
||||
$instance.value = host;
|
||||
}
|
||||
|
|
|
@ -19,9 +19,14 @@ export const normalizeURL = (url: string): string => {
|
|||
return url;
|
||||
};
|
||||
|
||||
export const extractHost = (url: string): string => {
|
||||
if (!(url.startsWith("https://") || url.startsWith("http://"))) {
|
||||
url = "https://" + url;
|
||||
export const getUrlDomain = (url: string | URL): string => {
|
||||
if (typeof url === "string") {
|
||||
url = url.trim();
|
||||
|
||||
if (!/^https?:\/\//.test(url)) {
|
||||
url = `https://${url}`;
|
||||
}
|
||||
}
|
||||
|
||||
return new URL(url).host;
|
||||
};
|
||||
|
|
Reference in a new issue