MCPcopy Create free account
hub / github.com/Openpanel-dev/openpanel / loadCompareSource

Function loadCompareSource

apps/public/src/lib/source.ts:66–97  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

64const contentDir = path.join(__dirname, '../../content/compare');
65
66function loadCompareSource(): CompareData[] {
67 try {
68 // Check if directory exists before trying to read it
69 if (!fs.existsSync(contentDir)) {
70 return [];
71 }
72
73 const files = fs
74 .readdirSync(contentDir)
75 .filter((file) => file.endsWith('.json'));
76
77 return files
78 .map((file) => {
79 const filePath = path.join(contentDir, file);
80 const fileContents = fs.readFileSync(filePath, 'utf8');
81 try {
82 return JSON.parse(fileContents) as CompareData;
83 } catch (error) {
84 console.error(`Error parsing compare data for ${file}:`, error);
85 return null;
86 }
87 })
88 .flatMap((item) => (item ? [item] : []))
89 .map((item) => ({
90 ...item,
91 url: `/compare/${item.slug}`,
92 }));
93 } catch (error) {
94 console.error('Error loading compare source:', error);
95 return [];
96 }
97}
98
99export const compareSource: CompareData[] = loadCompareSource();
100

Callers 1

source.tsFile · 0.85

Calls 4

joinMethod · 0.80
parseMethod · 0.80
mapMethod · 0.45
errorMethod · 0.45

Tested by

no test coverage detected