chore(deps): upgrade tailwind to v4 via vite plugin
Replace @astrojs/tailwind with @tailwindcss/vite in the Astro config and lockfile to adopt Tailwind CSS v4 and simplify the build setup. Also update Markdown site content with current SpaghetAI/MarvinBlade infrastructure details.
This commit is contained in:
1 parent
ac545c4668
commit
3fef5d378e
26 files changed
+1822
-3548
No files matched your search
@@ -0,0 +1,67 @@
|
||||
// src/lib/__tests__/content.test.ts
|
||||
import { describe, it, expect } from "vitest"
|
||||
import { byDateDesc } from "../content"
|
||||
|
||||
/**
|
||||
* Fixture factory rather than inline literals in every test: mirrors the shape
|
||||
* of an Astro content entry (id + data.date) without pulling in astro:content.
|
||||
*/
|
||||
function dated(id: string, date: string) {
|
||||
return { id, data: { date: new Date(date) } }
|
||||
}
|
||||
|
||||
describe("byDateDesc", () => {
|
||||
it("should order entries newest first when dates differ", () => {
|
||||
// Arrange: loader order (by id) is oldest -> newest.
|
||||
const entries = [
|
||||
dated("01-building-my-personal-website", "2025-08-12"),
|
||||
dated("03-spaghet-io-website-improvements", "2025-08-13"),
|
||||
dated("04-marvinblade-and-spaghetai", "2026-11-03"),
|
||||
]
|
||||
|
||||
// Act
|
||||
const sorted = [...entries].sort(byDateDesc)
|
||||
|
||||
// Assert
|
||||
expect(sorted.map((entry) => entry.id)).toEqual([
|
||||
"04-marvinblade-and-spaghetai",
|
||||
"03-spaghet-io-website-improvements",
|
||||
"01-building-my-personal-website",
|
||||
])
|
||||
})
|
||||
|
||||
it("should reverse entries that the loader already sorted oldest first by filename", () => {
|
||||
const entries = [
|
||||
dated("astro-profile", "2025-08-01"),
|
||||
dated("home-system", "2026-11-03"),
|
||||
]
|
||||
|
||||
expect([...entries].sort(byDateDesc).map((entry) => entry.id)).toEqual([
|
||||
"home-system",
|
||||
"astro-profile",
|
||||
])
|
||||
})
|
||||
|
||||
it("should break ties on id when two entries share the same date", () => {
|
||||
// Arrange: identical dates make the date comparison return 0.
|
||||
const entries = [
|
||||
dated("gitea", "2025-08-01"),
|
||||
dated("astro-profile", "2025-08-01"),
|
||||
]
|
||||
|
||||
// Act: sort twice to prove the result is stable, not build-order dependent.
|
||||
const first = [...entries].sort(byDateDesc).map((entry) => entry.id)
|
||||
const second = [...entries.reverse()].sort(byDateDesc).map((entry) => entry.id)
|
||||
|
||||
// Assert
|
||||
expect(first).toEqual(["astro-profile", "gitea"])
|
||||
expect(second).toEqual(first)
|
||||
})
|
||||
|
||||
it("should leave single-entry and empty collections untouched without throwing", () => {
|
||||
expect([...[dated("only", "2026-11-03")]].sort(byDateDesc).map((e) => e.id)).toEqual([
|
||||
"only",
|
||||
])
|
||||
expect(([] as ReturnType<typeof dated>[]).sort(byDateDesc)).toEqual([])
|
||||
})
|
||||
})
|
||||
@@ -0,0 +1,101 @@
|
||||
// src/lib/__tests__/search.test.ts
|
||||
import { describe, it, expect } from "vitest"
|
||||
import {
|
||||
createSearcher,
|
||||
partitionByCollection,
|
||||
runSearch,
|
||||
MIN_QUERY_LENGTH,
|
||||
} from "../search"
|
||||
import type { SearchEntry } from "@lib/types"
|
||||
|
||||
const ENTRIES: SearchEntry[] = [
|
||||
{
|
||||
id: "01-building-my-personal-website",
|
||||
slug: "01-building-my-personal-website",
|
||||
collection: "blog",
|
||||
title: "Building My Personal Website: From Idea to Deployment",
|
||||
summary: "A journey through creating my personal portfolio site.",
|
||||
tags: ["Tutorial", "Astro", "Portfolio", "Docker"],
|
||||
date: "2025-08-12T00:00:00.000Z",
|
||||
},
|
||||
{
|
||||
id: "astro-profile",
|
||||
slug: "astro-profile",
|
||||
collection: "projects",
|
||||
title: "Astro Profile",
|
||||
summary: "An Astro-based profile template with built in markdown support.",
|
||||
tags: ["portfolio", "personal", "astro"],
|
||||
date: "2025-08-08T00:00:00.000Z",
|
||||
},
|
||||
]
|
||||
|
||||
describe("createSearcher / runSearch", () => {
|
||||
const searcher = createSearcher(ENTRIES)
|
||||
|
||||
it("should return no results when the query is shorter than MIN_QUERY_LENGTH", () => {
|
||||
expect(runSearch(searcher, "")).toEqual([])
|
||||
expect(runSearch(searcher, "a")).toEqual([])
|
||||
// Whitespace-only input is treated as empty.
|
||||
expect(runSearch(searcher, " ")).toEqual([])
|
||||
})
|
||||
|
||||
it("should match on title", () => {
|
||||
const results = runSearch(searcher, "website")
|
||||
expect(results.map((entry) => entry.slug)).toContain(
|
||||
"01-building-my-personal-website"
|
||||
)
|
||||
})
|
||||
|
||||
it("should match tags case-insensitively", () => {
|
||||
const results = runSearch(searcher, "ASTRO")
|
||||
expect(results.length).toBeGreaterThan(0)
|
||||
expect(results.map((entry) => entry.slug)).toContain("astro-profile")
|
||||
})
|
||||
|
||||
it("should tolerate a mistyped query (fuzzy match)", () => {
|
||||
const results = runSearch(searcher, "websit")
|
||||
expect(results.map((entry) => entry.slug)).toContain(
|
||||
"01-building-my-personal-website"
|
||||
)
|
||||
})
|
||||
|
||||
it("should return no results when nothing matches", () => {
|
||||
expect(runSearch(searcher, "zzzq")).toEqual([])
|
||||
})
|
||||
|
||||
it("should never return fewer results than an exact substring match would", () => {
|
||||
const query = "deployment"
|
||||
const contains = ENTRIES.filter((entry) => entry.title.includes(query))
|
||||
expect(runSearch(searcher, query).length).toBeGreaterThanOrEqual(
|
||||
contains.length
|
||||
)
|
||||
})
|
||||
|
||||
it("should handle an empty dataset without throwing", () => {
|
||||
const empty = createSearcher([])
|
||||
expect(runSearch(empty, "astro")).toEqual([])
|
||||
})
|
||||
|
||||
it("should not require MIN_QUERY_LENGTH to change the contract", () => {
|
||||
expect(MIN_QUERY_LENGTH).toBeGreaterThan(1)
|
||||
})
|
||||
})
|
||||
|
||||
describe("partitionByCollection", () => {
|
||||
it("should split results into posts and projects by collection", () => {
|
||||
const { posts, projects } = partitionByCollection(ENTRIES)
|
||||
expect(posts.map((entry) => entry.slug)).toEqual([
|
||||
"01-building-my-personal-website",
|
||||
])
|
||||
expect(projects.map((entry) => entry.slug)).toEqual(["astro-profile"])
|
||||
})
|
||||
|
||||
it("should return empty buckets for an empty result set", () => {
|
||||
expect(partitionByCollection([])).toEqual({ posts: [], projects: [] })
|
||||
})
|
||||
|
||||
it("should preserve every entry exactly once across both buckets", () => {
|
||||
const { posts, projects } = partitionByCollection(ENTRIES)
|
||||
expect(posts.length + projects.length).toBe(ENTRIES.length)
|
||||
})
|
||||
})
|
||||
@@ -0,0 +1,23 @@
|
||||
// src/lib/__tests__/utils.test.ts
|
||||
import { describe, it, expect } from "vitest"
|
||||
import { formatDate, readingTime } from "@lib/utils"
|
||||
|
||||
describe("formatDate", () => {
|
||||
it("should render a frontmatter date exactly as authored when it is midnight UTC", () => {
|
||||
expect(formatDate(new Date("2025-08-12T00:00:00.000Z"))).toBe("Aug 12, 2025")
|
||||
})
|
||||
|
||||
it("should not shift the day when given an ISO string instead of a Date", () => {
|
||||
expect(formatDate("2026-11-03T00:00:00.000Z")).toBe("Nov 03, 2026")
|
||||
})
|
||||
|
||||
it("should stay stable for a date near the end of a month across timezones", () => {
|
||||
expect(formatDate(new Date("2026-11-30T00:00:00.000Z"))).toBe("Nov 30, 2026")
|
||||
})
|
||||
})
|
||||
|
||||
describe("readingTime", () => {
|
||||
it("should return a whole-number minute estimate for html content", () => {
|
||||
expect(readingTime("<p>one two three</p>")).toBe("1 min read")
|
||||
})
|
||||
})
|
||||
@@ -0,0 +1,43 @@
|
||||
// src/lib/content.ts
|
||||
import type { CollectionEntry } from "astro:content"
|
||||
import type { SearchEntry } from "@lib/types"
|
||||
|
||||
/**
|
||||
* Structural shape of anything the glob loader hands back for a dated
|
||||
* collection. Deliberately narrower than CollectionEntry<"blog"> so the
|
||||
* comparator can be unit tested without Astro's virtual module.
|
||||
*/
|
||||
interface DatedEntry {
|
||||
id: string
|
||||
data: { date: Date }
|
||||
}
|
||||
|
||||
/**
|
||||
* The glob loader returns entries in filename order, never by frontmatter
|
||||
* date, so every listing page must opt into date ordering explicitly.
|
||||
* Equal dates fall back to id to keep the order deterministic across builds
|
||||
* (two projects share 2025-08-01).
|
||||
*/
|
||||
export function byDateDesc(a: DatedEntry, b: DatedEntry): number {
|
||||
const diff = b.data.date.getTime() - a.data.date.getTime()
|
||||
return diff !== 0 ? diff : a.id.localeCompare(b.id)
|
||||
}
|
||||
|
||||
/**
|
||||
* Map a blog or project content entry down to the slim, serializable shape
|
||||
* used by ArrowCard and the search index. Centralising this keeps every page
|
||||
* (home, blog, projects, search) emitting identical card props.
|
||||
*/
|
||||
export function toSearchEntry(
|
||||
entry: CollectionEntry<"blog"> | CollectionEntry<"projects">
|
||||
): SearchEntry {
|
||||
return {
|
||||
id: entry.id,
|
||||
slug: entry.id,
|
||||
collection: entry.collection as "blog" | "projects",
|
||||
title: entry.data.title,
|
||||
summary: entry.data.summary,
|
||||
tags: entry.data.tags,
|
||||
date: entry.data.date.toISOString(),
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
// src/lib/search.ts
|
||||
import Fuse, { type IFuseOptions } from "fuse.js"
|
||||
import type { SearchEntry } from "@lib/types"
|
||||
|
||||
export type { SearchEntry }
|
||||
|
||||
/** Minimum characters before we bother running a query. */
|
||||
export const MIN_QUERY_LENGTH = 2
|
||||
|
||||
const FUSE_OPTIONS: IFuseOptions<SearchEntry> = {
|
||||
keys: [
|
||||
{ name: "title", weight: 0.4 },
|
||||
{ name: "tags", weight: 0.35 },
|
||||
{ name: "summary", weight: 0.25 },
|
||||
],
|
||||
threshold: 0.4,
|
||||
ignoreLocation: true,
|
||||
minMatchCharLength: MIN_QUERY_LENGTH,
|
||||
}
|
||||
|
||||
/**
|
||||
* Build a reusable fuzzy searcher over a set of entries.
|
||||
*
|
||||
* The index is created once per island hydration, so typing does not rebuild
|
||||
* it on every keystroke.
|
||||
*/
|
||||
export function createSearcher(entries: SearchEntry[]): Fuse<SearchEntry> {
|
||||
return new Fuse(entries, FUSE_OPTIONS)
|
||||
}
|
||||
|
||||
/**
|
||||
* Run a fuzzy query. Queries shorter than `MIN_QUERY_LENGTH` yield no results,
|
||||
* which lets the UI distinguish "not searched yet" from "searched, found none".
|
||||
*/
|
||||
export function runSearch(
|
||||
searcher: Fuse<SearchEntry>,
|
||||
rawQuery: string
|
||||
): SearchEntry[] {
|
||||
const query = rawQuery.trim()
|
||||
if (query.length < MIN_QUERY_LENGTH) return []
|
||||
return searcher.search(query).map((result) => result.item)
|
||||
}
|
||||
|
||||
/**
|
||||
* Partition a flat result set back into per-collection buckets for rendering.
|
||||
*/
|
||||
export function partitionByCollection(results: SearchEntry[]): {
|
||||
posts: SearchEntry[]
|
||||
projects: SearchEntry[]
|
||||
} {
|
||||
return {
|
||||
posts: results.filter((entry) => entry.collection === "blog"),
|
||||
projects: results.filter((entry) => entry.collection === "projects"),
|
||||
}
|
||||
}
|
||||
@@ -22,6 +22,30 @@ export interface Project {
|
||||
repoUrl: string;
|
||||
}
|
||||
|
||||
/**
|
||||
* The slim, client-serializable shape of a searchable document.
|
||||
*
|
||||
* Markdown `body` is deliberately excluded: serializing every post's full
|
||||
* content into the island's `props` measured 21,873 chars (43.5 KB page) and
|
||||
* was never matched against, so it was pure payload tax.
|
||||
*/
|
||||
export interface SearchEntry {
|
||||
id: string;
|
||||
slug: string;
|
||||
collection: "blog" | "projects";
|
||||
title: string;
|
||||
summary: string;
|
||||
tags: string[];
|
||||
date: string;
|
||||
}
|
||||
|
||||
/**
|
||||
* Shape accepted by ArrowCard. A union so the cards on the blog/projects
|
||||
* listing pages (flat BlogPost/Project) and search results (SearchEntry,
|
||||
* which carries `collection` + `slug`) both type-check.
|
||||
*/
|
||||
export type CardEntry = BlogPost | Project | SearchEntry
|
||||
|
||||
export interface WorkExperience {
|
||||
id: string;
|
||||
company: string;
|
||||
|
||||
+5
-1
@@ -10,7 +10,11 @@ export function formatDate(date: Date | string) {
|
||||
return Intl.DateTimeFormat("en-US", {
|
||||
month: "short",
|
||||
day: "2-digit",
|
||||
year: "numeric"
|
||||
year: "numeric",
|
||||
// Frontmatter dates such as `date: 2025-08-12` parse to midnight UTC. Without
|
||||
// pinning the timezone, formatting in a negative-offset locale (EST) shifted
|
||||
// every authored date one day earlier on screen.
|
||||
timeZone: "UTC",
|
||||
}).format(date)
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user