code/pages/project/[repo].tsx

66 lines
2.1 KiB
TypeScript
Raw Normal View History

2021-10-17 18:41:15 +00:00
import { useParams } from 'solid-app-router';
import { createSignal, For, onMount, Show } from 'solid-js';
2021-12-09 09:09:52 +00:00
import { marked } from 'marked';
2021-10-17 18:41:15 +00:00
import Navbar from '../../components/Navbar';
import { convertCase } from '../../config/case';
import projects from '../../config/projects';
import { GithubRepository } from '../../types/github';
import { Project } from '../../types/project';
import 'solid-styled-jsx';
import css from '../../styles/repo.sass';
2021-10-17 18:41:15 +00:00
import Icons from '../../components/Icons';
async function fetchData(repo: string): Promise<Project> {
const findData = projects.find(i => convertCase(i.title) === repo);
2021-10-17 18:41:15 +00:00
if (!findData.repository) {
return { ...findData, details: 'Oops, sorry. Nothing to see here yet.' };
}
const repoPath = findData.repository.replace('https://github.com/', '');
const github = await (await fetch(`https://api.github.com/repos/${repoPath}`)).json() as GithubRepository;
const details = await (await fetch(`https://raw.githubusercontent.com/${repoPath}/${github.default_branch}/README.md`)).text();
return {
...findData,
github,
details,
2021-10-17 18:41:15 +00:00
};
}
function ProjectRepo() {
const params = useParams<{repo: string}>();
2021-10-17 18:41:15 +00:00
const [data, setData] = createSignal<Project>();
const [requestOk, setRequestOk] = createSignal<boolean>(false);
onMount(async () => {
const p = await fetchData(params.repo);
setData(p);
setRequestOk(true);
2021-10-17 18:41:15 +00:00
});
return (
<div>
<Navbar />
<style jsx dynamic={false} global={false}>
{`${css}`}
</style>
<Show when={requestOk()} fallback={<div>Please wait...</div>}>
2022-08-06 08:44:27 +00:00
<h1 class='text-3xl font-bold text-left py-2'>
{data().title}
</h1>
2022-08-06 08:44:27 +00:00
<p class='text-left py-2'>{data().description}</p>
<div class='flex flex-row flex-wrap items-center'>
<For each={data().stack}>
2022-08-06 08:44:27 +00:00
{item => <div class='flex-initial pr-2'><Icons name={item} /></div>}
</For>
</div>
2022-08-06 08:44:27 +00:00
<div innerHTML={marked.parse(data().details)} class='repoContent pb-6 pt-4' />
</Show>
</div>
2021-10-17 18:41:15 +00:00
);
}
export default ProjectRepo;