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