Skip to content

Commit 0b4dae6

Browse files
Tom GotsmanTom Gotsman
authored andcommitted
improve-select-docs
1 parent d3d5bfb commit 0b4dae6

11 files changed

Lines changed: 355 additions & 153 deletions

File tree

docs/app/.python-version

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
3.13

docs/app/agent_files/_plugin.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,13 @@
99
def generate_markdown_files() -> tuple[tuple[Path, str | bytes], ...]:
1010
from reflex_docs.pages.docs import doc_markdown_sources
1111

12-
return tuple([
13-
(PosixPath(route.strip("/") + ".md"), resolved.read_bytes())
14-
for route, source_path in doc_markdown_sources.items()
15-
if (resolved := Path(source_path)).is_file()
16-
])
12+
return tuple(
13+
[
14+
(PosixPath(route.strip("/") + ".md"), resolved.read_bytes())
15+
for route, source_path in doc_markdown_sources.items()
16+
if (resolved := Path(source_path)).is_file()
17+
]
18+
)
1719

1820

1921
def generate_llms_txt(

docs/app/reflex_docs/pages/docs/__init__.py

Lines changed: 33 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,13 @@
1111
from reflex_site_shared.route import Route
1212

1313
from reflex_docs.docgen_pipeline import get_docgen_toc, render_docgen_document
14-
from reflex_docs.pages.docs.component import multi_docs
14+
from reflex_docs.pages.docs.component import (
15+
get_related_from_frontmatter,
16+
get_seo_from_frontmatter,
17+
multi_docs,
18+
related_links_footer,
19+
seo_kwargs,
20+
)
1521
from reflex_docs.pages.library_previews import components_previews_pages
1622
from reflex_docs.templates.docpage import docpage
1723
from reflex_docs.whitelist import _check_whitelisted_path
@@ -182,13 +188,21 @@ def resolve_doc_route(doc: str, title: str) -> ResolvedDoc | None:
182188
return ResolvedDoc(route=route, display_title=display_title, category=category)
183189

184190

185-
def make_docpage(route: str, title: str, doc_virtual: str, render_fn):
186-
"""Wrap a render function as a docpage, setting module metadata."""
191+
def make_docpage(route: str, title: str, doc_virtual: str, render_fn, **docpage_kwargs):
192+
"""Wrap a render function as a docpage, setting module metadata.
193+
194+
Args:
195+
route: The site route for this page.
196+
title: The page title.
197+
doc_virtual: The virtual path used for module metadata.
198+
render_fn: The function that returns the page component.
199+
**docpage_kwargs: Extra keyword args forwarded to ``docpage`` (SEO, etc.).
200+
"""
187201
doc_path = Path(doc_virtual)
188202
render_fn.__module__ = ".".join(doc_path.parts[:-1])
189203
render_fn.__name__ = doc_path.stem
190204
render_fn.__qualname__ = doc_path.stem
191-
return docpage(set_path=route, t=title)(render_fn)
205+
return docpage(set_path=route, t=title, **docpage_kwargs)(render_fn)
192206

193207

194208
def handle_library_doc(
@@ -223,15 +237,27 @@ def get_component_docgen(virtual_doc: str, actual_path: str, title: str):
223237
if virtual_doc.startswith("docs/library"):
224238
return handle_library_doc(virtual_doc, actual_path, title, resolved)
225239

226-
def comp(_actual=actual_path, _virtual=virtual_doc):
240+
seo = get_seo_from_frontmatter(actual_path)
241+
related = get_related_from_frontmatter(actual_path)
242+
seo_extras = seo_kwargs(seo, resolved.display_title, resolved.route)
243+
244+
def comp(_actual=actual_path, _virtual=virtual_doc, _related=related):
227245
toc = get_docgen_toc(_actual)
228246
doc_content = Path(_actual).read_text(encoding="utf-8")
229247
rendered = render_docgen_document(
230248
virtual_filepath=_virtual, actual_filepath=_actual
231249
)
232-
return ((toc, doc_content), rendered)
250+
footer = related_links_footer(_related)
251+
body = (
252+
rx.box(rendered, footer, class_name="flex flex-col w-full")
253+
if _related is not None
254+
else rendered
255+
)
256+
return ((toc, doc_content), body)
233257

234-
return make_docpage(resolved.route, resolved.display_title, virtual_doc, comp)
258+
return make_docpage(
259+
resolved.route, resolved.display_title, virtual_doc, comp, **seo_extras
260+
)
235261

236262

237263
# Build doc_markdown_sources mapping

docs/app/reflex_docs/pages/docs/cloud_cliref.py

Lines changed: 72 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -177,74 +177,83 @@ def process(
177177
"""Convert a Click command to a Markdown element."""
178178
actual_name = override_name or command["name"]
179179
full_name = prefix + " " + actual_name if prefix and actual_name else actual_name
180-
cli_to_doc[full_name] = Section((
181-
Paragraph(InlineText(command["help"])) if command["help"] else Empty(),
182-
Section((
183-
Header(3, InlineText("Usage")),
184-
CodeBlock(
185-
"$"
186-
+ (" " + prefix.strip() if prefix else "")
187-
+ " "
188-
+ actual_name.strip()
189-
+ (
190-
" [OPTIONS]"
191-
if command["params"]
192-
and any(
193-
param.get("param_type_name") != "argument"
194-
for param in command["params"]
195-
)
196-
else ""
197-
)
198-
+ (
199-
" " + " ".join(arguments)
200-
if (
201-
arguments := [
202-
param["name"].upper()
203-
for param in command["params"]
204-
if param.get("param_type_name") == "argument"
205-
and param["name"]
206-
]
207-
)
208-
else ""
209-
),
210-
language="console",
211-
),
212-
))
213-
if actual_name
214-
else Empty(),
215-
Section((
216-
Header(3, InlineText("Options")),
217-
List(
218-
tuple(
219-
InlineTextCollection((
220-
InlineCode(
221-
", ".join(param["opts"])
222-
+ (
223-
" / " + ", ".join(param["secondary_opts"])
224-
if param["secondary_opts"]
225-
else ""
180+
cli_to_doc[full_name] = Section(
181+
(
182+
Paragraph(InlineText(command["help"])) if command["help"] else Empty(),
183+
Section(
184+
(
185+
Header(3, InlineText("Usage")),
186+
CodeBlock(
187+
"$"
188+
+ (" " + prefix.strip() if prefix else "")
189+
+ " "
190+
+ actual_name.strip()
191+
+ (
192+
" [OPTIONS]"
193+
if command["params"]
194+
and any(
195+
param.get("param_type_name") != "argument"
196+
for param in command["params"]
226197
)
227-
+ (
198+
else ""
199+
)
200+
+ (
201+
" " + " ".join(arguments)
202+
if (
203+
arguments := [
204+
param["name"].upper()
205+
for param in command["params"]
206+
if param.get("param_type_name") == "argument"
207+
and param["name"]
208+
]
209+
)
210+
else ""
211+
),
212+
language="console",
213+
),
214+
)
215+
)
216+
if actual_name
217+
else Empty(),
218+
Section(
219+
(
220+
Header(3, InlineText("Options")),
221+
List(
222+
tuple(
223+
InlineTextCollection(
228224
(
229-
" " + param["type"]["name"].upper()
230-
if param["type"]["name"] != "boolean"
231-
else ""
225+
InlineCode(
226+
", ".join(param["opts"])
227+
+ (
228+
" / " + ", ".join(param["secondary_opts"])
229+
if param["secondary_opts"]
230+
else ""
231+
)
232+
+ (
233+
(
234+
" " + param["type"]["name"].upper()
235+
if param["type"]["name"] != "boolean"
236+
else ""
237+
)
238+
if (choices := param["type"].get("choices"))
239+
is None
240+
else " [" + "|".join(choices) + "]"
241+
)
242+
),
243+
InlineText(": " + option_help),
232244
)
233-
if (choices := param["type"].get("choices")) is None
234-
else " [" + "|".join(choices) + "]"
235245
)
246+
for param in command["params"]
247+
if (option_help := param.get("help")) is not None
236248
),
237-
InlineText(": " + option_help),
238-
))
239-
for param in command["params"]
240-
if (option_help := param.get("help")) is not None
241-
),
242-
ordered=False,
243-
),
244-
))
245-
if command["params"]
246-
else Empty(),
247-
)).into_text()
249+
ordered=False,
250+
),
251+
)
252+
)
253+
if command["params"]
254+
else Empty(),
255+
)
256+
).into_text()
248257
for name, sub_command in sort_subcommands(command.get("commands", {})).items():
249258
process(
250259
sub_command,

0 commit comments

Comments
 (0)