-
-
Notifications
You must be signed in to change notification settings - Fork 257
Show deprecation reason message in API docs #1328
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -31,6 +31,51 @@ let rec rawApiItemToNode = (apiItem: apiItem): ApiDocs.node => { | |
| @scope("JSON") @val | ||
| external parseApi: string => Dict.t<apiItem> = "parse" | ||
|
|
||
| type apiRequestPath = { | ||
| version: string, | ||
| slug: array<string>, | ||
| } | ||
|
|
||
| let normalizeVersion = version => | ||
| switch version { | ||
| | "latest" => Constants.versions.latest | ||
| | "next" => Constants.versions.next | ||
| | version => version | ||
| } | ||
|
|
||
| let isVersionSegment = segment => | ||
| segment === "latest" || segment === "next" || segment->Semver.parse->Option.isSome | ||
|
|
||
| let getApiRequestPath = (pathname: string): apiRequestPath => { | ||
| let segments = pathname->String.split("/")->Array.filter(segment => segment !== "") | ||
| let apiIndex = segments->Array.findIndex(segment => segment === "api") | ||
|
|
||
| let version = switch apiIndex { | ||
| | -1 => Constants.versions.latest | ||
| | index => | ||
| switch segments->Array.get(index - 1) { | ||
| | Some(segment) if segment->isVersionSegment => segment->normalizeVersion | ||
| | _ => Constants.versions.latest | ||
| } | ||
| } | ||
|
|
||
| let slug = switch apiIndex { | ||
| | -1 => [] | ||
| | index => segments->Array.slice(~start=index + 1) | ||
| } | ||
|
|
||
| {version, slug} | ||
| } | ||
|
|
||
| let getApiModuleName = slug => | ||
| switch slug->Array.get(0) { | ||
| | Some("belt") => "belt" | ||
| | Some("dom") => "dom" | ||
| | Some("js") => "js" | ||
| | Some("stdlib") => "stdlib" | ||
| | _ => "stdlib" | ||
| } | ||
|
|
||
| let groupItems = apiDocs => { | ||
| let parsedItems = | ||
| apiDocs | ||
|
|
@@ -122,26 +167,21 @@ let makeBreadcrumbs = (~prefix: Url.breadcrumb, route: Path.t): list<Url.breadcr | |
| } | ||
|
|
||
| let loader: ReactRouter.Loader.t<loaderData> = async args => { | ||
| let path = | ||
| WebAPI.URL.make(~url=args.request.url).pathname | ||
| ->String.replace("/docs/manual/api/", "") | ||
| ->String.split("/") | ||
| let {pathname} = WebAPI.URL.make(~url=args.request.url) | ||
| let apiRequestPath = getApiRequestPath((pathname :> string)) | ||
| let version = apiRequestPath.version | ||
| let path = apiRequestPath.slug | ||
| let basePath = path->getApiModuleName | ||
|
|
||
| let basePath = path[0]->Option.getUnsafe | ||
|
|
||
| let apiDocs = switch basePath { | ||
| | "belt" => parseApi(await Node.Fs.readFile("./markdown-pages/docs/api/belt.json", "utf-8")) | ||
| | "dom" => parseApi(await Node.Fs.readFile("./markdown-pages/docs/api/dom.json", "utf-8")) | ||
| | _ => parseApi(await Node.Fs.readFile("./markdown-pages/docs/api/stdlib.json", "utf-8")) | ||
| } | ||
| let apiDocs = parseApi(await Node.Fs.readFile(`data/api/${version}/${basePath}.json`, "utf-8")) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
When v13 becomes the selected documentation version, new modules in this dataset remain unreachable: this commit adds AGENTS.md reference: AGENTS.md:L5-L5 Useful? React with 👍 / 👎. |
||
|
|
||
| let toctree = groupItems(apiDocs) | ||
|
|
||
| let data = { | ||
| // TODO POST RR7: refactor this function to only return the module and not the toctree | ||
| // or move the toc logic to this function | ||
| try { | ||
| await ApiDocs.getStaticProps(path) | ||
| await ApiDocs.getStaticProps(~version, path) | ||
| } catch { | ||
| | err => {"props": Error(JSON.stringifyAny(err)->Option.getOr("Error loading API data"))} | ||
| } | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When a browser loads an API route,
ApiRoute.defaultimports this module to render<ApiDocs>, so this top-levelreaddirSyncis evaluated outside the loader. In thisssr: falseapp the browser has no Nodefs; unlike the previous implementation, which deferred the filesystem read untilgetVersionand guarded its top-level path lookup, this can make the API bundle throw before rendering. Enumerate the versions inside the loader-only path instead.AGENTS.md reference: AGENTS.md:L101-L104
Useful? React with 👍 / 👎.