From e5f4b9d755341e2f5004dda3c6a7f716c52bba1e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=96mer=20Faruk=20Demirel?= Date: Sun, 22 Mar 2026 20:01:51 +0300 Subject: [PATCH] feat: search modal implemented --- src/components/SearchModal.astro | 476 +++++++++++++++++++++++++++++++ src/components/TopBar.astro | 75 +---- src/layouts/DocsLayout.astro | 2 + uno.config.ts | 2 + 4 files changed, 492 insertions(+), 63 deletions(-) create mode 100644 src/components/SearchModal.astro diff --git a/src/components/SearchModal.astro b/src/components/SearchModal.astro new file mode 100644 index 0000000..8fac2c5 --- /dev/null +++ b/src/components/SearchModal.astro @@ -0,0 +1,476 @@ +--- +import { getCollection } from 'astro:content' +import rawCategoriesTr from '../data/tr/categories.json' +import rawCategoriesEn from '../data/en/categories.json' +import rawTagsTr from '../data/tr/tags.json' +import rawTagsEn from '../data/en/tags.json' + +interface Props { + lang: string +} + +const { lang } = Astro.props + +const allArticles = await getCollection('articles') +const articles = allArticles + .filter((a) => a.data.status === 'Published' && a.data.lang === lang) + .map((a) => ({ + id: a.data.slug, + title: a.data.title, + excerpt: a.data.excerpt || '', + category: a.data.category, + categorySlug: a.data.category.toLowerCase().replace(/\s+/g, '-'), + tags: a.data.tags || [], + views: a.data.views || 0, + url: `/${lang === 'en' ? 'en/' : ''}articles/${a.data.slug}`, + })) + +const rawCategories = lang === 'en' ? rawCategoriesEn : rawCategoriesTr +const categories = rawCategories.map((c) => ({ + id: c.slug, + name: c.name, + description: c.description || '', + articleCount: c.articleCount || 0, + color: c.color || '#6366F1', + url: `/${lang === 'en' ? 'en/' : ''}categories/${c.slug}`, +})) + +const rawTags = lang === 'en' ? rawTagsEn : rawTagsTr +const tags = rawTags.map((t) => ({ + id: t.slug, + name: t.name, + slug: t.slug, + articleCount: t.articleCount || 0, + description: t.description || '', + url: `/${lang === 'en' ? 'en/' : ''}tags/${t.slug}`, +})) + +const searchData = JSON.stringify({ articles, categories, tags }) +--- + + + + + + diff --git a/src/components/TopBar.astro b/src/components/TopBar.astro index 9690297..0ed1942 100644 --- a/src/components/TopBar.astro +++ b/src/components/TopBar.astro @@ -1,6 +1,4 @@ --- -import rawArticlesTr from '../data/tr/articles.json' -import rawArticlesEn from '../data/en/articles.json' import LanguageSelector from './LanguageSelector.astro' import { t } from '../i18n/index.ts' @@ -11,18 +9,6 @@ interface Props { } const { lang, currentPath, labels } = Astro.props - -interface Article { - slug: string - title: string -} - -const rawArticles: Article[] = lang === 'en' ? rawArticlesEn : rawArticlesTr -const mappedArticles = rawArticles.map((a) => ({ - id: a.slug, - title: a.title, - category: '', -})) ---
({
@@ -83,7 +67,7 @@ const mappedArticles = rawArticles.map((a) => ({
-