Skip to content

Commit 532e155

Browse files
authored
ENG-9274: .md endpoints for all docs pages (#1806)
* init * updates * bump
1 parent 225789e commit 532e155

File tree

3 files changed

+42
-0
lines changed

3 files changed

+42
-0
lines changed

pcweb/markdown_api.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
"""Write per-doc raw Markdown files under ``.web/public`` for ``<route>.md`` URLs."""
2+
3+
from pathlib import Path
4+
5+
from reflex.constants import Dirs
6+
7+
from pcweb.pages.docs import doc_markdown_sources
8+
9+
PUBLIC_DIR = Path.cwd() / Dirs.WEB / Dirs.PUBLIC
10+
11+
12+
def generate_markdown_files() -> None:
13+
for route, source_path in doc_markdown_sources.items():
14+
resolved = Path(source_path)
15+
if not resolved.is_absolute():
16+
resolved = Path.cwd() / resolved
17+
if not resolved.is_file():
18+
continue
19+
20+
dest = PUBLIC_DIR / (route.strip("/") + ".md")
21+
dest.parent.mkdir(parents=True, exist_ok=True)
22+
dest.write_text(resolved.read_text(encoding="utf-8"), encoding="utf-8")

pcweb/pages/docs/__init__.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,8 @@ def get_components_from_metadata(current_doc):
132132
recipes_list = defaultdict(list)
133133
docs_ns = SimpleNamespace()
134134

135+
doc_markdown_sources: dict[str, str] = {}
136+
135137

136138
def exec_blocks(doc, href):
137139
"""Execute the exec and demo blocks in the document."""
@@ -283,6 +285,21 @@ def comp(_actual=actual_path, _virtual=virtual_doc):
283285
return make_docpage(resolved.route, resolved.display_title, virtual_doc, comp)
284286

285287

288+
for fd in flexdown_docs:
289+
if fd.endswith("-style.md") or fd.endswith("-ll.md"):
290+
continue
291+
route = doc_route_from_path(fd)
292+
if not _check_whitelisted_path(route):
293+
continue
294+
doc_markdown_sources[route] = doc_path_mapping.get(fd, fd)
295+
for virtual_doc, actual_path in docgen_docs.items():
296+
if virtual_doc.endswith("-style.md") or virtual_doc.endswith("-ll.md"):
297+
continue
298+
route = doc_route_from_path(virtual_doc)
299+
if not _check_whitelisted_path(route):
300+
continue
301+
doc_markdown_sources[route] = actual_path
302+
286303
doc_routes = [
287304
library,
288305
custom_components,

pcweb/pcweb.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
from pcweb import styles
1010
from pcweb.constants import REFLEX_ASSETS_CDN
11+
from pcweb.markdown_api import generate_markdown_files
1112
from pcweb.meta.meta import favicons_links, to_cdn_image_url
1213
from pcweb.pages import page404, routes
1314
from pcweb.pages.docs import exec_blocks, outblocks
@@ -22,6 +23,8 @@
2223
for doc, href in outblocks:
2324
exec_blocks(doc, href)
2425

26+
generate_markdown_files()
27+
2528
# Create the app.
2629
app = rxe.App(
2730
style=styles.BASE_STYLE,

0 commit comments

Comments
 (0)