Clear existing content
This commit is contained in:
@@ -1,39 +0,0 @@
|
||||
import fs from 'fs'
|
||||
import path from 'path'
|
||||
import matter from 'gray-matter'
|
||||
|
||||
export interface MarkdownContent {
|
||||
frontmatter: {
|
||||
[key: string]: any
|
||||
}
|
||||
content: string
|
||||
}
|
||||
|
||||
export function getMarkdownContent(filePath: string): MarkdownContent {
|
||||
try {
|
||||
const fullPath = path.join(process.cwd(), filePath)
|
||||
|
||||
// Ensure file exists
|
||||
if (!fs.existsSync(fullPath)) {
|
||||
console.warn(`File not found: ${filePath}`)
|
||||
return {
|
||||
frontmatter: {},
|
||||
content: 'Content not found.'
|
||||
}
|
||||
}
|
||||
|
||||
const fileContents = fs.readFileSync(fullPath, 'utf8')
|
||||
const { data, content } = matter(fileContents)
|
||||
|
||||
return {
|
||||
frontmatter: data,
|
||||
content,
|
||||
}
|
||||
} catch (error) {
|
||||
console.error(`Error reading markdown file: ${filePath}`, error)
|
||||
return {
|
||||
frontmatter: {},
|
||||
content: 'Error loading content.'
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user