fix(blog): add gray-matter types and fix client/server code separation

- Add type declaration file for gray-matter module
- Fix blog-analytics.tsx to import from specific modules instead of barrel export
  to prevent fs module from being bundled into client code
This commit is contained in:
Roo Code 2026-01-28 00:49:10 +00:00
parent fe1bfc1fde
commit 8fae3aeedd
2 changed files with 47 additions and 2 deletions

View file

@ -1,8 +1,13 @@
"use client"
import { useEffect, useRef } from "react"
import type { BlogPost } from "@/lib/blog"
import { trackBlogIndexView, trackBlogPostView, trackBlogPostScrollDepth, trackBlogPostTimeSpent } from "@/lib/blog"
import type { BlogPost } from "@/lib/blog/types"
import {
trackBlogIndexView,
trackBlogPostView,
trackBlogPostScrollDepth,
trackBlogPostTimeSpent,
} from "@/lib/blog/analytics"
interface BlogIndexAnalyticsProps {
postCount: number

View file

@ -0,0 +1,40 @@
/**
* Type declarations for gray-matter
* @see https://github.com/jonschlinkert/gray-matter
*/
declare module "gray-matter" {
interface GrayMatterFile<T = Record<string, unknown>> {
/** The parsed frontmatter data */
data: T
/** The content of the file without the frontmatter */
content: string
/** The original input string */
orig: string | Buffer
/** The language of the frontmatter */
language: string
/** The raw frontmatter string (excluding delimiters) */
matter: string
/** Whether the input string is empty */
isEmpty: boolean
/** Alias for content */
excerpt?: string
}
interface GrayMatterOption {
/** Custom excerpt function or boolean */
excerpt?: boolean | ((file: GrayMatterFile, options: GrayMatterOption) => void)
/** Custom separator for excerpt */
excerpt_separator?: string
/** Custom engines for parsing */
engines?: Record<string, unknown>
/** Language to use for parsing */
language?: string
/** Custom delimiters */
delimiters?: string | [string, string]
}
function matter<T = Record<string, unknown>>(input: string | Buffer, options?: GrayMatterOption): GrayMatterFile<T>
export = matter
}