get all poems workin, get semantic search workin, get thoughts section working
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
<script lang="ts">
|
||||
import { searchResults } from '$lib/store';
|
||||
import type { SearchResult } from '$lib/utils/search';
|
||||
import { onMount } from 'svelte';
|
||||
|
||||
let results: SearchResult[] = [];
|
||||
|
||||
@@ -15,6 +16,10 @@
|
||||
.map((word) => word.charAt(0).toUpperCase() + word.slice(1))
|
||||
.join(' ');
|
||||
}
|
||||
|
||||
onMount(() => {
|
||||
searchResults.set([]);
|
||||
});
|
||||
</script>
|
||||
|
||||
{#if results.length > 0}
|
||||
@@ -26,8 +31,8 @@
|
||||
{#each results as result}
|
||||
<li class="py-4">
|
||||
<h3 class="pb-1">
|
||||
<a class="link" href="/poetry/{result.poem.id}">{slugToTitle(result.poem.id)}</a>
|
||||
<p class="text-sm">(Relevance: {(result.similarity * 100).toFixed(3)})%</p>
|
||||
<a class="link" href={`/poetry/${result.poem.id}`}>{slugToTitle(result.poem.id)}</a>
|
||||
<p class="text-sm">(Relevance: {(result.similarity * 100).toFixed(3)}%)</p>
|
||||
</h3>
|
||||
</li>
|
||||
{/each}
|
||||
|
@@ -1,5 +1,4 @@
|
||||
<script context="module">
|
||||
import { onMount } from 'svelte';
|
||||
import Headline from './poetry/h1.svelte';
|
||||
import p from './poetry/p.svelte';
|
||||
export { Headline as h1, p };
|
||||
|
18
src/lib/utils/ThoughtsLayout.svelte
Normal file
18
src/lib/utils/ThoughtsLayout.svelte
Normal file
@@ -0,0 +1,18 @@
|
||||
<script context="module">
|
||||
import Headline from './thoughts/h1.svelte';
|
||||
import p from './thoughts/p.svelte';
|
||||
export { Headline as h1, p };
|
||||
</script>
|
||||
|
||||
<script lang="ts">
|
||||
export let title;
|
||||
export let date;
|
||||
export let categories;
|
||||
export let tags;
|
||||
export let year;
|
||||
export let layout;
|
||||
</script>
|
||||
|
||||
<main>
|
||||
<slot />
|
||||
</main>
|
@@ -3,7 +3,7 @@ export interface Metadata {
|
||||
date: string;
|
||||
content: string;
|
||||
categories?: string[];
|
||||
section?: SectionKey;
|
||||
draft?: boolean;
|
||||
}
|
||||
|
||||
export interface Section {
|
||||
@@ -41,7 +41,7 @@ export const fetchMarkdownPosts = async (
|
||||
section: SectionKey,
|
||||
limit: number,
|
||||
offset: number
|
||||
): Promise<{posts: Post[], total: number}> => {
|
||||
): Promise<{ posts: Post[]; total: number }> => {
|
||||
let posts: Record<string, () => Promise<unknown>>;
|
||||
switch (section) {
|
||||
case 'poetry':
|
||||
@@ -50,33 +50,51 @@ export const fetchMarkdownPosts = async (
|
||||
case 'projects':
|
||||
posts = import.meta.glob('/src/routes/(app)/projects/posts/*.md');
|
||||
break;
|
||||
case 'thoughts':
|
||||
posts = import.meta.glob('/src/routes/(app)/thoughts/posts/*.md');
|
||||
case 'thoughts':
|
||||
posts = import.meta.glob('/src/posts/thoughts/*.md');
|
||||
console.log(posts);
|
||||
break;
|
||||
default:
|
||||
throw new Error('Could not find this section');
|
||||
}
|
||||
const iterablePostFiles = Object.entries(posts);
|
||||
|
||||
const postsWithErrors: string[] = [];
|
||||
|
||||
const allPosts = await Promise.all(
|
||||
iterablePostFiles.map(async ([path, resolver]) => {
|
||||
const data = await resolver();
|
||||
if (isData(data)) {
|
||||
const { metadata } = data;
|
||||
const postPath = path.slice(11, -3);
|
||||
return {
|
||||
meta: { ...metadata, section: section },
|
||||
path: postPath
|
||||
};
|
||||
} else {
|
||||
throw new Error('Could not properly parse this post');
|
||||
try {
|
||||
const data = await resolver();
|
||||
if (isData(data)) {
|
||||
if (data.metadata.draft) {
|
||||
return undefined;
|
||||
}
|
||||
const { metadata } = data;
|
||||
const postPath = path.slice(11, -3);
|
||||
return {
|
||||
meta: { ...metadata },
|
||||
path: postPath
|
||||
};
|
||||
} else {
|
||||
console.error('Could not properly parse this post');
|
||||
postsWithErrors.push(path);
|
||||
}
|
||||
} catch (error) {
|
||||
console.error(`Error parsing post at ${path}: ${error}`);
|
||||
postsWithErrors.push(path);
|
||||
}
|
||||
})
|
||||
);
|
||||
|
||||
const sortedPosts = allPosts.sort((a, b) => new Date(a.meta.date).getTime() - new Date(b.meta.date).getTime() );
|
||||
console.log('Files that could not be properly parsed:', postsWithErrors);
|
||||
|
||||
const sortedPosts: Post[] = allPosts
|
||||
.filter((post): post is Post => post !== undefined)
|
||||
.sort(
|
||||
(b, a) => new Date(a?.meta.date || '').getTime() - new Date(b?.meta.date || '').getTime()
|
||||
);
|
||||
|
||||
const paginatedPosts = sortedPosts.slice(offset, offset + limit);
|
||||
|
||||
return {posts: paginatedPosts, total: allPosts.length};
|
||||
return { posts: paginatedPosts, total: allPosts.length };
|
||||
};
|
||||
|
File diff suppressed because one or more lines are too long
3
src/lib/utils/thoughts/h1.svelte
Normal file
3
src/lib/utils/thoughts/h1.svelte
Normal file
@@ -0,0 +1,3 @@
|
||||
<h1 class="poetry-headline">
|
||||
<slot></slot>
|
||||
</h1>
|
3
src/lib/utils/thoughts/p.svelte
Normal file
3
src/lib/utils/thoughts/p.svelte
Normal file
@@ -0,0 +1,3 @@
|
||||
<p class="whitespace-pre-wrap">
|
||||
<slot></slot>
|
||||
</p>
|
Reference in New Issue
Block a user