From 100ea15dda8c0d03ec69ad4611d1f61c73b0cb72 Mon Sep 17 00:00:00 2001 From: nofurtherinformation Date: Thu, 11 Apr 2024 16:05:56 -0500 Subject: [PATCH] debug with path reference --- app/county/[county]/page.tsx | 9 +++++++-- hooks/useMdxContent.ts | 15 --------------- utils/data/summaryStats.ts | 25 +++++++++++++++---------- 3 files changed, 22 insertions(+), 27 deletions(-) diff --git a/app/county/[county]/page.tsx b/app/county/[county]/page.tsx index eae48fb..44908e9 100644 --- a/app/county/[county]/page.tsx +++ b/app/county/[county]/page.tsx @@ -42,8 +42,13 @@ const CountyPage: React.FC = async ({ params }) => { const contentPath = path.join(process.cwd(), "content", `page`) console.log(contentPath) // fs read files in contentPath - const files = fs.readdirSync(contentPath) - console.log(files) + try { + const files = fs.readdirSync(contentPath) + console.log(files) + } catch (error) { + console.log(error) + } + const countyStats = await getSummaryStats(countyDataPath, county) return ( diff --git a/hooks/useMdxContent.ts b/hooks/useMdxContent.ts index 769710c..33e715c 100644 --- a/hooks/useMdxContent.ts +++ b/hooks/useMdxContent.ts @@ -23,21 +23,6 @@ export const getMdxContent = async (contentType: keyof typeof cli return r } else { const filepath = path.join(process.cwd(), 'content', contentType, relativePath) - // log dirs in current dirxx - const dirs = fs.readdirSync(path.join(process.cwd())) - console.log('dirs', dirs) - // if (dirs.includes('public')) { - // const publicDirs = fs.readdirSync(path.join(process.cwd(), 'public')) - // console.log('publicDirs', publicDirs) - // if (publicDirs.includes('content')) { - // const contentDirs = fs.readdirSync(path.join(process.cwd(), 'public', 'content')) - // console.log('contentDirs', contentDirs) - // if (contentDirs.includes(contentType)) { - // const typeDirs = fs.readdirSync(path.join(process.cwd(), 'public', 'content', contentType)) - // console.log('typeDirs', typeDirs) - // } - // } - // } const mdxContent = fs.readFileSync(filepath, 'utf-8') const frontMatter = matter(mdxContent) const data: any = { diff --git a/utils/data/summaryStats.ts b/utils/data/summaryStats.ts index 2ef5277..2682ca5 100644 --- a/utils/data/summaryStats.ts +++ b/utils/data/summaryStats.ts @@ -1,17 +1,22 @@ -"use server" import { UnpackrStream } from "msgpackr" import fs from "fs" export const getSummaryStats = async (filepath: string, id: string) => { - const stream = fs.createReadStream(filepath) - const unpackr = new UnpackrStream() - stream.pipe(unpackr) + try { + const stream = fs.createReadStream(filepath) + const unpackr = new UnpackrStream() + stream.pipe(unpackr) - for await (const data of unpackr) { - const d = data.get(id) - if (d) { - return d as T + for await (const data of unpackr) { + const d = data.get(id) + if (d) { + return d as T + } } + return new Map() + } catch (error) { + console.log("Error getting messagepack data") + console.log(error) + return new Map() } - return {} -} \ No newline at end of file +}