Skip to content

Commit 1eee542

Browse files
authored
Merge pull request #109 from stackabletech/sbom_improvements
Extend the HTML with a title and some links
2 parents 87573b2 + 7a9c31b commit 1eee542

File tree

1 file changed

+74
-57
lines changed

1 file changed

+74
-57
lines changed

tools/harbor_sbom_browser/src/handlers/artifact_tree.rs

Lines changed: 74 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ lazy_static! {
4949
pub async fn render_as_html(
5050
State(cached_rendered_artifact_tree): State<CachedObject<Html<String>>>,
5151
) -> Result<Html<String>, ArtifactTreeError> {
52+
5253
// if the artifact tree is already cached, return it
5354
if let Some(html) = cached_rendered_artifact_tree.get() {
5455
return Ok(html);
@@ -57,7 +58,67 @@ pub async fn render_as_html(
5758
let artifact_tree = build_artifact_tree().await?;
5859

5960
let mut html = String::with_capacity(64 * 1024); // reserve 64KB to avoid reallocations
60-
html.push_str("<html><body><ul id='tree'>");
61+
html.push_str(
62+
r#"
63+
<!DOCTYPE html>
64+
<html lang="en">
65+
<head>
66+
<meta charset="UTF-8">
67+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
68+
<title>Stackable :: SBOM Browser</title>
69+
<style>
70+
body {
71+
font-family: Arial, sans-serif;
72+
padding: 20px;
73+
font-size: 20px;
74+
}
75+
ul {
76+
list-style-type: none;
77+
padding: 0;
78+
cursor: pointer;
79+
}
80+
li {
81+
margin: 6px 0;
82+
padding-left: 25px;
83+
position: relative;
84+
flex-direction: column;
85+
justify-content: center;
86+
display: none;
87+
}
88+
li::before {
89+
content: "";
90+
position: absolute;
91+
top: 4px;
92+
left: 0;
93+
width: 10px;
94+
height: 10px;
95+
border-top: 2px solid #000;
96+
border-right: 2px solid #000;
97+
transform: rotate(45deg);
98+
}
99+
li.open > ul > li, ul#tree > li {
100+
display: flex;
101+
}
102+
li.open::before {
103+
transform: rotate(135deg);
104+
top: 2px;
105+
left: 4px;
106+
}
107+
li.artifact::before {
108+
display: none;
109+
}
110+
</style>
111+
</head>
112+
<body>
113+
<div align="center">
114+
<a href="https://stackable.tech/">Stackable Data Platform</a> |
115+
<a href="https://docs.stackable.tech/">Documentation</a> |
116+
<a href="https://github.com/orgs/stackabletech/discussions">Discussions</a> |
117+
<a href="https://discord.gg/7kZ3BNnCAF">Discord</a>
118+
</div>
119+
<ul id='tree'>"#,
120+
);
121+
61122
for (release_version, repositories) in artifact_tree {
62123
html.push_str(&format!("<li>Release {}<ul>", release_version));
63124
for (repository, artifacts) in repositories {
@@ -72,68 +133,24 @@ pub async fn render_as_html(
72133
}
73134
html.push_str("</ul></li>");
74135
}
136+
75137
html.push_str(
76138
r#"</ul>
77-
<style>
78-
body {
79-
font-family: Arial, sans-serif;
80-
padding: 20px;
81-
font-size: 20px;
82-
}
83-
ul {
84-
list-style-type: none;
85-
padding: 0;
86-
cursor: pointer;
87-
}
88-
89-
li {
90-
margin: 6px 0px;
91-
padding-left: 25px;
92-
position: relative;
93-
flex-direction: column;
94-
justify-content: center;
95-
display: none;
96-
}
97-
98-
li::before {
99-
content: "";
100-
display: block;
101-
position: absolute;
102-
top: 4px;
103-
left: 0;
104-
width: 10px;
105-
height: 10px;
106-
border-top: 2px solid #000;
107-
border-right: 2px solid #000;
108-
transform: rotate(45deg);
109-
}
110-
li.open > ul > li, ul#tree > li {
111-
display: flex;
112-
}
113-
li.open::before {
114-
transform: rotate(135deg);
115-
top: 2px;
116-
left: 4px;
139+
<script>
140+
const tree = document.getElementById("tree");
141+
tree.addEventListener("click", (event) => {
142+
const target = event.target;
143+
if (target.tagName === "LI") {
144+
target.classList.toggle("open");
117145
}
118-
li.artifact::before {
119-
display: none;
120-
}
121-
</style>
122-
<script>
123-
const tree = document.getElementById("tree");
124-
tree.addEventListener("click", (event) => {
125-
const target = event.target;
126-
if (target.tagName === "LI") {
127-
target.classList.toggle("open");
128-
}
129-
});
130-
</script>
131-
</body></html>
132-
"#,
146+
});
147+
</script>
148+
</body>
149+
</html>
150+
"#,
133151
);
134152

135153
let html = Html(html);
136-
// cache the rendered artifact tree
137154
cached_rendered_artifact_tree.set_to(html.clone());
138155
Ok(html)
139156
}

0 commit comments

Comments
 (0)