|
1 | | -<script> |
| 1 | +<script lang="ts"> |
2 | 2 | import { page } from '$app/stores'; |
| 3 | + import { onMount } from 'svelte'; |
| 4 | + import config from '../../config'; |
| 5 | + import { fetchRepoDetails, findRepoMeta } from '../../helpers/fetchRepo'; |
| 6 | + import type { Project } from '../../types/Project'; |
| 7 | + import ProjectHero from '../../components/ProjectHero.svelte'; |
| 8 | +
|
| 9 | + let gitHubPagesUrl = ''; |
| 10 | +
|
| 11 | + export let data: { repoDetails: Project, readme: string, meta: any }; |
| 12 | +
|
| 13 | + const reload = (url: string) => { |
| 14 | + window.location.replace(url); |
| 15 | + }; |
| 16 | +
|
| 17 | + onMount(async () => { |
| 18 | + // only for genuine 500s on a top-level slug |
| 19 | + |
| 20 | + const parts = $page.url.pathname.split('/').filter(Boolean); |
| 21 | + const repo = parts[0]; |
| 22 | + if (repo) { |
| 23 | + fetchRepoDetails(config.githubUser, repo, fetch) |
| 24 | + .then((res) => { |
| 25 | + if (res && res?.id) { |
| 26 | + data.repoDetails = res as Project; |
| 27 | + data.meta = findRepoMeta(repo, config.projects) || {}; |
| 28 | + console.log(data.repoDetails) |
| 29 | + if (data.repoDetails.has_pages) { |
| 30 | + gitHubPagesUrl = `https://${config.githubUser}.github.io/${repo}/`; |
| 31 | + } |
| 32 | + } |
| 33 | + }) |
| 34 | + .catch((err) => { |
| 35 | + console.error('Error fetching repo details', err); |
| 36 | + }); |
| 37 | + } |
| 38 | + |
| 39 | + }); |
3 | 40 | </script> |
4 | 41 |
|
5 | 42 | <svelte:head> |
6 | | - <title>Error | AS93</title> |
7 | | - <meta name="description" content="AS93 - Free & Open Source apps by Alicia Sykes" /> |
| 43 | + <title>Error | AS93</title> |
| 44 | + <meta name="description" content="AS93 - Free & Open Source apps by Alicia Sykes" /> |
8 | 45 | </svelte:head> |
9 | 46 |
|
10 | | -<p>Oops, somethings gone a bit wrong here</p> |
| 47 | +{#if gitHubPagesUrl} |
| 48 | +<a href="{gitHubPagesUrl}" class="has-github-pages" on:click="{() => reload(gitHubPagesUrl)}" > |
| 49 | + <h3>This page has a GitHub Pages site. Click to redirect.</h3> |
| 50 | +</a> |
| 51 | +{/if} |
| 52 | + |
| 53 | +{#if data.repoDetails && data.repoDetails.id} |
| 54 | + <ProjectHero project={data.repoDetails} meta={data.meta} /> |
| 55 | +{/if} |
| 56 | + |
| 57 | +<p>Oops, something's gone a bit wrong here</p> |
11 | 58 | <h1>{$page.status}</h1> |
12 | 59 | <p class="emoji">😢</p> |
13 | 60 | {#if $page?.error?.message} |
14 | | -<p>{$page.error.message}</p> |
| 61 | + <p>{$page.error.message}</p> |
15 | 62 | {/if} |
16 | 63 |
|
17 | | -<style> |
| 64 | +<style lang="scss"> |
18 | 65 | h1 { |
19 | 66 | font-size: 6rem; |
20 | 67 | margin: 0; |
|
29 | 76 | p { |
30 | 77 | font-size: 2rem; |
31 | 78 | margin: 0; |
32 | | - |
33 | 79 | text-align: center; |
34 | 80 | } |
| 81 | +
|
| 82 | +.has-github-pages { |
| 83 | + position: fixed; |
| 84 | + top: 0; |
| 85 | + left: 0; |
| 86 | + right: 0; |
| 87 | + width: 100%; |
| 88 | + background-color: var(--primary); |
| 89 | + padding: 0.25rem; |
| 90 | + text-align: center; |
| 91 | + font-size: 1.2rem; |
| 92 | + h3 { |
| 93 | + margin: 0; |
| 94 | + font-size: 1rem; |
| 95 | + } |
| 96 | +} |
35 | 97 | </style> |
0 commit comments