mirror of
https://github.com/anomalyco/opencode.git
synced 2026-11-16 05:01:03 +03:00
fix(www): scroll wide docs tables and label the docs search (#56592)
This commit is contained in:
committed by
GitHub
Unverified
parent
a1246889a9
commit
e4b2afcf0c
@@ -3,6 +3,7 @@ import mdx from "@astrojs/mdx"
|
||||
import { unified } from "@astrojs/markdown-remark"
|
||||
import { defineConfig } from "astro/config"
|
||||
import remarkDocsLinks from "./src/docs/remark-links"
|
||||
import rehypeTableScroll from "./src/docs/rehype-table-scroll"
|
||||
|
||||
const base = "/v2/"
|
||||
|
||||
@@ -13,7 +14,7 @@ export default defineConfig({
|
||||
adapter: cloudflare({ imageService: "passthrough" }),
|
||||
integrations: [mdx()],
|
||||
markdown: {
|
||||
processor: unified({ remarkPlugins: [[remarkDocsLinks, { base }]] }),
|
||||
processor: unified({ remarkPlugins: [[remarkDocsLinks, { base }]], rehypePlugins: [rehypeTableScroll] }),
|
||||
shikiConfig: {
|
||||
themes: {
|
||||
light: "github-light",
|
||||
|
||||
@@ -48,7 +48,7 @@ const searchEnabled = import.meta.env.PROD
|
||||
>
|
||||
<form method="dialog" class="search-bar">
|
||||
<span aria-hidden="true">></span>
|
||||
<input data-search-input type="search" placeholder="Search docs" autocomplete="off" />
|
||||
<input data-search-input type="search" placeholder="Search docs" aria-label="Search docs" autocomplete="off" />
|
||||
<button type="submit" aria-label="Close search">Esc</button>
|
||||
</form>
|
||||
<div class="search-results" data-search-results>
|
||||
|
||||
@@ -0,0 +1,41 @@
|
||||
interface HastNode {
|
||||
type: string
|
||||
tagName?: string
|
||||
properties?: Record<string, unknown>
|
||||
attributes?: { name?: string; value?: unknown }[]
|
||||
children?: HastNode[]
|
||||
}
|
||||
|
||||
// Wide Markdown tables would otherwise widen the whole page on small screens.
|
||||
export default function rehypeTableScroll() {
|
||||
return (tree: HastNode) => {
|
||||
const visit = (node: HastNode) => {
|
||||
if (isScroller(node)) return
|
||||
node.children = node.children?.map((child) =>
|
||||
child.type === "element" && child.tagName === "table"
|
||||
? {
|
||||
type: "element",
|
||||
tagName: "div",
|
||||
properties: { className: ["docs-table-scroll"], tabIndex: 0 },
|
||||
children: [child],
|
||||
}
|
||||
: child,
|
||||
)
|
||||
node.children?.forEach(visit)
|
||||
}
|
||||
|
||||
visit(tree)
|
||||
}
|
||||
}
|
||||
|
||||
// Some pages already wrap tables by hand in an MDX `<div class="docs-table-scroll">`.
|
||||
function isScroller(node: HastNode) {
|
||||
const className = node.properties?.className
|
||||
if (Array.isArray(className) && className.includes("docs-table-scroll")) return true
|
||||
return !!node.attributes?.some(
|
||||
(attribute) =>
|
||||
(attribute.name === "class" || attribute.name === "className") &&
|
||||
typeof attribute.value === "string" &&
|
||||
attribute.value.split(/\s+/).includes("docs-table-scroll"),
|
||||
)
|
||||
}
|
||||
Reference in New Issue
Block a user