// lib/glossary.ts
import fs from 'fs';
import path from 'path';

const glossaryPath = path.join(process.cwd(), 'content/glossary');

export function getAllGlossarySlugs() {
  return fs.readdirSync(glossaryPath)
    .map((file) => file.replace(/\.(md|html)$/, ''));
}

export function getGlossaryContent(slug: string) {
  const fullPath = path.join(glossaryPath, `${slug}`);
  const mdFile = `${fullPath}.md`;
  const htmlFile = `${fullPath}.html`;

  if (fs.existsSync(mdFile)) {
    return { type: 'md', content: fs.readFileSync(mdFile, 'utf8') };
  } else if (fs.existsSync(htmlFile)) {
    return { type: 'html', content: fs.readFileSync(htmlFile, 'utf8') };
  } else {
    return null;
  }
}
