diff --git a/src/components/Search.astro b/src/components/Search.astro index 255277f..509dd52 100644 --- a/src/components/Search.astro +++ b/src/components/Search.astro @@ -19,26 +19,16 @@ let fuse; let posts = []; - let searchInitialized = false; async function initializeSearch() { - // Prevent multiple initializations - if (searchInitialized) return; - try { - // Fetch the search index - const response = await fetch('/search-index.json'); - posts = await response.json(); - - fuse = new Fuse(posts, { - keys: ['title', 'description', 'content'], - threshold: 0.3, - includeMatches: true - }); - searchInitialized = true; - document.getElementById('search-results').innerHTML = ''; - } catch (error) { - console.error('Error fetching search index:', error); - } + const response = await fetch('/search-index.json'); + posts = await response.json(); + + fuse = new Fuse(posts, { + keys: ['title', 'description', 'content'], + threshold: 0.3, + includeMatches: true + }); } function performSearch(query) { @@ -47,8 +37,6 @@ return; } - if (!searchInitialized) return; - const results = fuse.search(query); const resultsElement = document.getElementById('search-results'); @@ -70,27 +58,14 @@ resultsElement.innerHTML = html; } + + // Initialize search when the component mounts + initializeSearch(); + // Add event listener for search input const searchInput = document.getElementById('search-input'); - - // Initialize search only when the input is focused or clicked - searchInput.addEventListener('focus', initializeSearch); - searchInput.addEventListener('click', initializeSearch); - searchInput.addEventListener('input', (e) => { - if (!searchInitialized) { - initializeSearch().then(() => { - performSearch(e.target.value); - }); - } else { - performSearch(e.target.value); - } - }); - - searchInput.addEventListener('focus', () => { - if (!searchInitialized) { - document.getElementById('search-results').innerHTML = '
Loading search index...
'; - } + performSearch(e.target.value); }); diff --git a/src/content/posts/_schemas.ts b/src/content/blog/_schemas.ts similarity index 85% rename from src/content/posts/_schemas.ts rename to src/content/blog/_schemas.ts index a1e7613..23945ba 100644 --- a/src/content/posts/_schemas.ts +++ b/src/content/blog/_schemas.ts @@ -1,6 +1,6 @@ import { z } from 'astro:content'; -export const posts = z.object({ +export const blogs = z.object({ title: z.string(), description: z.string(), pubDate: z.coerce.date(), diff --git a/src/content/posts/first-post.md b/src/content/blog/first-post.md similarity index 100% rename from src/content/posts/first-post.md rename to src/content/blog/first-post.md diff --git a/src/content/posts/minimalism.md b/src/content/blog/minimalism.md similarity index 100% rename from src/content/posts/minimalism.md rename to src/content/blog/minimalism.md diff --git a/src/content/posts/terminal-setup.md b/src/content/blog/terminal-setup.md similarity index 100% rename from src/content/posts/terminal-setup.md rename to src/content/blog/terminal-setup.md diff --git a/src/content/config.ts b/src/content/config.ts index f0cc13e..2a3f37e 100644 --- a/src/content/config.ts +++ b/src/content/config.ts @@ -1,17 +1,11 @@ import { defineCollection } from 'astro:content'; -import { posts } from './posts/_schemas'; -import { pages } from "./pages/_schemas"; +import { blogs } from './blog/_schemas'; const blogCollection = defineCollection({ type: 'content', - schema: posts, -}); -const pageCollection = defineCollection({ - type: 'content', - schema: pages, + schema: blogs, }); export const collections = { - 'posts': blogCollection, - 'pages': pageCollection, + 'blog': blogCollection, }; \ No newline at end of file diff --git a/src/content/pages/_schemas.ts b/src/content/pages/_schemas.ts deleted file mode 100644 index ec1c912..0000000 --- a/src/content/pages/_schemas.ts +++ /dev/null @@ -1,7 +0,0 @@ -import { z } from 'astro:content'; - -export const pages = z.object({ - title: z.string(), - description: z.string(), - heroImage: z.string().optional() -}); \ No newline at end of file diff --git a/src/content/pages/test.md b/src/content/pages/test.md deleted file mode 100644 index 7818aee..0000000 --- a/src/content/pages/test.md +++ /dev/null @@ -1,5 +0,0 @@ ---- -title: 'Test Page' -description: 'This is a test page' ---- -testestestest \ No newline at end of file diff --git a/src/pages/[...slug].astro b/src/pages/[...slug].astro deleted file mode 100644 index ced400d..0000000 --- a/src/pages/[...slug].astro +++ /dev/null @@ -1,21 +0,0 @@ ---- -import Layout from '../layouts/Layout.astro'; -import { getCollection } from "astro:content"; - -export async function getStaticPaths() { - const pageEntries = await getCollection('pages'); - return pageEntries.map(entry => ({ - params: { slug: entry.slug }, props: { entry }, - })); -} -const { entry } = Astro.props; -const { Content } = await entry.render(); - ---- - -{new Date(post.data.pubDate).toISOString().split('T')[0]} - {post.data.title} + {post.data.title}
))} diff --git a/src/pages/post/[...slug].astro b/src/pages/blog/[...slug].astro similarity index 97% rename from src/pages/post/[...slug].astro rename to src/pages/blog/[...slug].astro index 2826d2d..56d86fd 100644 --- a/src/pages/post/[...slug].astro +++ b/src/pages/blog/[...slug].astro @@ -3,7 +3,7 @@ import Layout from '../../layouts/Layout.astro'; import { getCollection } from 'astro:content'; export async function getStaticPaths() { - const blogEntries = await getCollection('posts'); + const blogEntries = await getCollection('blog'); return blogEntries.map(entry => ({ params: { slug: entry.slug }, props: { entry }, })); diff --git a/src/pages/post/[...slug].txt.js b/src/pages/post/[...slug].txt.js deleted file mode 100644 index 8d5624f..0000000 --- a/src/pages/post/[...slug].txt.js +++ /dev/null @@ -1,25 +0,0 @@ -import { getCollection } from 'astro:content'; - -export const prerender = true; -export async function getStaticPaths() { - const blogEntries = await getCollection('posts'); - return blogEntries.map(entry => ({ - params: { slug: entry.slug }, props: { entry }, - })); -} -export async function GET({ props }) { - const { entry } = props; - // Format the content as plain text - const title = entry.data.title; - const date = entry.data.pubDate.toISOString().split('T')[0]; - const content = entry.body; - - // Combine the post info and body into a single text file - const textContent = `Title: ${title}\nPublished at: ${date}\n\n${content}`; - - return new Response(textContent, { - headers: { - 'Content-Type': 'text/plain', - }, - }); -} \ No newline at end of file diff --git a/src/pages/rss.xml.js b/src/pages/rss.xml.js index 77e0091..75401dc 100644 --- a/src/pages/rss.xml.js +++ b/src/pages/rss.xml.js @@ -21,7 +21,7 @@ export async function GET(context) { const container = await AstroContainer.create({ renderers }); // Load the content collection entries to add to our RSS feed. - const posts = (await getCollection("posts")).sort((a, b) => + const posts = (await getCollection("blog")).sort((a, b) => // Sort by publication date descending. a.data.pubDate > b.data.pubDate ? -1 : 1 ); diff --git a/src/pages/search-index.json.js b/src/pages/search-index.json.js index 8b91cef..64fddd4 100644 --- a/src/pages/search-index.json.js +++ b/src/pages/search-index.json.js @@ -1,7 +1,7 @@ import { getCollection } from 'astro:content'; export async function GET() { - const posts = await getCollection('posts'); + const posts = await getCollection('blog'); const searchIndex = posts.map(post => ({ title: post.data.title, description: post.data.description, diff --git a/src/styles/global.css b/src/styles/global.css index 17d0a69..8128d4a 100644 --- a/src/styles/global.css +++ b/src/styles/global.css @@ -13,7 +13,7 @@ } /* Light theme */ @media (prefers-color-scheme: light) { - :root:not([data-theme="dark"]) { + :root { --bg-color: #f3f4f6; --text-color: #374151; --accent-color: #3b82f6; @@ -23,6 +23,16 @@ --terminal-yellow: #d97706; --terminal-red: #dc2626; } + :root:not([data-theme="light"]) { + --bg-color: #1f2937; + --text-color: #a5b4cf; + --accent-color: #64a0ff; + --border-color: #3b4351; + --header-color: #83a2ce; + --terminal-green: #4ade80; + --terminal-yellow: #fbbf24; + --terminal-red: #ef4444; + } } /* Light theme override (for switch) */ :root[data-theme="light"] { @@ -36,7 +46,6 @@ --terminal-red: #dc2626; } - *, *::before, *::after { box-sizing: border-box; margin: 0;