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