Skip to content

Commit

Permalink
refactor generation script
Browse files Browse the repository at this point in the history
  • Loading branch information
xand6r committed Dec 11, 2024
1 parent 9a77e0e commit 9b66936
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 14 deletions.
26 changes: 12 additions & 14 deletions docs/generatedocs.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,11 @@ main() {
)

# The template for the list
item_html_template='
<li class="packages__list__item">
<a target="_blank" href="package_path_placeholder">
<span class="package__name"> {{name_placeholder}} </span>
<span class="package__description"> {{description_placeholder}} </span>
</a>
</li>
'
item_html_template=$(cat ./templates/item.hbs)

# The filled template
package_list_html=''
package_version=$(grep -oP '^version\s*=\s*"\K[^"]+' "../Cargo.toml")

for current_dir in ${projects_dirs[@]}; do
# Obtain the Cargo.toml file to the current_directory in the integration
Expand All @@ -33,20 +27,21 @@ main() {
# Use grep and sed to extract the value of the name, description and version of the package
package_name=$(grep -oP '^name\s*=\s*"\K[^"]+' "$manifest_path")
package_description=$(grep -oP '^description\s*=\s*"\K[^"]+' "$manifest_path")
package_version=$(grep -oP '^version\s*=\s*"\K[^"]+' "../Cargo.toml")

package_name_and_version="$package_name-$package_version"

# Replace all hyphens with underscores i/e pkg-1 => pkg_2
underscore_package_name=${package_name//-/_}

# Obtain the target_directory where the docs will be saved based on the package name
target_dir="./packages/$package_name"

# Run the command to generate the docs
cargo doc --manifest-path "$manifest_path" --target-dir "$target_dir"
path_to_docs=("packages/$package_name/doc/$underscore_package_name/index.html")
path_to_docs=("./packages/$package_name/doc/$underscore_package_name/index.html")

# Delete the build file because it takes space and is unnecessary to the docs
path_to_build=("packages/$package_name/debug")
path_to_build=("./packages/$package_name/debug")
rm -rf $path_to_build

# Replace name and description placeholders in the template
Expand All @@ -56,18 +51,21 @@ main() {
package_list_html+="$processed_html"
done

input_file_path="./base.html"
input_file_path="./templates/base.hbs"
output_file_path="./index.html"

# Read the input file into a variable
input_file=$(cat $input_file_path)

# Split the content into parts using 'packages_list' as the delimiter
# Split the content into parts using '{{packages_list}}' as the delimiter
before_placeholder=${input_file%%"{{packages_list}}"*}
after_placeholder=${input_file#*"{{packages_list}}"}

# Create the full html content by putting the html content in the middle of the htmltemplate
# ! have to do this instead of a direct replace because the replace command fails due to special characters present in an html template
full_html="$before_placeholder $package_list_html $after_placeholder"

# echo "Replaced 'packages_list' with the content of 'list_items' in $input_file_path."
# Write the processed HTML to the output file path
echo "$full_html" > $output_file_path
}

Expand Down
File renamed without changes.
6 changes: 6 additions & 0 deletions docs/templates/item.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<li class="packages__list__item">
<a target="_blank" href="package_path_placeholder">
<span class="package__name"> {{name_placeholder}} </span>
<span class="package__description"> {{description_placeholder}} </span>
</a>
</li>

0 comments on commit 9b66936

Please sign in to comment.