168685d988
* docs: convert Copy page button to dropdown menu with Open markdown and Edit page options * docs: fix button border highlight and add page footer with actions - Fix split-button hover: highlight entire button group (both main button and chevron) when hovering any part of the group, using .page-actions:hover parent selector - Add PageFooter component with horizontal layout showing Copy page, Open markdown, and Edit page actions at the bottom of every docs page - Footer uses same API endpoints (raw-markdown, resolve-path) and GitHub URL construction as the dropdown button * fix: remove flex class from article-content to fix PageFooter layout The article-content div had Tailwind's 'flex' class which set display:flex with default row direction. The 'column' class was not a valid Tailwind utility (should be 'flex-col'), so the PageFooter rendered to the right of page content instead of below it. Removing 'flex column' restores block layout so children stack vertically. --------- Co-authored-by: kiloconnect[bot] <240665456+kiloconnect[bot]@users.noreply.github.com>
37 lines
1.3 KiB
TypeScript
37 lines
1.3 KiB
TypeScript
import type { NextApiRequest, NextApiResponse } from "next"
|
|
import fs from "fs"
|
|
import path from "path"
|
|
|
|
export default async function handler(req: NextApiRequest, res: NextApiResponse) {
|
|
if (req.method !== "GET") {
|
|
return res.status(405).json({ error: "Method not allowed" })
|
|
}
|
|
|
|
const { path: mdPath } = req.query
|
|
|
|
if (!mdPath || typeof mdPath !== "string") {
|
|
return res.status(400).json({ error: "Missing path parameter" })
|
|
}
|
|
|
|
const sanitizedPath = path.normalize(mdPath).replace(/^\/+/, "")
|
|
const pagesDir = path.join(process.cwd(), "pages")
|
|
const resolvedPagesDir = path.resolve(pagesDir)
|
|
|
|
const candidatePath = path.resolve(pagesDir, `${sanitizedPath}.md`)
|
|
const candidateIndexPath = path.resolve(pagesDir, sanitizedPath, "index.md")
|
|
|
|
if (!candidatePath.startsWith(resolvedPagesDir) || !candidateIndexPath.startsWith(resolvedPagesDir)) {
|
|
return res.status(403).json({ error: "Access denied" })
|
|
}
|
|
|
|
if (fs.existsSync(candidatePath)) {
|
|
return res.status(200).json({ filePath: `packages/kilo-docs/pages/${sanitizedPath}.md` })
|
|
}
|
|
|
|
if (fs.existsSync(candidateIndexPath)) {
|
|
return res.status(200).json({ filePath: `packages/kilo-docs/pages/${sanitizedPath}/index.md` })
|
|
}
|
|
|
|
return res.status(404).json({ error: "File not found" })
|
|
}
|