Source identity
| Field | Recorded value |
|---|---|
| Source type | GitHub source |
| Original record | Janady13/llms-txt-hub / apps/web/scripts/generate-search.ts |
| Date | Not specified in source |
| Repository | Janady13/llms-txt-hub |
| Revision | e0f4bf978d4df168369c7601d9c5f5ea89e84377 |
| Branch | main |
| Path or archive member | apps/web/scripts/generate-search.ts |
| Original SHA-256 | 38af1a3ce0806ee5c4a8c7bd01afa366688f34e6696694a754190f1b28802a41 |
| Git blob SHA | dd12c305655037b1f53e8c37b8582b92fbd13bd9 |
| Reading-copy SHA-256 | 38af1a3ce0806ee5c4a8c7bd01afa366688f34e6696694a754190f1b28802a41 |
Recovered source transcript
Download complete source text ↓58 lines · 1.5 KB
import fs from 'node:fs'
import path from 'node:path'
import { getContentFilePath, getContentPath } from '@thedaviddias/utils/content-paths'
import matter from 'gray-matter'
interface SearchEntry {
title: string
description: string
url: string
content: string
category?: string
}
async function generateSearchIndex() {
const websitesDirectory = getContentPath('websites')
const allFiles = fs.readdirSync(websitesDirectory)
// Only process .mdx files
const files = allFiles.filter(file => file.endsWith('.mdx'))
const entries: SearchEntry[] = []
for (const file of files) {
const filePath = getContentFilePath('websites', file)
const content = fs.readFileSync(filePath, 'utf8')
const { data, content: mdxContent } = matter(content)
entries.push({
title: data.name,
description: data.description,
url: `/${file.replace(/\.mdx$/, '')}`,
content: mdxContent,
category: data.category
})
}
// Write the search index to the apps/web/public directory instead of the root public directory
const searchIndexPath = path.join(
process.cwd(),
'apps',
'web',
'public',
'search',
'search-index.json'
)
// Ensure the directory exists
const searchIndexDir = path.dirname(searchIndexPath)
if (!fs.existsSync(searchIndexDir)) {
fs.mkdirSync(searchIndexDir, { recursive: true })
}
fs.writeFileSync(searchIndexPath, JSON.stringify(entries))
// Search index generated successfully
}
generateSearchIndex().catch(console.error)