web/src/components/things/ServiceList.astro

308 lines · 8917 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 ? (
 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 && ( <Button className="view-all" text="View More..." url={buttonLink} /> )}
130</section>
131
132
133<style lang="scss">
134
135  section {
136    padding: 1rem 0;
137    position: relative;
138    &:not(:last-child) {
139      border-bottom: 2px solid var(--accent-3);
140    }
141  }
142  
143  .nothing-yet {
144    font-size: 1.4rem;
145    opacity: 0.8;
146    font-style: italic;
147    text-align: center;
148    margin-bottom: 3rem;
149  }
150  
151  ul {
152    list-style: none;
153    padding: 0;
154    margin: 0 0 3rem 0;
155    li {
156      margin-bottom: 1rem;
157      position: relative;
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          position: relative;
172          &:after {    
173            background: none repeat scroll 0 0 transparent;
174            bottom: 0;
175            content: "";
176            display: block;
177            height: 3px;
178            left: 50%;
179            position: absolute;
180            background: var(--accent-3);
181            transition: width 0.3s ease 0s, left 0.3s ease 0s;
182            width: 0;
183          }
184          &:hover:after { 
185            width: 100%; 
186            left: 0; 
187          }
188        }
189        
190        .service-icon {
191          width: 2.5rem;
192          height: 2.5rem;
193          border-radius: var(--curve-sm);
194
195          font-size: 10px;
196          overflow: hidden;
197          color: var(--accent);
198        }
199        .follow-with {
200          opacity: 0.7;
201          font-style: italic;
202          margin: 0;
203        }
204        .service-link {
205          max-width: 300px;
206          text-overflow: ellipsis;
207          overflow: hidden;
208          white-space: nowrap;
209        }
210      }
211  
212      .service-body {
213        margin: 0.5rem 0 2rem;
214        opacity: 0.8;
215        :global(p) {
216          margin: 0;
217          font-size: 1.2rem;
218          :global(a) {
219            color: var(--foregorund);
220          }
221        }
222        .service-stats {
223          .left {
224            display: flex;
225            gap: 1rem;
226            flex-wrap: wrap;
227            align-items: center;
228          }
229          display: flex;
230          gap: 1rem;
231          flex-wrap: wrap;
232          align-items: center;
233          justify-content: space-between;
234        }
235        .view-service {
236          transition: all 0.2s ease-in-out;
237          opacity: 0.8;
238          a {
239            padding: 0.25rem 0.6rem;
240            width: fit-content;
241            right: 1rem;
242            font-size: 0.9rem;
243            background: var(--accent-3);
244            color: var(--accent-fg);
245            text-decoration: none;
246            border-radius: var(--curve-md);
247          }
248          &:hover {
249            opacity: 1;
250            transform: scale(1.05);
251          }
252        }
253
254        .meta-item, .warning {
255          display: flex;
256          align-items: center;
257          // justify-content: center;
258          gap: 0.25rem;
259          opacity: 0.6;
260          font-size: 0.9rem;
261          padding: 0.5rem 0;
262          :global(svg) {
263            color: var(--foreground);
264            width: 1.2rem;
265            height: 1.2rem;
266          }
267          a {
268            text-decoration: none;
269            color: var(--foreground);
270            display: flex;
271            gap: 0.25rem;
272            &:hover {
273              color: var(--accent-3);
274              :global(svg) {
275                color: var(--accent-3);
276              }
277            }
278          }
279        }
280        .warning {
281          color: var(--danger);
282          :global(svg) {
283            color: var(--danger);
284          }
285        }
286        .great {
287          color: #007930; // var(--success);
288          :global(svg) {
289            color: #007930; // var(--success);
290          }
291        }
292      }
293    }
294  }
295
296  section :global(.view-all) {
297    width: fit-content;
298    position: absolute;
299    right: 1rem;
300    margin-top: -2.5rem;
301    background: var(--accent-3);
302  }
303
304  li:hover :global(.actions) {
305    opacity: 0.5;
306  }
307  
308</style>