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

Update generate-table-json.sh #181

Merged
merged 2 commits into from
Dec 23, 2024
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
50 changes: 36 additions & 14 deletions scripts/generate-table-json.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,32 +10,54 @@ generate_json() {
if [ -d "$folder" ]; then
# Extract folder name
folder_name=$(basename "$folder")
json="$json\"$folder_name\": ["

# Loop through files and directories in the folder
# We'll build an array of objects here
local items="["

# Loop through files in the folder
for item in "$folder"/*; do
item_name=$(basename "$item")
# Check if the item is a file and not named "index.md" or "index.mdx"
if [ -f "$item" ] && [ "$item_name" != "index.md" ] && [ "$item_name" != "index.mdx" ]; then
# Remove file extension
item_name_no_ext="${item_name%.*}"
json="$json\"$item_name_no_ext\", "
if [ -f "$item" ]; then
item_name=$(basename "$item")

# Skip index.md or index.mdx
if [ "$item_name" != "index.md" ] && [ "$item_name" != "index.mdx" ]; then

# Remove extension from the filename
local link_name="${item_name%.*}"

# Attempt to extract 'sidebar_label' from the front matter
# removing any trailing newline/carriage return characters
local nice_name=""
nice_name=$(grep '^sidebar_label: ' "$item" \
| head -n 1 \
| sed -E 's/^sidebar_label:\s*"(.*)"/\1/' \
| tr -d '\r\n')

# If no sidebar_label was found, default to the link_name
if [ -z "$nice_name" ]; then
nice_name="$link_name"
fi

# Append object to our items array
items="$items{\"link\": \"$link_name\", \"nice_name\": \"$nice_name\"}, "
fi
fi
done

# Remove the trailing comma and close the array
json="${json%, }], "
# Remove trailing comma and close the array
items="${items%, }]"

# Add this folder's items array to the JSON
json="$json\"$folder_name\": $items, "
fi
done

# Remove the trailing comma and close the JSON object
# Remove trailing comma and close the main JSON object
json="${json%, }}"
echo "$json"
}


# Get the relative path to the directory
# directory="/home/akshat/oet-handbook/docs"
relative_directory="docs"
directory="$(pwd)/$relative_directory"

Expand All @@ -48,4 +70,4 @@ output_file="output.json"
# Write JSON to file
echo "$output_json" > "$output_file"

echo "json generated and saved as output.json"
echo "JSON generated and saved as output.json"
4 changes: 2 additions & 2 deletions src/components/DocsTable/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ const PageLinkTable = ({ key, title, items }) => {
{items.map((item, index) => (
<tr key={index}>
<td className={styles.column_width}>
<Link to={`${pageLink}/${item}`}>
{camelCaseToNormalText(item)}
<Link to={`${pageLink}/${item.link}`}>
{item.nice_name}
</Link>
</td>
</tr>
Expand Down
Loading