Skip to content

Commit ce41696

Browse files
committed
search
1 parent aa41263 commit ce41696

File tree

3 files changed

+38
-5
lines changed

3 files changed

+38
-5
lines changed

public/posts/001-project-overview.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,8 @@ The project follows a typical React application structure, with key directories
3939
1. **Entry Point (`src/index.js`):** The application starts by rendering the main `App` component into the `index.html` file.
4040
2. **Main Application (`src/App.js`):** The `App` component sets up client-side routing using `HashRouter`, defines the overall layout, and manages global contexts like the `ToastProvider`.
4141
3. **Routing (`react-router-dom`):** `AnimatedRoutes` (likely a component that uses `react-router-dom`'s `Routes` and `Route` components) handles mapping URLs to specific page components.
42-
4. **Content Fetching:** Blog posts and other dynamic content are fetched from `.txt` files located in the `public/` directory. Metadata for these posts is often stored in corresponding `.json` files (e.g., `public/posts/shownPosts.json`).
42+
4. **Content Fetching:** Blog posts and other dynamic content are fetched from `.txt` files located in the `public/` directory. Metadata for these posts is often stored in corresponding `.json` files (e.g., `public/posts/posts.json`). The blog page now includes a search functionality to easily find posts by title or slug.
4343
5. **Styling (`Tailwind CSS`):** The UI is styled primarily using Tailwind CSS utility classes, with some custom CSS if needed.
4444
6. **Deployment:** The application is built into static assets and deployed to GitHub Pages using the `gh-pages` package.
4545

46-
This overview provides a foundational understanding of the Fezcode project. Subsequent documents will delve into more specific details of each component and concept.
46+
This overview provides a foundational understanding of the Fezcode project. Subsequent documents will delve into more specific details of each component and concept.

src/index.css

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,16 @@ code {
5757
font-weight: 400; /* Lighter font weight */
5858
}
5959

60+
.prose h1 code,
61+
.prose h2 code,
62+
.prose h3 code,
63+
.prose h4 code,
64+
.prose h5 code,
65+
.prose h6 code {
66+
padding: 0.1em 0.2em !important;
67+
font-size: 0.9em !important;
68+
}
69+
6070
:root {
6171
--color-dev-badge: #44403c; /* stone-700 */
6272
--color-takes-badge: #065f46; /* emerald-800 */

src/pages/BlogPage.js

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ const BlogPage = () => {
99
const [displayItems, setDisplayItems] = useState([]);
1010
const [loading, setLoading] = useState(true);
1111
const [activeFilter, setActiveFilter] = useState('all'); // New state for active filter
12+
const [searchQuery, setSearchQuery] = useState(''); // New state for search query
1213

1314
useEffect(() => {
1415
const fetchPostSlugs = async () => {
@@ -94,9 +95,21 @@ const BlogPage = () => {
9495
}, []);
9596

9697
const filteredItems = displayItems.filter(item => {
97-
if (activeFilter === 'all') return true;
98-
if (activeFilter === 'series') return item.isSeries;
99-
return item.category === activeFilter && !item.isSeries;
98+
const matchesFilter = () => {
99+
if (activeFilter === 'all') return true;
100+
if (activeFilter === 'series') return item.isSeries;
101+
return item.category === activeFilter && !item.isSeries;
102+
};
103+
104+
const matchesSearch = () => {
105+
if (searchQuery === '') return true;
106+
const query = searchQuery.toLowerCase();
107+
const title = item.title ? item.title.toLowerCase() : '';
108+
const slug = item.slug ? item.slug.toLowerCase() : '';
109+
return title.includes(query) || slug.includes(query);
110+
};
111+
112+
return matchesFilter() && matchesSearch();
100113
});
101114

102115
if (loading) {
@@ -143,6 +156,16 @@ const BlogPage = () => {
143156
Total: {filteredItems.length}
144157
</span>
145158
</div>
159+
{/* Search Input */}
160+
<div className="mt-8 mb-4 flex justify-center">
161+
<input
162+
type="text"
163+
placeholder="Search posts..."
164+
className="w-full max-w-md px-4 py-2 rounded-full bg-gray-800 text-white placeholder-gray-400 focus:outline-none focus:ring-2 focus:ring-primary-500"
165+
value={searchQuery}
166+
onChange={(e) => setSearchQuery(e.target.value)}
167+
/>
168+
</div>
146169
{/* Filter Buttons */}
147170
<div className="mt-8 flex justify-center space-x-4">
148171
<button

0 commit comments

Comments
 (0)