-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgenerateJupyterReportReference.sh
More file actions
executable file
·59 lines (44 loc) · 2.5 KB
/
generateJupyterReportReference.sh
File metadata and controls
executable file
·59 lines (44 loc) · 2.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#!/usr/bin/env bash
# Generates "JUPYTER_REPORTS.md" containing a reference to all Jupyter Notebook Markdown reports in this directory and its subdirectories.
# This script was generated by Chat-GPT after some messages back and forth and then tuned manually.
# Fail on any error ("-e" = exit on first error, "-o pipefail" exist on errors within piped commands)
set -o errexit -o pipefail
# Markdown file name
markdown_file="JUPYTER_REPORTS.md"
echo "generateJupyterReportReference: Generating ${markdown_file}..."
{
echo "# Jupyter Notebook Reports Reference"
echo ""
echo "This document serves as a reference for all Jupyter Notebook reports in the current directory and its subdirectories."
echo "It provides a table listing each file and its corresponding description found in the first header line."
echo "This file was generated with the script [generateJupyterReportReference.sh](./../documentation/analysis-reports-reference/generateJupyterReportReference.sh)."
echo ""
echo "Report | Analysis | Description"
echo "-------|----------|------------"
} > ${markdown_file}
# Loop through all Markdown files in the current directory
find . -type f -name "*.md" | sort | while read -r report_file; do
# Extract the first non-empty line that starts with one or more '#', allowing leading spaces
if ! report_file_header_line=$(grep -m 1 -e '^[[:space:]]*#\+[[:space:]]*.*' "${report_file}"); then
echo "generateJupyterReportReference: Warning: No header line found in ${report_file}, skipping."
continue
fi
# Remove leading '#' characters and trim leading/trailing spaces
description=$(echo "${report_file_header_line}" | sed -E 's/^#+\s*//')
# Trim leading and trailing whitespace
description=$(echo "${description}" | awk '{$1=$1;print}')
# Extract the script file name without the path
filename=$(basename "$report_file")
if [ "$filename" = "${markdown_file}" ]; then
continue
fi
# Extract the script file path without the name
pathname=$(dirname "$report_file")
# Extract the second part of the path after ./ that contains the analysis directory name
analysisname=$(echo "${pathname}" | cut -d/ -f 3)
# Create a link to the script file in the table
link="[${filename}](${report_file})"
# Add the script file and its description to the Markdown table
echo "| ${link} | ${analysisname%%.} | ${description} |" >> ${markdown_file}
done
echo "generateJupyterReportReference: Successfully generated ${markdown_file}."