Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions pcweb/markdown_api.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
"""Write per-doc raw Markdown files under ``.web/public`` for ``<route>.md`` URLs."""

from pathlib import Path

from reflex.constants import Dirs

from pcweb.pages.docs import doc_markdown_sources

PUBLIC_DIR = Path.cwd() / Dirs.WEB / Dirs.PUBLIC


def generate_markdown_files() -> None:
for route, source_path in doc_markdown_sources.items():
resolved = Path(source_path)
if not resolved.is_absolute():
resolved = Path.cwd() / resolved
if not resolved.is_file():
continue

dest = PUBLIC_DIR / (route.strip("/") + ".md")
dest.parent.mkdir(parents=True, exist_ok=True)
dest.write_text(resolved.read_text(encoding="utf-8"), encoding="utf-8")
17 changes: 17 additions & 0 deletions pcweb/pages/docs/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,8 @@ def get_components_from_metadata(current_doc):
recipes_list = defaultdict(list)
docs_ns = SimpleNamespace()

doc_markdown_sources: dict[str, str] = {}


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


for fd in flexdown_docs:
if fd.endswith("-style.md") or fd.endswith("-ll.md"):
continue
route = doc_route_from_path(fd)
if not _check_whitelisted_path(route):
continue
doc_markdown_sources[route] = doc_path_mapping.get(fd, fd)
for virtual_doc, actual_path in docgen_docs.items():
if virtual_doc.endswith("-style.md") or virtual_doc.endswith("-ll.md"):
continue
route = doc_route_from_path(virtual_doc)
if not _check_whitelisted_path(route):
continue
doc_markdown_sources[route] = actual_path

doc_routes = [
library,
custom_components,
Expand Down
3 changes: 3 additions & 0 deletions pcweb/pcweb.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

from pcweb import styles
from pcweb.constants import REFLEX_ASSETS_CDN
from pcweb.markdown_api import generate_markdown_files
from pcweb.meta.meta import favicons_links, to_cdn_image_url
from pcweb.pages import page404, routes
from pcweb.pages.docs import exec_blocks, outblocks
Expand All @@ -22,6 +23,8 @@
for doc, href in outblocks:
exec_blocks(doc, href)

generate_markdown_files()

# Create the app.
app = rxe.App(
style=styles.BASE_STYLE,
Expand Down
Loading