.mdx files in the original product repository’s /website directory. The update-mdx-files.sh script automates the process of adding a prominent notice to those files.
Purpose
The script inserts a standardized notice block into every.mdx file in a specified directory. The notice informs contributors that:
- Documentation has moved to
hashicorp/web-unified-docs - Changes made in the original
/websitedirectory will not appear ondeveloper.hashicorp.com - Future contributions should be made directly in web-unified-docs
--- of each file’s YAML frontmatter, so it appears prominently at the top of the file content in any editor.
Usage
.mdx files. It recursively processes all .mdx files found within that directory.
What the script does
Validates the input
The script checks that a directory path was provided and that the path exists. If either check fails, it exits with an error message.
Processes each MDX file
For each
.mdx file found recursively in the target directory, the script:- Checks whether the file has YAML frontmatter (delimited by
---) - Finds the line number of the second
---marker (the closing delimiter) - Inserts the notice block immediately after that closing
--- - Overwrites the original file with the updated content
Example output
Example file before and after
- Before
- After
When to run this script
Run this script after the migration PR for a product has been merged into web-unified-docs. The sequence is:- Migrate the product’s documentation into web-unified-docs
- Merge the migration PR
- Run
update-mdx-files.shagainst the original product repository - Open a PR to the product repository with the updated files
- Merge the PR to the product repository
Error handling
| Condition | Behavior |
|---|---|
| File has frontmatter and is updated successfully | Counted in “Files updated” |
| File has no frontmatter | Counted in “Files with no frontmatter”, not modified |
| File could not be written | Error printed, counted in “Files with errors” |
| Second frontmatter marker not found | Error printed, counted in “Files with errors” |