Skip to content

Commit

Permalink
docs: partial fixes DOC-1263
Browse files Browse the repository at this point in the history
  • Loading branch information
addetz committed Jul 8, 2024
1 parent 71c9bf6 commit 9589f4b
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 9 deletions.
14 changes: 11 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -557,8 +557,16 @@ scheme. The rows of cards are dynamically created according to the list of speci
## Partials Component
This is a custom component that allows you to create and use
[Import Markdown](https://docusaurus.io/docs/3.2.1/markdown-features/react#importing-markdown).
This is a custom component that allows you to create and use Docusaurus'
[Import Markdown](https://docusaurus.io/docs/markdown-features/react#importing-markdown) functionality.

> [!IMPORTANT]
> Docusaurus does not provide the ability to dynamically configure table of contents. See
> [this issue](https://github.com/facebook/docusaurus/issues/6201) for more information. This means that you should
> avoid adding headings to partials that you intend to use with the Partials Component.
>
> If you require headings, then you should import your partials using the guidance on the Docusaurus
> [Import Markdown](https://docusaurus.io/docs/markdown-features/react#importing-markdown) page.

Partials must be created under the `_partials` folder. They must be named using an `_` prefix and the `*.mdx` filetype.
Partials may be organised in any further subfolders as required. For example, you could create
Expand Down Expand Up @@ -610,7 +618,7 @@ partial_name: palette-setup
This is how you set up Palette in {props.cloud}.
This is an <VersionedLink name="Internal Link" url="/getting-started/additional-capabilities"/>.
This is a <VersionedLink text="Internal Link" url="/getting-started/additional-capabilities"/>`.
```
The path of the link should be the path of the destination file from the root directory, without any back operators
Expand Down
10 changes: 6 additions & 4 deletions scripts/generate-partials.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,18 @@ touch _partials/index.ts
# Make the versioned partials folder to satisfy compiler.
mkdir -p versioned_partials

# Make _partials the current working directory. All paths will be relative to it now.
cd _partials

# Create the file and add the generated warning.
echo "// This file is generated. DO NOT EDIT!" >> _partials/index.ts
echo "// This file is generated. DO NOT EDIT!" >> index.ts

# Find all the MDX files recursively in the _partials folder.
# Loop through each file.
find _partials -name "*.mdx" -print0 | while read -d $'\0' path
find . -name "*.mdx" -print0 | while read -d $'\0' path
do
module_name=$(basename ${path} .mdx | tr -d '_' | tr -d '-')
file_name=$(basename ${path})
echo "export * as ${module_name}${RANDOM} from './${file_name}';" >> _partials/index.ts
echo "export * as ${module_name}${RANDOM} from '${path}';" >> index.ts
done

echo "Completed generation of _partials/index.ts."
5 changes: 3 additions & 2 deletions src/components/PartialsComponent/PartialsComponent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ export default function PartialsComponent(details: ComponentProperties): React.R

// Construct the map key including the version
const mapKey = getMapKey(ver, details.category, details.name);
if (!AllPartials[mapKey]) {
const foundPartial = AllPartials[mapKey];
if (!foundPartial) {
throw new Error(
"No partial found for name "
.concat(details.name)
Expand All @@ -42,7 +43,7 @@ export default function PartialsComponent(details: ComponentProperties): React.R
propAttribute[key] = details[key];
}

return React.createElement(AllPartials[mapKey], propAttribute);
return React.createElement(foundPartial, propAttribute);
}

function getMapKey(ver: string, category: string, name: string): string {
Expand Down

0 comments on commit 9589f4b

Please sign in to comment.