web/src/components/things/ServiceList.astro
336 lines · 9657 bytes
1---
2
3import Button from '@components/form/Button.astro';
4import { parseMarkdown, formatLink } from '@utils/parse-markdown';
5import type { Service } from 'src/types/Service';
6import FontAwesome from '@components/form/FontAwesome.svelte';
7import DeleteListing from '@components/things/DeleteListing.svelte';
8import { slugify } from '@utils/fetch-data';
9
10import GitHubMetrics from '@components/things/ItemGitHubMetrics.astro';
11import SaveListing from '@components/things/SaveListing.svelte';
12
13interface Props {
14 services: Service[];
15 subHeading?: boolean;
16 buttonLink?: string;
17 noGitHubMetrics?: boolean;
18 sectionName: string;
19 categoryName: string;
20}
21
22const {
23 services,
24 subHeading,
25 buttonLink,
26 noGitHubMetrics,
27 sectionName,
28 categoryName,
29} = Astro.props;
30
31---
32
33<script>
34 document.addEventListener('DOMContentLoaded', () => {
35 const serviceIcons = document.querySelectorAll<HTMLImageElement>('.service-icon');
36 const broke = '/broken-image.png';
37
38 serviceIcons.forEach(function(icon) {
39 icon.onerror = function() {
40 const imgElement = this as HTMLImageElement;
41 const serviceUrl = imgElement.getAttribute('data-service-url');
42 const newSrcAttribute = (imgElement.src.includes('on.ho') ? broke : `https://icon.horse/icon/${serviceUrl}`);
43 imgElement.src = imgElement.src !== newSrcAttribute ? newSrcAttribute : broke;
44 imgElement.onerror = null;
45 };
46 });
47});
48</script>
49
50
51
52<section>
53 {services && services.length > 0 ? (
54 <ul>
55 {services.map((service: Service) => (
56 <li id={slugify(service.name)}>
57 <DeleteListing client:load categoryName={categoryName} sectionName={sectionName} serviceName={service.name} />
58 <div class="save-listing">
59 <SaveListing client:visible
60 categoryName={categoryName}
61 sectionName={sectionName}
62 serviceName={service.name}
63 />
64 </div>
65 <div class="service-head">
66 <img
67 width="40"
68 height="40"
69 loading="lazy"
70 decoding="async"
71 class="service-icon"
72 alt={`${service.name} Icon`}
73 data-service-url={formatLink(service.url)}
74 src={service.icon || `https://icon.horse/icon/${formatLink(service.url)}`}
75 />
76
77 <a class="service-title" href={`/${slugify(categoryName)}/${slugify(sectionName)}/${slugify(service.name)}`}>
78 {subHeading ? <h4>{service.name}</h4> : <h3>{service.name}</h3>}
79 </a>
80 {service.followWith && <p class="follow-with">({service.followWith})</p> }
81 <a class="service-link" href={service.url}>{formatLink(service.url)}</a>
82 </div>
83 <div class="service-body">
84 <p set:html={parseMarkdown(service.description)}></p>
85 <div class="service-stats">
86 <div class="left">
87 { service.securityAudited && (
88 <span class="meta-item great" title={`${service.name} has been security audited by an accredited auditor, with results published publicly`}>
89 <FontAwesome iconName="securityAudited" /> Security Audited
90 </span>
91 )}
92 { service.acceptsCrypto && (
93 <span class="meta-item great" title={`${service.name} accepts anonymous payment methods`}>
94 <FontAwesome iconName="cryptoAccepted" /> Crypto Payments Accepted
95 </span>
96 )}
97 { service.securityAudited === false && (
98 <span class="meta-item warning" title={`${service.name} has not been audited`}>
99 <FontAwesome iconName="notSecurityAudited" /> No Security Audit
100 </span>
101 )}
102 { (service.openSource === false) && (
103 <span class="warning">
104 <FontAwesome iconName="closedSource" />
105 Not Open Source
106 </span>
107 )}
108 { service.openSource || (service.github && service.openSource !== false) ? (
109 <span class="meta-item great" title={`${service.name} is open source`}>
110 <FontAwesome iconName="openSource" /> Open Source
111 </span>
112 ) : null }
113 { service.github && !noGitHubMetrics && <GitHubMetrics github={service.github} /> }
114 { service.github && noGitHubMetrics && (
115 <span class="meta-item" title={`View ${service.name} on GitHub`}>
116 <a href={`https://github.com/${service.github}`} target="_blank">
117 <FontAwesome iconName="github" /> {service.github}
118 </a>
119 </span>
120 ) }
121 </div>
122 <div class="view-service">
123 <a href={`/${slugify(categoryName)}/${slugify(sectionName)}/${slugify(service.name)}`}>View {service.name} Report</a>
124 </div>
125 </div>
126 </div>
127 </li>
128 ))}
129 </ul>
130 ) : (
131 <p class="nothing-yet">
132 <strong>⚠️ This section is still a work in progress ⚠️</strong><br />
133 Check back soon, or help us complete it by submiting a pull request on GitHub.
134 <br />
135 <span class="quick-submit">Or submit an entry <a href="/submit">here</a></span>
136 </p>
137 )}
138
139 {buttonLink && (
140 <Button title={`View all ${categoryName}`} className="view-all" text="View More..." url={buttonLink} />
141 )}
142</section>
143
144
145<style lang="scss">
146
147 section {
148 padding: 1rem 0;
149 position: relative;
150 &:not(:last-child) {
151 border-bottom: 2px solid var(--accent-3);
152 }
153 }
154
155 .nothing-yet {
156 font-size: 1.4rem;
157 opacity: 0.8;
158 font-style: italic;
159 text-align: center;
160 margin-bottom: 3rem;
161 .quick-submit {
162 margin-top: 1rem;
163 font-size: 0.8rem;
164 opacity: 0.8;
165 }
166 }
167
168 ul {
169 list-style: none;
170 padding: 0;
171 margin: 0 0 3rem 0;
172 li {
173 margin-bottom: 1rem;
174 position: relative;
175 .save-listing {
176 position: absolute;
177 right: 1rem;
178 top: 1rem;
179 }
180 .service-head {
181 display: flex;
182 align-items: center;
183 gap: 0.5rem;
184 flex-wrap: wrap;
185 .service-title {
186 text-decoration: none;
187 color: var(--foreground);
188 h3, h4 {
189 margin: 0;
190 font-size: 1.6rem;
191 }
192
193 position: relative;
194 &:after {
195 background: none repeat scroll 0 0 transparent;
196 bottom: 0;
197 content: "";
198 display: block;
199 height: 3px;
200 left: 50%;
201 position: absolute;
202 background: var(--accent-3);
203 transition: width 0.3s ease 0s, left 0.3s ease 0s;
204 width: 0;
205 }
206 &:hover:after {
207 width: 100%;
208 left: 0;
209 }
210 }
211
212 .service-icon {
213 width: 2.5rem;
214 height: 2.5rem;
215 border-radius: var(--curve-sm);
216
217 font-size: 10px;
218 overflow: hidden;
219 color: var(--accent);
220 }
221 .follow-with {
222 opacity: 0.7;
223 font-style: italic;
224 margin: 0;
225 }
226 .service-link {
227 max-width: 300px;
228 text-overflow: ellipsis;
229 overflow: hidden;
230 white-space: nowrap;
231 }
232 }
233
234 .service-body {
235 margin: 0.5rem 0 2rem;
236 opacity: 0.8;
237 :global(p) {
238 margin: 0;
239 font-size: 1.2rem;
240 :global(a) {
241 color: var(--foregorund);
242 }
243 }
244 .service-stats {
245 .left {
246 display: flex;
247 gap: 1rem;
248 flex-wrap: wrap;
249 align-items: center;
250 }
251 display: flex;
252 gap: 1rem;
253 flex-wrap: wrap;
254 align-items: center;
255 justify-content: space-between;
256 }
257 .view-service {
258 transition: all 0.2s ease-in-out;
259 opacity: 0.95;
260 a {
261 padding: 0.25rem 0.6rem;
262 width: fit-content;
263 right: 1rem;
264 font-size: 0.9rem;
265 background: var(--accent-3);
266 color: var(--accent-fg);
267 text-decoration: none;
268 border-radius: var(--curve-md);
269 }
270 &:hover {
271 opacity: 1;
272 transform: scale(1.05);
273 }
274 }
275
276 .meta-item, .warning {
277 display: flex;
278 align-items: center;
279 // justify-content: center;
280 gap: 0.25rem;
281 // opacity: 0.6;
282 font-size: 0.9rem;
283 padding: 0.5rem 0;
284 :global(svg) {
285 color: var(--foreground);
286 width: 1.2rem;
287 height: 1.2rem;
288 }
289 a {
290 text-decoration: none;
291 color: var(--foreground);
292 display: flex;
293 gap: 0.25rem;
294 &:hover {
295 color: var(--accent-3);
296 :global(svg) {
297 color: var(--accent-3);
298 }
299 }
300 }
301 }
302 .warning {
303 color: var(--danger);
304 :global(svg) {
305 color: var(--danger);
306 }
307 }
308 .great {
309 color: #0fb953; // var(--success);
310 :global(svg) {
311 color: #0fb953; // var(--success);
312 }
313 }
314 }
315 }
316 }
317
318 section :global(.view-all) {
319 width: fit-content;
320 position: absolute;
321 right: 1rem;
322 margin-top: -2.5rem;
323 background: var(--accent-3);
324 }
325
326 li:hover :global(.actions) {
327 opacity: 0.6;
328 :global(a):hover {
329 opacity: 1;
330 }
331 }
332 :global(.actions a):hover {
333 opacity: 1;
334 }
335
336</style>