web/src/components/things/ServiceList.astro
226 lines · 6625 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 h3, h4 {
137 margin: 0;
138 font-size: 1.6rem;
139 }
140 .service-icon {
141 width: 2.5rem;
142 height: 2.5rem;
143 border-radius: var(--curve-sm);
144
145 font-size: 10px;
146 overflow: hidden;
147 color: var(--accent);
148 }
149 .follow-with {
150 opacity: 0.7;
151 font-style: italic;
152 margin: 0;
153 }
154 .service-link {
155 max-width: 300px;
156 text-overflow: ellipsis;
157 overflow: hidden;
158 white-space: nowrap;
159 }
160 }
161
162 .service-body {
163 margin: 0.5rem 0 2rem;
164 opacity: 0.8;
165 :global(p) {
166 margin: 0;
167 font-size: 1.2rem;
168 :global(a) {
169 color: var(--foregorund);
170 }
171 }
172 .service-stats {
173 display: flex;
174 gap: 1rem;
175 }
176 .meta-item, .warning {
177 display: flex;
178 align-items: center;
179 // justify-content: center;
180 gap: 0.25rem;
181 opacity: 0.6;
182 font-size: 0.9rem;
183 padding: 0.5rem 0;
184 :global(svg) {
185 color: var(--foreground);
186 width: 1.2rem;
187 height: 1.2rem;
188 }
189 a {
190 text-decoration: none;
191 color: var(--foreground);
192 display: flex;
193 gap: 0.25rem;
194 &:hover {
195 color: var(--accent-3);
196 :global(svg) {
197 color: var(--accent-3);
198 }
199 }
200 }
201 }
202 .warning {
203 color: var(--danger);
204 :global(svg) {
205 color: var(--danger);
206 }
207 }
208 .great {
209 color: #007930; // var(--success);
210 :global(svg) {
211 color: #007930; // var(--success);
212 }
213 }
214 }
215 }
216 }
217
218section :global(.button) {
219 width: fit-content;
220 position: absolute;
221 right: 1rem;
222 margin-top: -2.5rem;
223 background: var(--accent-3);
224}
225
226</style>