[learn-example][sm] - dont panic when no markdown.db file found
This commit is contained in:
@@ -1,4 +1,4 @@
|
|||||||
import { promises as fs } from 'fs';
|
import { existsSync, promises as fs } from 'fs';
|
||||||
import path from 'path';
|
import path from 'path';
|
||||||
import parse from '../lib/markdown';
|
import parse from '../lib/markdown';
|
||||||
import DRD from '../components/DRD';
|
import DRD from '../components/DRD';
|
||||||
@@ -24,11 +24,14 @@ export const getStaticProps = async (context) => {
|
|||||||
pathToFile = context.params.path.join('/') + '/index.md';
|
pathToFile = context.params.path.join('/') + '/index.md';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let datasets = [];
|
||||||
|
const mddbFileExists = existsSync('markdown.db');
|
||||||
|
if (mddbFileExists) {
|
||||||
const mddb = await clientPromise;
|
const mddb = await clientPromise;
|
||||||
const datasetsFiles = await mddb.getFiles({
|
const datasetsFiles = await mddb.getFiles({
|
||||||
extensions: ['md', 'mdx'],
|
extensions: ['md', 'mdx'],
|
||||||
});
|
});
|
||||||
const datasets = datasetsFiles
|
datasets = datasetsFiles
|
||||||
.filter((dataset) => dataset.url_path !== '/')
|
.filter((dataset) => dataset.url_path !== '/')
|
||||||
.map((dataset) => ({
|
.map((dataset) => ({
|
||||||
_id: dataset._id,
|
_id: dataset._id,
|
||||||
@@ -36,6 +39,7 @@ export const getStaticProps = async (context) => {
|
|||||||
file_path: dataset.file_path,
|
file_path: dataset.file_path,
|
||||||
metadata: dataset.metadata,
|
metadata: dataset.metadata,
|
||||||
}));
|
}));
|
||||||
|
}
|
||||||
|
|
||||||
const indexFile = path.join(process.cwd(), '/content/' + pathToFile);
|
const indexFile = path.join(process.cwd(), '/content/' + pathToFile);
|
||||||
const readme = await fs.readFile(indexFile, 'utf8');
|
const readme = await fs.readFile(indexFile, 'utf8');
|
||||||
|
|||||||
Reference in New Issue
Block a user