Generate post toc on build time

This commit is contained in:
DefectingCat
2022-08-19 10:50:02 +08:00
parent 03d6fd1a0f
commit f6cb2a8f74
7 changed files with 114 additions and 75 deletions

View File

@ -4,17 +4,19 @@ import fs from 'fs';
import path from 'path';
import { nanoid } from 'nanoid';
const dataPath = 'data/posts';
/**
* Build post information for Algolia search.
* @param filename
* @returns
*/
const postLists = () => {
const files = fs.readdirSync(path.join('pages/p'));
const files = fs.readdirSync(path.join(dataPath));
const myPosts = [];
files.map((f) => {
const content = fs.readFileSync(path.join('pages/p', f), 'utf-8');
const content = fs.readFileSync(path.join(dataPath, f), 'utf-8');
// const { data: meta, content } = matter(markdownWithMeta);
const slug = f.replace(/\.mdx$/, '');