mirror of
https://github.com/lucide-icons/lucide.git
synced 2026-11-17 14:28:25 +00:00
* Add markdown support * Fix a lot of issues * Add core components * Add codeblocks * fix codeblocks * Add More components * add links * Fix loading docs * Fix docs * Fix empty lines * small Fix * Add heading provider * created menu * remove borderline * Add mobilemenu component * add next env * update code style * generate heading element positions * Add package pages * add fetch packages * Add lucide logo * Add icons and adjust description * improve some things * fix types * Fix logo types * fix types * Add logo's * update packages docs * resize icons * small changes * update packages links
57 lines
1.5 KiB
TypeScript
57 lines
1.5 KiB
TypeScript
import { promises as fs } from 'fs';
|
|
import { serialize } from 'next-mdx-remote/serialize'
|
|
import path from 'path';
|
|
import grayMatter from 'gray-matter'
|
|
|
|
export default async function fetchAllDocuments() {
|
|
const docsDir = path.resolve(process.cwd(), '../docs');
|
|
const fileNames = await (await fs.readdir(docsDir)).map(filename => ({filename, directory: docsDir}))
|
|
|
|
const mapDirectoryTree = async ({filename, directory}) => {
|
|
const filePath = path.join(directory, filename);
|
|
const fileStat = await fs.lstat(filePath);
|
|
|
|
if(fileStat.isDirectory()) {
|
|
const filenamesInDirectory =
|
|
(await fs.readdir(filePath))
|
|
.map(childFileName => ({
|
|
directory: filePath,
|
|
directoryName: filename,
|
|
filename: childFileName
|
|
}))
|
|
|
|
return await Promise.all(filenamesInDirectory.map(mapDirectoryTree))
|
|
}
|
|
|
|
if (!fileStat.isFile()) return null;
|
|
|
|
return {
|
|
filePath,
|
|
filename,
|
|
}
|
|
}
|
|
|
|
const mapFileContents = async ({filename, filePath, directoryName = null}) => {
|
|
const source = await fs.readFile(filePath, 'utf-8');
|
|
|
|
const { content, data } = grayMatter(source)
|
|
const doc = await serialize(content)
|
|
|
|
return {
|
|
filename,
|
|
directoryName,
|
|
doc,
|
|
data,
|
|
content
|
|
}
|
|
}
|
|
|
|
const mappedDirectoryTree = (await Promise.all(fileNames.map(mapDirectoryTree))).flat().filter(({filename}) => filename.endsWith('.md'))
|
|
const mappedFileContents = await Promise.all(
|
|
mappedDirectoryTree
|
|
.map(mapFileContents)
|
|
)
|
|
|
|
return mappedFileContents
|
|
}
|