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