Compare commits
5 Commits
08c174ba82
...
38ce5f3554
| Author | SHA1 | Date | |
|---|---|---|---|
| 38ce5f3554 | |||
| 5e3b5200e3 | |||
| ff839c5077 | |||
| 952cf9b949 | |||
| 844e47b88f |
@@ -4,7 +4,8 @@ import { decode } from 'he';
|
||||
|
||||
export enum ContentType {
|
||||
YOUTUBE_VIDEO,
|
||||
BLOG_POST
|
||||
BLOG_POST,
|
||||
THOUGHT
|
||||
}
|
||||
|
||||
export interface ContentItem {
|
||||
@@ -61,7 +62,7 @@ async function fetchBlogArticles(fetch: typeof globalThis.fetch, url: string) {
|
||||
published: new Date(article.pubDate),
|
||||
link: article.link,
|
||||
image: undefined,
|
||||
type: ContentType.BLOG_POST
|
||||
type: article.title == article.description ? ContentType.THOUGHT : ContentType.BLOG_POST
|
||||
});
|
||||
}
|
||||
return items.slice(0, 5);
|
||||
@@ -126,7 +127,7 @@ async function fetchContentItems(
|
||||
|
||||
finalArray.sort((a, b) => b.published.getTime() - a.published.getTime());
|
||||
|
||||
return finalArray.slice(0, 5);
|
||||
return finalArray.slice(0, 8);
|
||||
}
|
||||
|
||||
export async function getContentItems(
|
||||
|
||||
71
src/lib/server/gitea.ts
Normal file
71
src/lib/server/gitea.ts
Normal file
@@ -0,0 +1,71 @@
|
||||
export interface GitCommit {
|
||||
message: string;
|
||||
hash: string;
|
||||
shortHash: string;
|
||||
url: string;
|
||||
timestamp: Date;
|
||||
}
|
||||
|
||||
async function getGiteaRepos(fetch: typeof globalThis.fetch) {
|
||||
let response = await fetch(
|
||||
'https://git.voidarc.co.uk/api/v1/repos/search?sort=updated&order=desc&limit=10'
|
||||
);
|
||||
|
||||
if (!response.ok) {
|
||||
throw new Error('Could not fetch repo information: ' + response.status);
|
||||
}
|
||||
|
||||
let data = await response.json();
|
||||
|
||||
return data.data;
|
||||
}
|
||||
|
||||
async function getRepoCommits(fetch: typeof globalThis.fetch, url: string) {
|
||||
let response = await fetch(url + '/commits?page=1&limit=15');
|
||||
|
||||
if (!response.ok) {
|
||||
throw new Error('Could not fetch commit information: ' + response.status);
|
||||
}
|
||||
|
||||
let data = await response.json();
|
||||
|
||||
let finalData = [];
|
||||
|
||||
for (let commit of data) {
|
||||
// Filter out other users
|
||||
if (commit.author.login == 'voidarc') {
|
||||
finalData.push(commit);
|
||||
}
|
||||
}
|
||||
|
||||
return finalData;
|
||||
}
|
||||
|
||||
export async function getLatestCommits(fetch: typeof globalThis.fetch, count: number): GitCommit[] {
|
||||
const repos = await getGiteaRepos(fetch);
|
||||
|
||||
let commitList = [];
|
||||
for (let repo of repos) {
|
||||
console.log(repo.name);
|
||||
let commits = await getRepoCommits(fetch, repo.url);
|
||||
for (let commit of commits) {
|
||||
commitList.push(commit);
|
||||
console.log('pushed');
|
||||
}
|
||||
}
|
||||
commitList.sort((a, b) => new Date(b.created).getTime() - new Date(a.created).getTime());
|
||||
|
||||
let interfaceCommitList: GitCommit[] = [];
|
||||
for (let commit of commitList) {
|
||||
let commitObject: GitCommit = {
|
||||
message: commit.commit.message,
|
||||
hash: commit.sha,
|
||||
shortHash: commit.sha.substring(0, 8),
|
||||
timestamp: new Date(commit.created),
|
||||
url: commit.html_url
|
||||
};
|
||||
interfaceCommitList.push(commitObject);
|
||||
}
|
||||
|
||||
return interfaceCommitList.slice(0, count);
|
||||
}
|
||||
@@ -2,7 +2,9 @@ import type { PageServerLoad } from './$types';
|
||||
import { getLatestPlaylistSong, getLatestWatchedSeries } from '#lib/server/jellyfin';
|
||||
import { getLatestBook } from '#lib/server/komga';
|
||||
import { getContentItems } from '#lib/server/content';
|
||||
import { getLatestCommits } from '#lib/server/gitea';
|
||||
import type { ContentItem } from '#lib/server/content';
|
||||
import type { GitCommit } from '#lib/server/gitea';
|
||||
import {
|
||||
JELLYFIN_PLAYLIST_ID,
|
||||
JELLYFIN_LIBRARY_ID,
|
||||
@@ -17,19 +19,22 @@ export const load: PageServerLoad = () => {
|
||||
const latestBook = getLatestBook(globalThis.fetch, KOMGA_LIBRARY_ID);
|
||||
|
||||
const contentItems: ContentItem = getContentItems(globalThis.fetch, CHANNEL_ID, BLOG_URL);
|
||||
const latestCommits: GitCommit = getLatestCommits(globalThis.fetch, 10);
|
||||
|
||||
latestSong.catch(() => {});
|
||||
latestSeries.catch(() => {});
|
||||
latestBook.catch(() => {});
|
||||
|
||||
contentItems.catch(() => {});
|
||||
latestCommits.catch(() => {});
|
||||
|
||||
return {
|
||||
streamed: {
|
||||
latestSong,
|
||||
latestSeries,
|
||||
latestBook,
|
||||
contentItems
|
||||
contentItems,
|
||||
latestCommits
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
import { SiGit, SiHugo, SiYoutube } from '@icons-pack/svelte-simple-icons';
|
||||
|
||||
import Content from './Content.svelte';
|
||||
import Commits from './Commits.svelte';
|
||||
|
||||
let { data }: { data: PageData } = $props();
|
||||
import voidarcIcon from '../voidarc-hollow.svg?raw';
|
||||
@@ -187,6 +188,12 @@
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
{#await data.streamed.latestCommits}
|
||||
<p>loading commits...</p>
|
||||
{:then commits}
|
||||
{console.log(commits)}
|
||||
<Commits items={commits} />
|
||||
{/await}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
108
src/routes/Commits.svelte
Normal file
108
src/routes/Commits.svelte
Normal file
@@ -0,0 +1,108 @@
|
||||
<script lang="ts">
|
||||
import type { GitCommit } from './types';
|
||||
|
||||
let { items }: { items: GitCommit[] } = $props();
|
||||
|
||||
let containerElement: HTMLDivElement;
|
||||
let cardElements = $state<HTMLElement[]>([]);
|
||||
|
||||
let graphHeight = $state(0);
|
||||
let nodePositions = $state<{ x: number; y: number }[]>([]);
|
||||
|
||||
// Measure the actual centre of every article card.
|
||||
$effect(() => {
|
||||
const currentItems = items;
|
||||
const cards = cardElements.filter(Boolean);
|
||||
const container = containerElement;
|
||||
|
||||
if (!container || cards.length !== currentItems.length) return;
|
||||
|
||||
function updatePositions() {
|
||||
const containerRect = container.getBoundingClientRect();
|
||||
|
||||
nodePositions = cards.map((card) => {
|
||||
const rect = card.getBoundingClientRect();
|
||||
|
||||
return {
|
||||
x: 10,
|
||||
y: rect.top - containerRect.top + rect.height / 2
|
||||
};
|
||||
});
|
||||
|
||||
graphHeight = container.scrollHeight;
|
||||
}
|
||||
|
||||
// Initial measurement.
|
||||
updatePositions();
|
||||
|
||||
// Watch for changes in card or container dimensions.
|
||||
const observer = new ResizeObserver(updatePositions);
|
||||
|
||||
observer.observe(container);
|
||||
cards.forEach((card) => observer.observe(card));
|
||||
|
||||
// Also handle viewport changes.
|
||||
window.addEventListener('resize', updatePositions);
|
||||
|
||||
return () => {
|
||||
observer.disconnect();
|
||||
window.removeEventListener('resize', updatePositions);
|
||||
};
|
||||
});
|
||||
</script>
|
||||
|
||||
<div bind:this={containerElement} class="relative mt-1">
|
||||
<!-- SVG timeline overlay -->
|
||||
<svg
|
||||
class="pointer-events-none absolute top-0 left-0 z-0 overflow-visible"
|
||||
width="10"
|
||||
height={graphHeight}
|
||||
viewBox={`0 0 10 ${graphHeight}`}
|
||||
>
|
||||
<!-- Connecting lines -->
|
||||
{#each nodePositions as node, index}
|
||||
{#if nodePositions[index + 1]}
|
||||
<line
|
||||
x1={node.x}
|
||||
y1={node.y}
|
||||
x2={nodePositions[index + 1].x}
|
||||
y2={nodePositions[index + 1].y}
|
||||
stroke="currentColor"
|
||||
stroke-width="2"
|
||||
class="text-ctp-green"
|
||||
stroke-linecap="round"
|
||||
/>
|
||||
{/if}
|
||||
{/each}
|
||||
|
||||
<!-- Commit nodes -->
|
||||
{#each nodePositions as node}
|
||||
<circle
|
||||
cx={node.x}
|
||||
cy={node.y}
|
||||
r="7"
|
||||
fill="#313244"
|
||||
stroke="currentColor"
|
||||
stroke-width="2"
|
||||
class="text-ctp-green"
|
||||
/>
|
||||
{/each}
|
||||
</svg>
|
||||
|
||||
<!-- Article list -->
|
||||
<div class="mt-3 mr-3 grid grid-flow-row auto-rows-min">
|
||||
{#each items as item, index (item.hash)}
|
||||
<div class="relative z-10 grid grid-cols-[1.25rem_minmax(0,1fr)] gap-x-3.5 gap-y-4 pb-3">
|
||||
<!-- Timeline space -->
|
||||
<div></div>
|
||||
|
||||
<!-- Article card -->
|
||||
<div bind:this={cardElements[index]} class="min-w-0">
|
||||
<a href={item.link} class="group flex">
|
||||
<p class="rounded-md bg-ctp-surface2 px-1">{item.shortHash}</p>
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
{/each}
|
||||
</div>
|
||||
</div>
|
||||
@@ -100,7 +100,11 @@
|
||||
<div bind:this={cardElements[index]} class="min-w-0">
|
||||
<a
|
||||
href={item.link}
|
||||
style:--container-color={item.type == 0 ? 'var(--ctp-red)' : 'var(--ctp-lavender)'}
|
||||
style:--container-color={item.type == 0
|
||||
? 'var(--ctp-red)'
|
||||
: item.type == 2
|
||||
? 'var(--ctp-pink)'
|
||||
: 'var(--ctp-lavender)'}
|
||||
class="group dynamic-container flex bg-ctp-surface1 p-3 pl-2"
|
||||
>
|
||||
{#if item.image}
|
||||
@@ -109,9 +113,19 @@
|
||||
</div>
|
||||
{/if}
|
||||
<div style:padding-left={!item.image ? '4px' : 0}>
|
||||
<p class="font-medium group-hover:text-ctp-mauve group-hover:underline">
|
||||
{item.title}
|
||||
</p>
|
||||
{#if item.type == 2}
|
||||
<p
|
||||
class="line-clamp-3 font-medium italic group-hover:text-ctp-mauve group-hover:underline"
|
||||
>
|
||||
{item.title}
|
||||
</p>
|
||||
{:else}
|
||||
<p
|
||||
class="line-clamp-2 font-medium group-hover:text-ctp-mauve group-hover:underline"
|
||||
>
|
||||
{item.title}
|
||||
</p>
|
||||
{/if}
|
||||
|
||||
{#if item.description != item.title}
|
||||
<p class="text-muted-foreground mt-1 line-clamp-2 text-sm">
|
||||
|
||||
Reference in New Issue
Block a user