web/src/components/things/ServiceCard.astro
185 lines · 4524 bytes
1---
2
3import { formatLink } from '@utils/parse-markdown';
4import type { Service } from 'src/types/Service';
5import FontAwesome from '@components/form/FontAwesome.svelte';
6import { slugify } from '@utils/fetch-data';
7
8interface Props {
9 service: Service;
10 categoryName: string;
11 sectionName: string;
12}
13
14const {
15 service,
16 sectionName,
17 categoryName,
18} = Astro.props;
19
20---
21
22<script>
23 document.addEventListener('DOMContentLoaded', () => {
24 const serviceIcons = document.querySelectorAll<HTMLImageElement>('.service-icon');
25 const broke = '/broken-image.png';
26
27 serviceIcons.forEach(function(icon) {
28 icon.onerror = function() {
29 const imgElement = this as HTMLImageElement;
30 const serviceUrl = imgElement.getAttribute('data-service-url');
31 const newSrcAttribute = (imgElement.src.includes('on.ho') ? broke : `https://icon.horse/icon/${serviceUrl}`);
32 imgElement.src = imgElement.src !== newSrcAttribute ? newSrcAttribute : broke;
33 imgElement.onerror = null;
34 };
35 });
36});
37</script>
38
39
40
41<div class="service" id={slugify(service.name)}>
42 <!-- <DeleteListing client:load categoryName={categoryName} sectionName={sectionName} serviceName={service.name} /> -->
43 <div class="service-head">
44 <a class="service-title" href={`/${slugify(categoryName)}/${slugify(sectionName)}/${slugify(service.name)}`}>
45 <h4>{service.name}</h4>
46 </a>
47 {service.followWith && <p class="follow-with">({service.followWith})</p> }
48 </div>
49
50 <div class="service-body">
51 <img
52 width="40"
53 height="40"
54 loading="lazy"
55 decoding="async"
56 class="service-icon"
57 alt={`${service.name} Icon`}
58 data-service-url={formatLink(service.url)}
59 src={service.icon || `https://icon.horse/icon/${formatLink(service.url)}`}
60 />
61 <div class="service-body">
62 <p set:html={service.description}></p>
63 </div>
64 </div>
65
66 <div class="service-links">
67 <a class="link" href={service.url}>
68 <FontAwesome iconName="website"/> <span>{formatLink(service.url)}</span>
69 </a>
70 {service.github &&
71 <a class="link" href={`https://github.com/${service.github}`}>
72 <FontAwesome iconName="sourceCode"/> GitHub
73 </a>
74 }
75 <a href={`/${slugify(categoryName)}/${slugify(sectionName)}/${slugify(service.name)}`}>
76 <FontAwesome iconName="viewReport" /> View Report ➔
77 </a>
78
79 </div>
80 </div>
81
82
83<style lang="scss">
84.service {
85 display: flex;
86 flex-direction: column;
87 padding: 1rem;
88 border: 2px solid var(--foreground);
89 box-shadow: 6px 6px 0 var(--foreground);
90 background: var(--accent-fg);
91 border-radius: var(--curve-sm);
92
93 .service-head {
94 display: flex;
95 align-items: center;
96 gap: 0.5rem;
97 h4 {
98 margin: 0;
99 font-size: 1.4rem;
100 color: var(--foreground);
101 }
102 p {
103 margin: 0;
104 font-size: 1rem;
105 opacity: 0.7;
106 }
107 a {
108 text-decoration: none;
109 }
110 h4 {
111 text-decoration: none;
112 position: relative;
113 &:after {
114 background: none repeat scroll 0 0 transparent;
115 bottom: 0;
116 content: "";
117 display: block;
118 height: 3px;
119 left: 50%;
120 position: absolute;
121 background: var(--accent-3);
122 transition: width 0.2s ease 0s, left 0.2s ease 0s;
123 width: 0;
124 }
125 &:hover:after {
126 width: 100%;
127 left: 0;
128 }
129 }
130 }
131
132 .service-body {
133 display: flex;
134 align-items: center;
135 gap: 0.5rem;
136 img {
137 border-radius: var(--curve-sm);
138 }
139 :global(p) {
140 display: -webkit-box;
141 -webkit-line-clamp: 3;
142 -webkit-box-orient: vertical;
143 overflow: hidden;
144 margin: 0.5rem 0;
145 width: calc(100% - 2rem);
146 overflow-x: hidden;
147 }
148 }
149
150 .service-links {
151 display: flex;
152 gap: 0.5rem;
153 justify-content: space-between;
154 a {
155 color: var(--accent-3);
156 font-size: 0.8rem;
157 display: inline-flex;
158 align-items: center;
159 gap: 0.25rem;
160 opacity: 0.7;
161 text-decoration: none;
162 max-width: 50%;
163 min-width: 25%;
164 &:not(:last-child) {
165 margin-right: 0.5rem;
166 }
167 &:hover {
168 text-decoration: underline;
169 opacity: 0.8;
170 }
171 :global(svg) {
172 width: 1rem;
173 height: 1rem;
174 }
175 span {
176 max-width: calc(100% - 1rem);
177 text-overflow: ellipsis;
178 white-space: nowrap;
179 overflow: hidden;
180 }
181 }
182 }
183}
184
185</style>