mirror of
https://github.com/youwen5/site.git
synced 2024-11-28 10:53:50 -08:00
feat: shift props around in components to prepare for real data
This commit is contained in:
parent
8d03497232
commit
9b5fab47c1
6 changed files with 97 additions and 43 deletions
10
src/globals.d.ts
vendored
10
src/globals.d.ts
vendored
|
@ -0,0 +1,10 @@
|
||||||
|
interface BlogDocument {
|
||||||
|
time: number;
|
||||||
|
title: string;
|
||||||
|
content: string;
|
||||||
|
primaryTags: string[];
|
||||||
|
secondaryTags: string[];
|
||||||
|
blurb: string;
|
||||||
|
image?: string;
|
||||||
|
description: string;
|
||||||
|
}
|
|
@ -1,29 +1,35 @@
|
||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import { ChevronRight } from 'svelte-radix';
|
import { ChevronRight } from 'svelte-radix';
|
||||||
|
import PostMetadata from './PostMetadata.svelte';
|
||||||
|
|
||||||
export let content: string;
|
export let doc: BlogDocument;
|
||||||
export let title: string;
|
|
||||||
export let description: string;
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<article>
|
<article>
|
||||||
<div class="mb-4 flex items-center space-x-1 text-sm text-muted-foreground">
|
<div class="mb-4 flex items-center space-x-1 text-sm text-muted-foreground">
|
||||||
<div class="overflow-hidden text-ellipsis whitespace-nowrap">The Coredump</div>
|
<div class="overflow-hidden text-ellipsis whitespace-nowrap">The Coredump</div>
|
||||||
<ChevronRight class="h-4 w-4" />
|
<ChevronRight class="h-4 w-4" />
|
||||||
<div class="font-medium text-foreground">{title}</div>
|
<div class="font-medium text-foreground">{doc.title}</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="space-y-2">
|
<div class="space-y-2">
|
||||||
<h1 class="scroll-m-20 text-5xl font-bold font-serif tracking-tight">
|
<h1 class="scroll-m-20 text-5xl font-bold font-serif tracking-tight">
|
||||||
{title}
|
{doc.title}
|
||||||
</h1>
|
</h1>
|
||||||
{#if description}
|
{#if doc.description}
|
||||||
<p class="text-balance text-lg text-muted-foreground">
|
<p class="text-balance text-lg text-muted-foreground">
|
||||||
{description}
|
{doc.description}
|
||||||
</p>
|
</p>
|
||||||
{/if}
|
{/if}
|
||||||
|
<PostMetadata
|
||||||
|
primaryTags={doc.primaryTags}
|
||||||
|
secondaryTags={doc.secondaryTags}
|
||||||
|
time={doc.time}
|
||||||
|
length={doc.content.length}
|
||||||
|
reverseDateAndRest
|
||||||
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="markdown-body mt-8 font-serif">
|
<div class="markdown-body mt-8 font-serif">
|
||||||
{@html content}
|
{@html doc.content}
|
||||||
</div>
|
</div>
|
||||||
</article>
|
</article>
|
||||||
|
|
|
@ -5,20 +5,18 @@
|
||||||
import PostMetadata from './PostMetadata.svelte';
|
import PostMetadata from './PostMetadata.svelte';
|
||||||
import { faker } from '@faker-js/faker';
|
import { faker } from '@faker-js/faker';
|
||||||
|
|
||||||
export let title: string;
|
export let doc: BlogDocument;
|
||||||
export let blurb: string;
|
|
||||||
export let description: string;
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<Card.Root>
|
<Card.Root>
|
||||||
<Card.Header>
|
<Card.Header>
|
||||||
<h3 class="text-4xl font-serif font-bold mb-4 leading-tight">{title}</h3>
|
<h3 class="text-4xl font-serif font-bold mb-4 leading-tight">{doc.title}</h3>
|
||||||
<p class="text-muted-foreground text-xl">{blurb}</p>
|
<p class="text-muted-foreground text-xl">{doc.blurb}</p>
|
||||||
<PostMetadata
|
<PostMetadata
|
||||||
primaryTags={Array.from({ length: 3 }, () => faker.hacker.noun())}
|
primaryTags={doc.primaryTags}
|
||||||
secondaryTags={Array.from({ length: 2 }, () => faker.hacker.noun())}
|
secondaryTags={doc.secondaryTags}
|
||||||
time={Date.now() / 1000}
|
time={doc.time}
|
||||||
length={faker.number.int(1000)}
|
length={doc.content.split(' ').length}
|
||||||
/>
|
/>
|
||||||
</Card.Header>
|
</Card.Header>
|
||||||
<Card.Content class="grid grid-cols-3 gap-6">
|
<Card.Content class="grid grid-cols-3 gap-6">
|
||||||
|
@ -28,7 +26,7 @@
|
||||||
class="col-span-3 md:col-span-1 rounded-2xl shadow-md"
|
class="col-span-3 md:col-span-1 rounded-2xl shadow-md"
|
||||||
/>
|
/>
|
||||||
<div class="flex flex-col justify-around col-span-3 md:col-span-2 gap-4">
|
<div class="flex flex-col justify-around col-span-3 md:col-span-2 gap-4">
|
||||||
<p class="text-primary/95 font-serif leading-relaxed">{description}</p>
|
<p class="text-primary/95 font-serif leading-relaxed">{doc.description}</p>
|
||||||
<Button variant="outline" href="/blog/2024/test-post" class="text-xl flex-grow sm:flex-grow-0"
|
<Button variant="outline" href="/blog/2024/test-post" class="text-xl flex-grow sm:flex-grow-0"
|
||||||
>Read More</Button
|
>Read More</Button
|
||||||
>
|
>
|
||||||
|
|
|
@ -9,6 +9,7 @@
|
||||||
- `secondaryTags` - An array of strings representing the secondary tags of the post.
|
- `secondaryTags` - An array of strings representing the secondary tags of the post.
|
||||||
- `time` - A unix epoch integer representing the time the post was published.
|
- `time` - A unix epoch integer representing the time the post was published.
|
||||||
- `length` - An integer representing amount of words in the post.
|
- `length` - An integer representing amount of words in the post.
|
||||||
|
- `reverseDateAndRest` - A boolean that determines whether the date should be displayed at the bottom of the metadata.
|
||||||
-->
|
-->
|
||||||
|
|
||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
|
@ -22,12 +23,15 @@
|
||||||
export let secondaryTags: string[] = [];
|
export let secondaryTags: string[] = [];
|
||||||
export let time: number;
|
export let time: number;
|
||||||
export let length: number;
|
export let length: number;
|
||||||
|
export let reverseDateAndRest: boolean = false;
|
||||||
|
|
||||||
let date = dayjs(time * 1000);
|
let date = dayjs(time * 1000);
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<div class="grid grid-cols-1">
|
<div class="grid grid-cols-1">
|
||||||
<p class="text-muted-foreground/80 my-1 text-lg">{date.format('MM/DD/YY')}</p>
|
{#if !reverseDateAndRest}
|
||||||
|
<p class="text-muted-foreground/80 my-1 text-lg">{date.format('MMMM DD, YYYY')}</p>
|
||||||
|
{/if}
|
||||||
<span class="flex items-center flex-wrap my-2 gap-2">
|
<span class="flex items-center flex-wrap my-2 gap-2">
|
||||||
{#each primaryTags as tag}
|
{#each primaryTags as tag}
|
||||||
<Badge>{tag}</Badge>
|
<Badge>{tag}</Badge>
|
||||||
|
@ -38,6 +42,9 @@
|
||||||
</span>
|
</span>
|
||||||
<!-- Assuming adult silent reading rate of 238 wpm -->
|
<!-- Assuming adult silent reading rate of 238 wpm -->
|
||||||
<span class="text-muted-foreground text-sm mt-2">
|
<span class="text-muted-foreground text-sm mt-2">
|
||||||
{dayjs(date).fromNow()} | {Math.round(length / 238)} min read | {length} words
|
{dayjs(date).fromNow()} | {Math.ceil(length / 238)} min read | {length} words
|
||||||
</span>
|
</span>
|
||||||
|
{#if reverseDateAndRest}
|
||||||
|
<p class="text-muted-foreground/80 text-xl mt-4">{date.format('MMMM DD, YYYY')}</p>
|
||||||
|
{/if}
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -17,6 +17,18 @@
|
||||||
onMount(() => {
|
onMount(() => {
|
||||||
loaded = true;
|
loaded = true;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
let testDoc: BlogDocument = {
|
||||||
|
title: 'An introduction to Taylor Series',
|
||||||
|
primaryTags: ['Computer Science', 'Mathematics'],
|
||||||
|
secondaryTags: ['Calculus', 'Taylor Series'],
|
||||||
|
time: Date.now() / 1000,
|
||||||
|
content:
|
||||||
|
"This is a test post to test the layout and rendering of the blog. It's taken directly from my obsidian notebook, so some of the formatting may be off. The blog supports KaTeX math rendering and GitHub markdown alerts. Support for syntax highlighting and graphs is coming soon.",
|
||||||
|
blurb: 'A brief introduction to Taylor Series and its applications in calculus.',
|
||||||
|
description:
|
||||||
|
'An insightful and longer description of the post. This should be a bit more detailed than the blurb. It should give the reader a good idea of what the post is about.'
|
||||||
|
};
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<svelte:head>
|
<svelte:head>
|
||||||
|
@ -43,22 +55,38 @@
|
||||||
Latest Posts
|
Latest Posts
|
||||||
</h2>
|
</h2>
|
||||||
{#each Array(5) as _, i}
|
{#each Array(5) as _, i}
|
||||||
<div
|
{#if i > 0}
|
||||||
class="grid grid-cols-1 gap-4 mt-8"
|
<div
|
||||||
in:fly|global={{ x: -50, delay: 350 + i * 100 }}
|
class="grid grid-cols-1 gap-4 mt-8"
|
||||||
>
|
in:fly|global={{ x: -50, delay: 350 + i * 100 }}
|
||||||
<PostCard
|
>
|
||||||
title={faker.hacker.noun() +
|
<PostCard
|
||||||
' ' +
|
doc={{
|
||||||
faker.hacker.verb() +
|
title:
|
||||||
' ' +
|
faker.hacker.noun() +
|
||||||
faker.hacker.adjective() +
|
' ' +
|
||||||
' ' +
|
faker.hacker.verb() +
|
||||||
faker.hacker.noun()}
|
' ' +
|
||||||
blurb={faker.hacker.phrase()}
|
faker.hacker.adjective() +
|
||||||
description={faker.lorem.paragraphs(2)}
|
' ' +
|
||||||
/>
|
faker.hacker.noun(),
|
||||||
</div>
|
primaryTags: Array(2).map(() => faker.hacker.noun()),
|
||||||
|
secondaryTags: Array(2).map(() => faker.hacker.noun()),
|
||||||
|
time: Date.now() / 1000,
|
||||||
|
content: faker.lorem.paragraphs(5),
|
||||||
|
blurb: faker.hacker.phrase(),
|
||||||
|
description: faker.lorem.paragraphs(2)
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
{:else}
|
||||||
|
<div
|
||||||
|
class="grid grid-cols-1 gap-4 mt-8"
|
||||||
|
in:fly|global={{ x: -50, delay: 350 + i * 100 }}
|
||||||
|
>
|
||||||
|
<PostCard doc={testDoc} />
|
||||||
|
</div>
|
||||||
|
{/if}
|
||||||
{/each}
|
{/each}
|
||||||
</div>
|
</div>
|
||||||
<div in:fly={{ y: -50, delay: 300 }} class="col-span-3 md:col-span-1">
|
<div in:fly={{ y: -50, delay: 300 }} class="col-span-3 md:col-span-1">
|
||||||
|
|
|
@ -6,13 +6,18 @@
|
||||||
import { cn } from '$lib/utils.js';
|
import { cn } from '$lib/utils.js';
|
||||||
import Article from '$lib/components/Blog/Article.svelte';
|
import Article from '$lib/components/Blog/Article.svelte';
|
||||||
|
|
||||||
let doc = {
|
|
||||||
title: 'Test Post',
|
|
||||||
description: 'An insightful and succinct blurb about the post.'
|
|
||||||
};
|
|
||||||
|
|
||||||
export let data: PageData;
|
export let data: PageData;
|
||||||
$: markdown = data.markdown;
|
|
||||||
|
let doc: BlogDocument = {
|
||||||
|
title: 'Test Post',
|
||||||
|
primaryTags: ['Computer Science', 'Mathematics'],
|
||||||
|
secondaryTags: ['Calculus', 'Taylor Series'],
|
||||||
|
time: Date.now() / 1000,
|
||||||
|
content: data.markdown,
|
||||||
|
blurb: 'A short and succinct, yet descriptive blurb about the post.',
|
||||||
|
description:
|
||||||
|
'An insightful and longer description of the post. This should be a bit more detailed than the blurb. It should give the reader a good idea of what the post is about.'
|
||||||
|
};
|
||||||
// $: doc = data.metadata;
|
// $: doc = data.metadata;
|
||||||
// $: componentSource = data.metadata.source?.replace('default', $config.style ?? 'default');
|
// $: componentSource = data.metadata.source?.replace('default', $config.style ?? 'default');
|
||||||
</script>
|
</script>
|
||||||
|
@ -24,5 +29,5 @@
|
||||||
</svelte:head>
|
</svelte:head>
|
||||||
|
|
||||||
<main class="max-w-4xl md:mx-auto mx-4 mt-8 mb-14">
|
<main class="max-w-4xl md:mx-auto mx-4 mt-8 mb-14">
|
||||||
<Article title={doc.title} description={doc.description} content={markdown} />
|
<Article {doc} />
|
||||||
</main>
|
</main>
|
||||||
|
|
Loading…
Reference in a new issue