Skip to content

Commit 4c53848

Browse files
authored
ENG-9295: add docs llms.txt (#6327)
1 parent e05eb8f commit 4c53848

File tree

5 files changed

+64
-25
lines changed

5 files changed

+64
-25
lines changed

docs/app/agent_files/__init__.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
from ._plugin import AgentFilesPlugin
2+
3+
__all__ = ["AgentFilesPlugin"]

docs/app/agent_files/_plugin.py

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
from collections.abc import Sequence
2+
from pathlib import Path, PosixPath
3+
4+
from reflex.constants import Dirs
5+
from reflex_base.plugins import CommonContext, Plugin
6+
from typing_extensions import Unpack
7+
8+
9+
def generate_markdown_files() -> tuple[tuple[Path, str | bytes], ...]:
10+
from reflex_docs.pages.docs import doc_markdown_sources
11+
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+
)
19+
20+
21+
def generate_llms_txt(
22+
markdown_files: Sequence[tuple[Path, str | bytes]],
23+
) -> tuple[Path, str]:
24+
from reflex_base.config import get_config
25+
26+
config = get_config()
27+
28+
if deploy_url := config.deploy_url:
29+
deploy_url = config.deploy_url.removesuffix("/")
30+
else:
31+
deploy_url = ""
32+
33+
return (
34+
Path("docs") / "llms.txt",
35+
"# Reflex\n\n"
36+
+ "## Docs\n\n"
37+
+ "\n".join(
38+
f"- [{deploy_url}/{url}]({deploy_url}/{url})" for url, _ in markdown_files
39+
),
40+
)
41+
42+
43+
def generate_agent_files() -> tuple[tuple[Path, str | bytes], ...]:
44+
markdown_files = generate_markdown_files()
45+
return (*markdown_files, generate_llms_txt(markdown_files))
46+
47+
48+
class AgentFilesPlugin(Plugin):
49+
def get_static_assets(
50+
self, **context: Unpack[CommonContext]
51+
) -> Sequence[tuple[Path, str | bytes]]:
52+
return [
53+
(Dirs.PUBLIC / path, content) for path, content in generate_agent_files()
54+
]

docs/app/reflex_docs/pages/docs/markdown_api.py

Lines changed: 0 additions & 22 deletions
This file was deleted.

docs/app/reflex_docs/reflex_docs.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,12 @@
1212
from reflex_ui_shared.telemetry import get_pixel_website_trackers
1313

1414
from reflex_docs.pages import page404, routes
15-
from reflex_docs.pages.docs.markdown_api import generate_markdown_files
1615
from reflex_docs.whitelist import _check_whitelisted_path
1716

1817
# This number discovered by trial and error on Windows 11 w/ Node 18, any
1918
# higher and the prod build fails with EMFILE error.
2019
WINDOWS_MAX_ROUTES = int(os.environ.get("REFLEX_WEB_WINDOWS_MAX_ROUTES", "100"))
2120

22-
generate_markdown_files()
2321
# Create the app.
2422
app = rxe.App(
2523
style=styles.BASE_STYLE,

docs/app/rxconfig.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,17 @@
11
import reflex as rx
22

3+
from agent_files import AgentFilesPlugin
4+
35
config = rx.Config(
46
app_name="reflex_docs",
57
deploy_url="https://reflex.dev",
68
frontend_packages=[
79
"tailwindcss-animated",
810
],
911
telemetry_enabled=False,
10-
plugins=[rx.plugins.TailwindV4Plugin(), rx.plugins.SitemapPlugin()],
12+
plugins=[
13+
rx.plugins.TailwindV4Plugin(),
14+
rx.plugins.SitemapPlugin(),
15+
AgentFilesPlugin(),
16+
],
1117
)

0 commit comments

Comments
 (0)