|
| 1 | +import React from "react"; |
| 2 | +import clsx from "clsx"; |
| 3 | +import { ThemeClassNames } from "@docusaurus/theme-common"; |
| 4 | +import { useDoc } from "@docusaurus/plugin-content-docs/client"; |
| 5 | +import Heading from "@theme/Heading"; |
| 6 | +import MDXContent from "@theme/MDXContent"; |
| 7 | +import TopSection from "@site/src/components/topSection"; |
| 8 | +import { useLocation } from "@docusaurus/router"; |
| 9 | +/** |
| 10 | + Title can be declared inside md content or declared through |
| 11 | + front matter and added manually. To make both cases consistent, |
| 12 | + the added title is added under the same div.markdown block |
| 13 | + See https://github.com/facebook/docusaurus/pull/4882#issuecomment-853021120 |
| 14 | +
|
| 15 | + We render a "synthetic title" if: |
| 16 | + - user doesn't ask to hide it with front matter |
| 17 | + - the markdown content does not already contain a top-level h1 heading |
| 18 | +*/ |
| 19 | +function useSyntheticTitle() { |
| 20 | + const { metadata, frontMatter, contentTitle } = useDoc(); |
| 21 | + const shouldRender = !frontMatter.hide_title && typeof contentTitle === "undefined"; |
| 22 | + if (!shouldRender) { |
| 23 | + return null; |
| 24 | + } |
| 25 | + return metadata.title; |
| 26 | +} |
| 27 | +export default function DocItemContent({ children }) { |
| 28 | + const { frontMatter } = useDoc(); |
| 29 | + const syntheticTitle = useSyntheticTitle(); |
| 30 | + const location = useLocation(); |
| 31 | + return ( |
| 32 | + <div className={clsx(ThemeClassNames.docs.docMarkdown, "markdown")}> |
| 33 | + {syntheticTitle && ( |
| 34 | + <header> |
| 35 | + <Heading as="h1">{syntheticTitle}</Heading> |
| 36 | + {(frontMatter.langSwitcher || frontMatter.dbSwitcher) && ( |
| 37 | + <section className="top-section"> |
| 38 | + <TopSection |
| 39 | + location={location} |
| 40 | + langSwitcher={frontMatter?.langSwitcher} |
| 41 | + dbSwitcher={frontMatter?.dbSwitcher} |
| 42 | + slug={frontMatter?.slugSwitch} |
| 43 | + /> |
| 44 | + </section> |
| 45 | + )} |
| 46 | + {frontMatter.completion_time && ( |
| 47 | + <div className="completion-time-wrapper"> |
| 48 | + <div className="completion-time-container">{frontMatter.completion_time}</div> |
| 49 | + </div> |
| 50 | + )} |
| 51 | + </header> |
| 52 | + )} |
| 53 | + <MDXContent> |
| 54 | + {children}{" "} |
| 55 | + {frontMatter.community_section && ( |
| 56 | + <div> |
| 57 | + <br /> |
| 58 | + <h2>Stay connected with Prisma</h2> |
| 59 | + <p> |
| 60 | + Continue your Prisma journey by connecting with{" "} |
| 61 | + <a href="https://www.prisma.io/community" target="_blank"> |
| 62 | + {" "} |
| 63 | + our active community |
| 64 | + </a> |
| 65 | + . Stay informed, get involved, and collaborate with other developers: |
| 66 | + <br /> |
| 67 | + <ul> |
| 68 | + <li> |
| 69 | + <a |
| 70 | + href="https://pris.ly/x?utm_source=docs&utm_medium=generated_text_cta" |
| 71 | + target="_blank" |
| 72 | + > |
| 73 | + Follow us on X |
| 74 | + </a>{" "} |
| 75 | + for announcements, live events and useful tips. |
| 76 | + </li> |
| 77 | + <li> |
| 78 | + <a |
| 79 | + href="https://pris.ly/discord?utm_source=docs&utm_medium=generated_text_cta" |
| 80 | + target="_blank" |
| 81 | + > |
| 82 | + Join our Discord |
| 83 | + </a>{" "} |
| 84 | + to ask questions, talk to the community, and get active support through |
| 85 | + conversations. |
| 86 | + </li> |
| 87 | + <li> |
| 88 | + <a |
| 89 | + href="https://pris.ly/youtube?utm_source=docs&utm_medium=generated_text_cta" |
| 90 | + target="_blank" |
| 91 | + > |
| 92 | + Subscribe on YouTube |
| 93 | + </a>{" "} |
| 94 | + for tutorials, demos, and streams. |
| 95 | + </li> |
| 96 | + <li> |
| 97 | + <a |
| 98 | + href="https://pris.ly/github?utm_source=docs&utm_medium=generated_text_cta" |
| 99 | + target="_blank" |
| 100 | + > |
| 101 | + Engage on GitHub |
| 102 | + </a>{" "} |
| 103 | + by starring the repository, reporting issues, or contributing to an issue. |
| 104 | + </li> |
| 105 | + </ul> |
| 106 | + We genuinely value your involvement and look forward to having you as part of our |
| 107 | + community! |
| 108 | + </p> |
| 109 | + </div> |
| 110 | + )} |
| 111 | + </MDXContent> |
| 112 | + </div> |
| 113 | + ); |
| 114 | +} |
0 commit comments