web/src/components/things/ServiceList.astro
329 lines · 9463 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 </p>
135 )}
136
137 {buttonLink && (
138 <Button title={`View all ${categoryName}`} className="view-all" text="View More..." url={buttonLink} />
139 )}
140</section>
141
142
143<style lang="scss">
144
145 section {
146 padding: 1rem 0;
147 position: relative;
148 &:not(:last-child) {
149 border-bottom: 2px solid var(--accent-3);
150 }
151 }
152
153 .nothing-yet {
154 font-size: 1.4rem;
155 opacity: 0.8;
156 font-style: italic;
157 text-align: center;
158 margin-bottom: 3rem;
159 }
160
161 ul {
162 list-style: none;
163 padding: 0;
164 margin: 0 0 3rem 0;
165 li {
166 margin-bottom: 1rem;
167 position: relative;
168 .save-listing {
169 position: absolute;
170 right: 1rem;
171 top: 1rem;
172 }
173 .service-head {
174 display: flex;
175 align-items: center;
176 gap: 0.5rem;
177 flex-wrap: wrap;
178 .service-title {
179 text-decoration: none;
180 color: var(--foreground);
181 h3, h4 {
182 margin: 0;
183 font-size: 1.6rem;
184 }
185
186 position: relative;
187 &:after {
188 background: none repeat scroll 0 0 transparent;
189 bottom: 0;
190 content: "";
191 display: block;
192 height: 3px;
193 left: 50%;
194 position: absolute;
195 background: var(--accent-3);
196 transition: width 0.3s ease 0s, left 0.3s ease 0s;
197 width: 0;
198 }
199 &:hover:after {
200 width: 100%;
201 left: 0;
202 }
203 }
204
205 .service-icon {
206 width: 2.5rem;
207 height: 2.5rem;
208 border-radius: var(--curve-sm);
209
210 font-size: 10px;
211 overflow: hidden;
212 color: var(--accent);
213 }
214 .follow-with {
215 opacity: 0.7;
216 font-style: italic;
217 margin: 0;
218 }
219 .service-link {
220 max-width: 300px;
221 text-overflow: ellipsis;
222 overflow: hidden;
223 white-space: nowrap;
224 }
225 }
226
227 .service-body {
228 margin: 0.5rem 0 2rem;
229 opacity: 0.8;
230 :global(p) {
231 margin: 0;
232 font-size: 1.2rem;
233 :global(a) {
234 color: var(--foregorund);
235 }
236 }
237 .service-stats {
238 .left {
239 display: flex;
240 gap: 1rem;
241 flex-wrap: wrap;
242 align-items: center;
243 }
244 display: flex;
245 gap: 1rem;
246 flex-wrap: wrap;
247 align-items: center;
248 justify-content: space-between;
249 }
250 .view-service {
251 transition: all 0.2s ease-in-out;
252 opacity: 0.95;
253 a {
254 padding: 0.25rem 0.6rem;
255 width: fit-content;
256 right: 1rem;
257 font-size: 0.9rem;
258 background: var(--accent-3);
259 color: var(--accent-fg);
260 text-decoration: none;
261 border-radius: var(--curve-md);
262 }
263 &:hover {
264 opacity: 1;
265 transform: scale(1.05);
266 }
267 }
268
269 .meta-item, .warning {
270 display: flex;
271 align-items: center;
272 // justify-content: center;
273 gap: 0.25rem;
274 // opacity: 0.6;
275 font-size: 0.9rem;
276 padding: 0.5rem 0;
277 :global(svg) {
278 color: var(--foreground);
279 width: 1.2rem;
280 height: 1.2rem;
281 }
282 a {
283 text-decoration: none;
284 color: var(--foreground);
285 display: flex;
286 gap: 0.25rem;
287 &:hover {
288 color: var(--accent-3);
289 :global(svg) {
290 color: var(--accent-3);
291 }
292 }
293 }
294 }
295 .warning {
296 color: var(--danger);
297 :global(svg) {
298 color: var(--danger);
299 }
300 }
301 .great {
302 color: #0fb953; // var(--success);
303 :global(svg) {
304 color: #0fb953; // var(--success);
305 }
306 }
307 }
308 }
309 }
310
311 section :global(.view-all) {
312 width: fit-content;
313 position: absolute;
314 right: 1rem;
315 margin-top: -2.5rem;
316 background: var(--accent-3);
317 }
318
319 li:hover :global(.actions) {
320 opacity: 0.6;
321 :global(a):hover {
322 opacity: 1;
323 }
324 }
325 :global(.actions a):hover {
326 opacity: 1;
327 }
328
329</style>