web/src/components/things/ServiceCard.svelte

81 lines · 2288 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 } 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    <a href={`/${categorySlug}/${sectionSlug}/${serviceRef}`}>
74      <FontAwesome iconName="viewReport" /> View Report ➔
75    </a>
76  </div>
77</div>
78
79<style lang="scss">
80  @use './service-card.scss';
81</style>