Skip to content

Commit

Permalink
debug with path reference
Browse files Browse the repository at this point in the history
  • Loading branch information
nofurtherinformation committed Apr 11, 2024
1 parent 665ddf7 commit 100ea15
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 27 deletions.
9 changes: 7 additions & 2 deletions app/county/[county]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,13 @@ const CountyPage: React.FC<CountyRouteProps> = 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<CountyDataMap>(countyDataPath, county)

return (
Expand Down
15 changes: 0 additions & 15 deletions hooks/useMdxContent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,21 +23,6 @@ export const getMdxContent = async <T extends any>(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 = {
Expand Down
25 changes: 15 additions & 10 deletions utils/data/summaryStats.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,22 @@
"use server"
import { UnpackrStream } from "msgpackr"
import fs from "fs"

export const getSummaryStats = async <T extends any>(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 {}
}
}

0 comments on commit 100ea15

Please sign in to comment.