web/src/components/things/ServiceCard.svelte
101 lines · 2764 bytes
1<script lang="ts">
2 import FontAwesome from '@components/form/FontAwesome.svelte';
3 import SaveListing from '@components/things/SaveListing.svelte';
4 import { slugify } from '@utils/fetch-data';
5 import { formatLink, codebergUrl } from '@utils/parse-markdown';
6 import type { Service } from 'src/types/Service';
7
8 interface Props {
9 service: Service;
10 categoryName: string;
11 sectionName: string;
12 }
13 const { service, categoryName, sectionName }: Props = $props();
14
15 const serviceRef = $derived(slugify(service.name));
16 const categorySlug = $derived(slugify(categoryName));
17 const sectionSlug = $derived(slugify(sectionName));
18</script>
19
20<div class="service" id={serviceRef}>
21 <div class="service-head">
22 <a
23 class="service-title"
24 href={`/${categorySlug}/${sectionSlug}/${serviceRef}`}
25 >
26 <h4>{service.name}</h4>
27 </a>
28 {#if service.followWith}
29 <p class="follow-with">({service.followWith})</p>
30 {/if}
31 </div>
32
33 <div class="save-listing">
34 <SaveListing {categoryName} {sectionName} serviceName={service.name} />
35 </div>
36
37 <div class="service-body">
38 <img
39 width="40"
40 height="40"
41 loading="lazy"
42 decoding="async"
43 class="service-icon"
44 alt={`${service.name} Icon`}
45 data-service-url={formatLink(service.url)}
46 src={service.icon || `https://icon.horse/icon/${formatLink(service.url)}`}
47 />
48 <div class="service-body">
49 <!-- eslint-disable-next-line svelte/no-at-html-tags -- description is from curated YAML data, not user input -->
50 <p>{@html service.description}</p>
51 </div>
52 </div>
53
54 <div class="service-links">
55 <a
56 class="link"
57 href={service.url}
58 target="_blank"
59 rel="noopener noreferrer"
60 >
61 <FontAwesome iconName="website" /> <span>{formatLink(service.url)}</span>
62 </a>
63 {#if service.github}
64 <a
65 class="link"
66 href={`https://github.com/${service.github}`}
67 target="_blank"
68 rel="noopener noreferrer"
69 >
70 <FontAwesome iconName="sourceCode" /> GitHub
71 </a>
72 {/if}
73 {#if service.codeberg}
74 <a
75 class="link"
76 href={codebergUrl(service.codeberg)}
77 target="_blank"
78 rel="noopener noreferrer"
79 >
80 <FontAwesome iconName="sourceCode" /> Codeberg
81 </a>
82 {/if}
83 {#if service.git}
84 <a
85 class="link"
86 href={service.git}
87 target="_blank"
88 rel="noopener noreferrer"
89 >
90 <FontAwesome iconName="sourceCode" /> Source
91 </a>
92 {/if}
93 <a href={`/${categorySlug}/${sectionSlug}/${serviceRef}`}>
94 <FontAwesome iconName="viewReport" /> View Report ➔
95 </a>
96 </div>
97</div>
98
99<style lang="scss">
100 @use './service-card.scss';
101</style>