import { MediaQuery } from 'svelte/reactivity';
import HoverIcon from './HoverIcon.svelte';
+ import { tryGetIcon } from '$lib/util/IconResolver';
export let href: string;
let className: string = '';
@@ -8,60 +9,13 @@
export let customIcon: string | null = null;
const sm = new MediaQuery('width >= 40rem', false);
-
- let url: URL;
- let host: string;
-
- const icons: Record
= {
- none: 'material-symbols:link',
- 'steamcommunity.com': 'simple-icons:steam',
- 'twitter.com': 'simple-icons:x',
- 'x.com': 'simple-icons:x',
- 'github.com': 'simple-icons:github',
- 'youtube.com': 'simple-icons:youtube',
- 'itch.io': 'simple-icons:itchdotio',
- 'discord.gg': 'simple-icons:discord',
- 'gamebanana.com': 'simple-icons:gamebanana',
- // https://хамяк.рф
- 'xn--80auf8a2c.xn--p1ai': 'fluent-emoji-high-contrast:hamster',
- 'teasanctuary.ru': '/icons/tea-sanctuary.svg',
- 'hl.teasanctuary.ru': '/icons/half-life.svg',
- localhost: '/icons/tea-sanctuary.svg',
- email: 'material-symbols:alternate-email'
- };
-
- function getHost(url: URL) {
- const isEmail = url.href.startsWith('mailto:');
- const hostname = isEmail ? 'email' : url.hostname;
- // const split = hostname.split('.');
- // const name = split[Math.max(split.length - 2, 0)];
- // if (split.length > 1) return `${name}.${split[split.length - 1]}`;
-
- // return name;
- return hostname;
- }
-
- function tryGetIcon(link: string) {
- try {
- url = new URL(link);
- host = getHost(url).replace(/\.com$/, '');
- } catch {
- return icons['none'];
- }
-
- let domain = getHost(url).toLocaleLowerCase();
- let key = Object.keys(icons).find((key) => key == domain);
- if (key == null) return icons['none'];
-
- return icons[key];
- }
diff --git a/src/lib/util/IconResolver.ts b/src/lib/util/IconResolver.ts
new file mode 100644
index 0000000..3425a3a
--- /dev/null
+++ b/src/lib/util/IconResolver.ts
@@ -0,0 +1,65 @@
+const icons: Record = {
+ none: 'material-symbols:link',
+ 'steamcommunity.com': 'simple-icons:steam',
+ 'twitter.com': 'simple-icons:x',
+ 'x.com': 'simple-icons:x',
+ 'github.com': 'simple-icons:github',
+ 'youtube.com': 'simple-icons:youtube',
+ 'itch.io': 'simple-icons:itchdotio',
+ 'discord.gg': 'simple-icons:discord',
+ 'gamebanana.com': 'simple-icons:gamebanana',
+ 'bsky.app': 'simple-icons:bluesky',
+ 'bsky.social': 'simple-icons:bluesky',
+ // https://хамяк.рф
+ 'xn--80auf8a2c.xn--p1ai': 'fluent-emoji-high-contrast:hamster',
+ 'teasanctuary.ru': '/icons/tea-sanctuary-white.svg',
+ 'hl.teasanctuary.ru': '/icons/half-life.svg',
+ 'git.teasanctuary.ru': 'devicon-plain:git',
+ localhost: '/icons/tea-sanctuary.svg',
+ email: 'material-symbols:alternate-email'
+};
+
+// Особые случаи, когда одним доменом второго уровня не ограничишься (например, randomtrash.itch.io)
+const specialResolvers: Record string> = {
+ 'teasanctuary.ru': (url) => {
+ // Домены третьего уровня и выше
+ const prefix = url.hostname.split('.').toReversed();
+ prefix.shift();
+ prefix.shift();
+ if (prefix[0] === "hl") {
+ return 'hl.teasanctuary.ru';
+ }
+ if (prefix[0] === "git" || url.pathname.split('/')[1] == "git") {
+ return 'git.teasanctuary.ru';
+ }
+ return 'teasanctuary.ru';
+ },
+ // Игнорируем имя пользователя
+ 'bsky.app': (url) => 'bsky.app',
+ 'bsky.social': (url) => 'bsky.social',
+ 'itch.io': (url) => 'itch.io'
+}
+
+function getIconFromUrl(url: URL): string | undefined {
+ const href = url.href;
+ if (href.startsWith('mailto:'))
+ return 'email';
+
+ const hostname = url.hostname;
+ const secondLevel = hostname.match(/(([A-Za-z0-9\-])+\.([A-Za-z0-9\-])+)$/)?.at(0) ?? '';
+ if (specialResolvers[secondLevel])
+ return icons[specialResolvers[secondLevel](url)];
+
+ return icons[hostname];
+}
+
+export function tryGetIcon(link: string): string {
+ let url: URL;
+ try {
+ url = new URL(link);
+ } catch {
+ return icons['none'];
+ }
+
+ return getIconFromUrl(url) ?? icons['none'];
+}
\ No newline at end of file
diff --git a/src/routes/+page.svelte b/src/routes/+page.svelte
index 54c57d0..8d5cd50 100644
--- a/src/routes/+page.svelte
+++ b/src/routes/+page.svelte
@@ -5,7 +5,7 @@
-
+
+
Сообщество
GitHub
-
+
Наш Git
Сервер HLDM
-
+
хамяк)
@@ -109,8 +107,8 @@
Наша главная страсть — это, конечно, видеоигры. Мы часто участвуем в так называемых
"гейм джемах" — конкурсах на разработку игр. Наши игры вы можете оценить здесь:
- RandomTrash
- FriendlyWithMeat .
+ RandomTrash
+ FriendlyWithMeat .
Также мы ведём работу над нашим первым полноценным игровым проектом.
Следите за новостями в нашем
сообществе !
@@ -138,3 +136,11 @@
+
+
\ No newline at end of file
diff --git a/static/icons/tea-sanctuary-white.svg b/static/icons/tea-sanctuary-white.svg
new file mode 100644
index 0000000..6f05103
--- /dev/null
+++ b/static/icons/tea-sanctuary-white.svg
@@ -0,0 +1,70 @@
+
+
+
+
+
+
+
+
+
+