Skip to content

Instantly share code, notes, and snippets.

@phgeraldeli
Created February 26, 2023 15:38
Show Gist options
  • Save phgeraldeli/5949677fa44d7d195020414d1cad56b3 to your computer and use it in GitHub Desktop.
Save phgeraldeli/5949677fa44d7d195020414d1cad56b3 to your computer and use it in GitHub Desktop.
Generate single index with HTML Reports for GitLab CI + GitLab Pages
#!/bin/bash
# Define the HTML header and footer
header="<html><head><title>HTML Reports</title>
<style>
.topnav {
position: fixed;
top: 0;
left: 0;
width: 100%;
background-color: #333;
overflow: hidden;
}
.topnav a {
float: left;
color: #ffffff !important;
text-align: center;
padding: 14px 16px;
text-decoration: none;
font-size: 17px;
}
.topnav a:hover {
background-color: #ddd;
color: black;
}
.active {
background-color: #4CAF50;
color: white;
}
</style>
</head>
<body>
<div class=\"topnav\">
<a class=\"active\" href=\"#\">HTML Reports</a>"
for filepath in "$@"
do
filename=$(basename "$filepath")
header+="<a href=\"#${filename}\">${filename}</a>"
done
header+="</div>"
footer="</body></html>"
# Define the HTML for the content section
content="<div>"
for filepath in "$@"
do
filename=$(basename "$filepath")
content+="<div id=\"${filename}\"><h2>${filename}</h2>"
content+=$(cat "$filepath")
content+="</div>"
done
content+="</div>"
# Combine the HTML sections into a single document
html="${header}${homepage}${content}${footer}"
# Write the HTML to a file
echo "$html" > index.html
# Create the CSS file for smooth scrolling
echo 'html { scroll-behavior: smooth; }' > smooth-scroll.css
# Create the JavaScript file for smooth scrolling
echo 'function smoothScroll(target) {
document.querySelector(target).scrollIntoView({
behavior: "smooth"
});
}' > smooth-scroll.js
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment