Skip to content
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

Added conditional content tags to conditionally render collate and OSS only content #357

Merged
merged 2 commits into from
Feb 18, 2025
Merged
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
34 changes: 34 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ Here are the custom markdoc tags to use for desired functionalities.
- [5. connectorDetailsHeader](#5-connectorDetailsHeader)
- [6. connectorInfoCard](#6-connectorInfoCard)
- [7. connectorsListContainer](#7-connectorsListContainer)
- [Conditional Content](#conditional-content)
- [1. collateContent](#1-collateContent)
- [2. ossContent](#2-ossContent)
- [Tags for Code Preview Functionality](#tags-for-code-preview-functionality)
- [1. codePreview](#1-codePreview)
- [2. codeInfoContainer](#2-codeInfoContainer)
Expand Down Expand Up @@ -284,6 +287,37 @@ A wrapper tag to envelope the connectorInfoCard tags for a grid view.

---

## Conditional Content

- [1. collateContent](#1-collateContent)
- [2. ossContent](#2-ossContent)

### 1. collateContent

A tag to conditionally render content only on collate documentation.

### 2. ossContent

A tag to conditionally render content only on open source documentation.

Example:

This is {% collateContent %}Collate{% /collateContent %}{% ossContent %}OSS{% /ossContent %} documentation.

**The above content will be shown on collate documentation as:**

```
This is Collate documentation.
```

**And will be shown on open source documentation as:**

```
This is OSS documentation.
```

---

## Tags for Code Preview Functionality

For showing code or commands with the explanations by side use following tags:-
Expand Down
14 changes: 14 additions & 0 deletions components/ConditionalContent/CollateContent.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { ReactNode } from "react";
import { useDocVersionContext } from "../../context/DocVersionContext";

function CollateContent({ children }: { children: ReactNode }) {
const { enableVersion } = useDocVersionContext();

if (enableVersion) {
return null;
}

return <>{children}</>;
}

export default CollateContent;
14 changes: 14 additions & 0 deletions components/ConditionalContent/OSSContent.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { ReactNode } from "react";
import { useDocVersionContext } from "../../context/DocVersionContext";

function OSSContent({ children }: { children: ReactNode }) {
const { enableVersion } = useDocVersionContext();

if (!enableVersion) {
return null;
}

return <>{children}</>;
}

export default OSSContent;
24 changes: 14 additions & 10 deletions lib/markdoc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,6 @@ import CodeInfo from "../components/CodePreview/CodeInfo/CodeInfo";
import CodeInfoContainer from "../components/CodePreview/CodeInfoContainer/CodeInfoContainer";
import CodePreview from "../components/CodePreview/CodePreview";
import CodeWithLanguageSelector from "../components/CodeWithLanguageSelector/CodeWithLanguageSelector";
import ConnectorDetailsHeader from "../components/ConnectorDetailsHeader/ConnectorDetailsHeader";
import ConnectorInfoCard from "../components/ConnectorInfoCard/ConnectorInfoCard";
import ConnectorsListContainer from "../components/ConnectorsListContainer/ConnectorsListContainer";
import ExtraContent from "../components/ExtraContent/ExtraContent";
import { Heading } from "../components/Heading/Heading";
import Roadmap from "../components/Roadmap/Roadmap";
import Step from "../components/Steps/Step/Step";
import StepDescription from "../components/Steps/Step/StepDescription/StepDescription";
import StepVisualInfo from "../components/Steps/Step/StepVisualInfo/StepVisualInfo";
import StepsContainer from "../components/Steps/StepsContainer/StepsContainer";
import Code from "../components/common/Code/Code";
import InlineCode from "../components/common/Code/InlineCode";
import CustomAnchorNode from "../components/common/CustomAnchorNode/CustomAnchorNode";
Expand All @@ -32,6 +22,18 @@ import Table from "../components/common/Table/Table";
import Tile from "../components/common/Tiles/Tile/Tile";
import TilesContainer from "../components/common/Tiles/TilesContainer/TilesContainer";
import YouTube from "../components/common/Youtube/Youtube";
import CollateContent from "../components/ConditionalContent/CollateContent";
import OSSContent from "../components/ConditionalContent/OSSContent";
import ConnectorDetailsHeader from "../components/ConnectorDetailsHeader/ConnectorDetailsHeader";
import ConnectorInfoCard from "../components/ConnectorInfoCard/ConnectorInfoCard";
import ConnectorsListContainer from "../components/ConnectorsListContainer/ConnectorsListContainer";
import ExtraContent from "../components/ExtraContent/ExtraContent";
import { Heading } from "../components/Heading/Heading";
import Roadmap from "../components/Roadmap/Roadmap";
import Step from "../components/Steps/Step/Step";
import StepDescription from "../components/Steps/Step/StepDescription/StepDescription";
import StepVisualInfo from "../components/Steps/Step/StepVisualInfo/StepVisualInfo";
import StepsContainer from "../components/Steps/StepsContainer/StepsContainer";
import * as allFunctions from "../markdoc/functions";
import * as allNodes from "../markdoc/nodes";
import * as allTags from "../markdoc/tags";
Expand Down Expand Up @@ -74,6 +76,8 @@ export const components = {
ConnectorsListContainer,
ConnectorDetailsHeader,
Roadmap,
CollateContent,
OSSContent,
};

export const configs: Config = {
Expand Down
3 changes: 3 additions & 0 deletions markdoc/tags/ConditionalContent/collateContent.markdoc.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export const collateContent = {
render: "CollateContent",
};
3 changes: 3 additions & 0 deletions markdoc/tags/ConditionalContent/ossContent.markdoc.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export const ossContent = {
render: "OSSContent",
};
16 changes: 9 additions & 7 deletions markdoc/tags/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,13 @@ export * from "./APIInfoContainer/apiDescription/apiDescription.markdoc";
export * from "./APIInfoContainer/apiInfoContainer.markdoc";
export * from "./APIInfoContainer/apiPageContainer.markdoc";
export * from "./APIInfoContainer/apiVisualInfo/apiVisualInfo.markdoc";
export * from "./Steps/ExtraContent/extraContent.markdoc";
export * from "./Steps/Step/StepDescription/stepDescription.markdoc";
export * from "./Steps/Step/StepVisualInfo/stepVisualInfo.markdoc";
export * from "./Steps/Step/step.markdoc";
export * from "./Steps/StepsContainer/stepsContainer.markdoc";
export * from "./Tiles/Tile/tile.markdoc";
export * from "./Tiles/TilesContainer/tilesContainer.markdoc";
export * from "./codePreview/codeBlock.markdoc";
export * from "./codePreview/codeInfo.markdoc";
export * from "./codePreview/codeInfoContainer.markdoc";
export * from "./codePreview/codePreview.markdoc";
export * from "./codeWithLanguageSelector/codeWithLanguageSelector.markdoc";
export * from "./ConditionalContent/collateContent.markdoc";
export * from "./ConditionalContent/ossContent.markdoc";
export * from "./connectorDetailsHeader.markdoc";
export * from "./connectorInfoCard.markdoc";
export * from "./connectorsListContainer.markdoc";
Expand All @@ -26,5 +21,12 @@ export * from "./inlineCalloutContainer.markdoc";
export * from "./multiTablesWrapper.markdoc";
export * from "./note.markdoc";
export * from "./roadmap.markdoc";
export * from "./Steps/ExtraContent/extraContent.markdoc";
export * from "./Steps/Step/step.markdoc";
export * from "./Steps/Step/StepDescription/stepDescription.markdoc";
export * from "./Steps/Step/StepVisualInfo/stepVisualInfo.markdoc";
export * from "./Steps/StepsContainer/stepsContainer.markdoc";
export * from "./Tiles/Tile/tile.markdoc";
export * from "./Tiles/TilesContainer/tilesContainer.markdoc";
export * from "./youtube.markdoc";