2024-07-12 12:49:56 +08:00
|
|
|
mport fs from "node:fs/promises";
|
2024-07-11 12:33:19 +08:00
|
|
|
import path from "node:path";
|
|
|
|
|
2024-07-10 11:00:11 +08:00
|
|
|
export async function fetchNewsData(id: string) {
|
2024-07-11 12:33:19 +08:00
|
|
|
try {
|
|
|
|
const dataDirectory = path.join(process.cwd(), "public", "data");
|
|
|
|
const filePath = path.join(dataDirectory, `${id}.json`);
|
|
|
|
const fileContents = await fs.readFile(filePath, "utf8");
|
|
|
|
return JSON.parse(fileContents);
|
|
|
|
} catch (error) {
|
|
|
|
console.error("Error reading news data:", error);
|
2024-07-10 11:00:11 +08:00
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|