web/src/components/things/ServiceList.astro
261 lines · 7319 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 {subHeading ? <h4>{service.name}</h4> : <h3>{service.name}</h3>}
71 {service.followWith && <p class="follow-with">({service.followWith})</p> }
72 <a class="service-link" href={service.url}>{formatLink(service.url)}</a>
73 </div>
74 <div class="service-body">
75 <p set:html={parseMarkdown(service.description)}></p>
76 <div class="service-stats">
77 { service.securityAudited && (
78 <span class="meta-item great" title={`${service.name} has been security audited by an accredited auditor, with results published publicly`}>
79 <FontAwesome iconName="securityAudited" /> Security Audited
80 </span>
81 )}
82 { service.acceptsCrypto && (
83 <span class="meta-item great" title={`${service.name} accepts anonymous payment methods`}>
84 <FontAwesome iconName="cryptoAccepted" /> Crypto Payments Accepted
85 </span>
86 )}
87 { service.securityAudited === false && (
88 <span class="meta-item warning" title={`${service.name} has not been audited`}>
89 <FontAwesome iconName="notSecurityAudited" /> No Security Audit
90 </span>
91 )}
92 { (service.openSource === false) && (
93 <span class="warning">
94 <FontAwesome iconName="closedSource" />
95 Not Open Source
96 </span>
97 )}
98 { service.openSource || (service.github && service.openSource !== false) ? (
99 <span class="meta-item great" title={`${service.name} is open source`}>
100 <FontAwesome iconName="openSource" /> Open Source
101 </span>
102 ) : null }
103 { service.github && !noGitHubMetrics && <GitHubMetrics github={service.github} /> }
104 { service.github && noGitHubMetrics && (
105 <span class="meta-item" title={`View ${service.name} on GitHub`}>
106 <a href={`https://github.com/${service.github}`}>
107 <FontAwesome iconName="github" /> {service.github}
108 </a>
109 </span>
110 ) }
111 <div class="view-service">
112 <a href={`/${slugify(categoryName)}/${slugify(sectionName)}/${slugify(service.name)}`}>View {service.name} Report</a>
113 </div>
114 </div>
115 </div>
116 </li>
117 ))}
118 </ul>
119 ) : (
120 <p class="nothing-yet">
121 <strong>⚠️ This section is still a work in progress ⚠️</strong><br />
122 Check back soon, or help us complete it by submiting a pull request on GitHub.
123 </p>
124 )}
125
126 {buttonLink && ( <Button className="view-all" text="View More..." url={buttonLink} /> )}
127</section>
128
129
130<style lang="scss">
131
132 section {
133 padding: 1rem 0;
134 position: relative;
135 &:not(:last-child) {
136 border-bottom: 2px solid var(--accent-3);
137 }
138 }
139
140 .nothing-yet {
141 font-size: 1.4rem;
142 opacity: 0.8;
143 font-style: italic;
144 text-align: center;
145 margin-bottom: 3rem;
146 }
147
148 ul {
149 list-style: none;
150 padding: 0;
151 margin: 0 0 3rem 0;
152 li {
153 margin-bottom: 1rem;
154 .service-head {
155 display: flex;
156 align-items: center;
157 gap: 0.5rem;
158 flex-wrap: wrap;
159 h3, h4 {
160 margin: 0;
161 font-size: 1.6rem;
162 }
163 .service-icon {
164 width: 2.5rem;
165 height: 2.5rem;
166 border-radius: var(--curve-sm);
167
168 font-size: 10px;
169 overflow: hidden;
170 color: var(--accent);
171 }
172 .follow-with {
173 opacity: 0.7;
174 font-style: italic;
175 margin: 0;
176 }
177 .service-link {
178 max-width: 300px;
179 text-overflow: ellipsis;
180 overflow: hidden;
181 white-space: nowrap;
182 }
183 }
184
185 .service-body {
186 margin: 0.5rem 0 2rem;
187 opacity: 0.8;
188 :global(p) {
189 margin: 0;
190 font-size: 1.2rem;
191 :global(a) {
192 color: var(--foregorund);
193 }
194 }
195 .service-stats {
196 display: flex;
197 gap: 1rem;
198 flex-wrap: wrap;
199 }
200 .meta-item, .warning {
201 display: flex;
202 align-items: center;
203 // justify-content: center;
204 gap: 0.25rem;
205 opacity: 0.6;
206 font-size: 0.9rem;
207 padding: 0.5rem 0;
208 :global(svg) {
209 color: var(--foreground);
210 width: 1.2rem;
211 height: 1.2rem;
212 }
213 a {
214 text-decoration: none;
215 color: var(--foreground);
216 display: flex;
217 gap: 0.25rem;
218 &:hover {
219 color: var(--accent-3);
220 :global(svg) {
221 color: var(--accent-3);
222 }
223 }
224 }
225 }
226 .warning {
227 color: var(--danger);
228 :global(svg) {
229 color: var(--danger);
230 }
231 }
232 .great {
233 color: #007930; // var(--success);
234 :global(svg) {
235 color: #007930; // var(--success);
236 }
237 }
238 }
239 }
240 }
241
242.view-service {
243 a {
244 padding: 0.25rem 0.6rem;
245 color: var(--accent-3);
246 width: fit-content;
247 position: absolute;
248 right: 1rem;
249 transform: scale(0.8);
250 }
251}
252
253section :global(.view-all) {
254 width: fit-content;
255 position: absolute;
256 right: 1rem;
257 margin-top: -2.5rem;
258 background: var(--accent-3);
259}
260
261</style>