---
import { getCollection, render } from "astro:content";
import DocsLayout from "../../layouts/DocsLayout.astro";

export async function getStaticPaths() {
  // Internal governance drafts that should not appear on the public site.
  const HIDDEN_DOCS = new Set(["board-resolution-draft"]);
  const docs = await getCollection("docs");
  return docs
    .filter((entry) => !HIDDEN_DOCS.has(entry.id.replace(/\.md$/, "")))
    .map((entry) => ({
      params: { slug: entry.id.replace(/\.md$/, "") },
      props: { entry },
    }));
}

const { entry } = Astro.props;
const { Content } = await render(entry);
const title = entry.data.title ?? entry.id.split("/").pop()?.replace(/\.md$/, "").replace(/-/g, " ");
// Docs markdown is synced from apache/magpie/docs — edits go to that repo.
// Use filePath (preserves original name + case, e.g. README.md) rather than
// entry.id, which the glob loader lowercases and strips the extension from.
const docRelPath = entry.filePath
  ? entry.filePath.replace(/^.*\/content\/docs\//, "")
  : `${entry.id.replace(/\.md$/, "")}.md`;
const editUrl = `https://github.com/apache/magpie/edit/main/docs/${docRelPath}`;
---

<DocsLayout title={title} currentSlug={entry.id.replace(/\.md$/, "")} editUrl={editUrl}>
  <Content />
</DocsLayout>
