Skip to content

Commit

Permalink
fix: fixing display of documentation data in web app (#8)
Browse files Browse the repository at this point in the history
  • Loading branch information
woutersl committed Sep 11, 2024
1 parent f2bb3fb commit 63b235a
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 27 deletions.
67 changes: 44 additions & 23 deletions src/webapp/crate.html
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,9 @@ <h5 class="text-xl font-bold tracking-tight text-gray-900 dark:text-white mt-8">
</p>
<pre class="max-w-xs"><code id="meta-install" class="language-toml hljs"></code></pre>
<h5 class="text-xl font-bold tracking-tight text-gray-900 dark:text-white mt-8">Documentation</h5>
<p id="meta-docs" class="ml-4 font-normal text-gray-700 dark:text-gray-400"></p>
<div class="ml-4 font-normal text-gray-700 dark:text-gray-400">
<ul id="meta-docs" class="max-w-md space-y-1 text-gray-500 list-disc list-inside dark:text-gray-400"></ul>
</div>
<h5 class="text-xl font-bold tracking-tight text-gray-900 dark:text-white mt-8">Owners</h5>
</div>
</div>
Expand All @@ -141,7 +143,7 @@ <h5 class="text-xl font-bold tracking-tight text-gray-900 dark:text-white mt-8">
Version
</th>
<th scope="col" class="px-6 py-3">
Status
Targets / Status
</th>
<th scope="col" class="px-6 py-3">
Actions
Expand Down Expand Up @@ -315,12 +317,22 @@ <h3 class="mb-3 text-2xl font-bold text-gray-900 dark:text-white">Remove this ta
document.getElementById("meta-uploaded-by").appendChild(document.createTextNode(currentVersion.uploadedBy.name));
document.getElementById("meta-uploaded-by").href = `mailto:${currentVersion.uploadedBy.email}`;
document.getElementById("meta-install").appendChild(document.createTextNode(`${currentVersion.index.name} = { version = "${currentVersion.index.vers}", registry = "${registryInfo.registryName}" }`));
if (currentVersion.hasDocs) {
const crateRustName = currentVersion.index.name.replaceAll("-", "_");
const link = document.createElement("a");
link.appendChild(document.createTextNode(`v${currentVersion.index.vers}`));
link.setAttribute("href", `/docs/${currentVersion.index.name}/${currentVersion.index.vers}/${crateRustName}/index.html`);
document.getElementById("meta-docs").appendChild(link);
for (const doc of currentVersion.docs) {
if (doc.isPresent) {
const crateRustName = currentVersion.index.name.replaceAll("-", "_");
const link = document.createElement("a");
if (doc.target === registryInfo.toolchainHost) {
// default target
link.appendChild(document.createTextNode(`v${currentVersion.index.vers}`));
link.setAttribute("href", `/docs/${currentVersion.index.name}/${currentVersion.index.vers}/${crateRustName}/index.html`);
} else {
link.appendChild(document.createTextNode(`v${currentVersion.index.vers} - ${doc.target}`));
link.setAttribute("href", `/docs/${currentVersion.index.name}/${currentVersion.index.vers}/${doc.target}/${crateRustName}/index.html`);
}
const li = document.createElement("li");
li.appendChild(link);
document.getElementById("meta-docs").appendChild(li);
}
}
document.getElementById("tab-readme-dl-total").appendChild(document.createTextNode(
crate.versions.reduce((acc, v) => acc + v.downloadCount, 0).toString()
Expand Down Expand Up @@ -693,32 +705,41 @@ <h3 class="mb-3 text-2xl font-bold text-gray-900 dark:text-white">Remove this ta
}

function renderDocsVersion(version) {
const linkEl = document.createElement("a");
if (version.hasDocs) {
const crateRustName = version.index.name.replaceAll("-", "_");
linkEl.setAttribute("href", `/docs/${version.index.name}/${version.index.vers}/${crateRustName}/index.html`);
}
linkEl.className = "font-medium text-blue-600 dark:text-blue-500 hover:underline";
linkEl.appendChild(document.createTextNode(version.index.vers));
const hasMissing = version.docs.length === 0 || version.docs.reduce((acc, doc) => acc || !doc.isPresent, false);

const color = version.hasDocs ? "green" : "red";
const statusEl = document.createElement("span");
statusEl.className = `bg-${color}-100 text-${color}-800 text-xs font-medium me-2 px-2.5 py-0.5 rounded dark:bg-${color}-900 dark:text-${color}-300`;
statusEl.style.display = "inline-block";
statusEl.appendChild(document.createTextNode(version.hasDocs ? "available" : "missing"));
const versionEl = document.createElement("span");
versionEl.className = "font-medium text-blue-600 dark:text-blue-500";
versionEl.appendChild(document.createTextNode(version.index.vers));

const row = document.createElement("tr");
const cell1 = document.createElement("th");
cell1.setAttribute("scope", "row");
cell1.className = "px-6 py-4 font-medium";
cell1.appendChild(linkEl);
cell1.appendChild(versionEl);
const cell2 = document.createElement("td");
cell2.className = "px-6 py-4";
cell2.appendChild(statusEl);
const cell3 = document.createElement("td");
cell3.className = "px-6 py-4";

if (!version.hasDocs) {
for (const doc of version.docs) {
const color = doc.isPresent ? "green" : "red";
const statusEl = document.createElement("span");
statusEl.className = `mx-3 bg-${color}-100 text-${color}-800 text-xs font-medium me-2 px-2.5 py-0.5 rounded dark:bg-${color}-900 dark:text-${color}-300`;
statusEl.appendChild(document.createTextNode(doc.isPresent ? "available" : "missing"));

const crateRustName = version.index.name.replaceAll("-", "_");
const linkEl = document.createElement("a");
linkEl.appendChild(document.createTextNode(doc.target));
linkEl.setAttribute("href", `/docs/${version.index.name}/${version.index.vers}/${doc.target}/${crateRustName}/index.html`);

const wrapper = document.createElement("div");
wrapper.appendChild(linkEl);
wrapper.appendChild(statusEl);
wrapper.style.display = "inline-block";
cell2.appendChild(wrapper);
}

if (hasMissing) {
// <button type="button" class="text-white bg-blue-700 hover:bg-blue-800 focus:ring-4 focus:ring-blue-300 font-medium rounded-lg text-sm px-5 py-2.5 me-2 mb-2 dark:bg-blue-600 dark:hover:bg-blue-700 focus:outline-none dark:focus:ring-blue-800">Default</button>
const refreshEl = document.createElement("button");
refreshEl.type = "button";
Expand Down
4 changes: 2 additions & 2 deletions src/webapp/index-outdated.html
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,10 @@ <h1 class="text-xl font-bold leading-tight tracking-tight text-gray-900 md:text-
const color = hasWarning ? "yellow" : "gray";
const card = document.createElement("a");
card.className = `block m-2 p-2 bg-white border border-${color}-200 rounded-lg shadow hover:bg-${color}-100 dark:bg-${color}-800 dark:border-${color}-700 dark:hover:bg-${color}-700`;
card.href = withVersion ? `/crates/${crate.name}/${crate.version}` : `/crates/${crate.name}`;
card.href = withVersion ? `/crates/${crate.package}/${crate.version}` : `/crates/${crate.package}`;
const title = document.createElement("h5");
title.className = `mb-1 text-xl font-bold tracking-tight text-${color}-900 dark:text-${color}-100`;
title.appendChild(document.createTextNode(crate.name));
title.appendChild(document.createTextNode(crate.package));
card.appendChild(title);
if (withVersion) {
const sub = document.createElement("p");
Expand Down
4 changes: 2 additions & 2 deletions src/webapp/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -130,10 +130,10 @@ <h1 class="text-xl font-bold leading-tight tracking-tight text-gray-900 md:text-
const color = hasWarning ? "yellow" : "gray";
const card = document.createElement("a");
card.className = `block m-2 p-2 bg-white border border-${color}-200 rounded-lg shadow hover:bg-${color}-100 dark:bg-${color}-800 dark:border-${color}-700 dark:hover:bg-${color}-700`;
card.href = withVersion ? `/crates/${crate.name}/${crate.version}` : `/crates/${crate.name}`;
card.href = withVersion ? `/crates/${crate.package}/${crate.version}` : `/crates/${crate.package}`;
const title = document.createElement("h5");
title.className = `mb-1 text-xl font-bold tracking-tight text-${color}-900 dark:text-${color}-100`;
title.appendChild(document.createTextNode(crate.name));
title.appendChild(document.createTextNode(crate.package));
card.appendChild(title);
if (withVersion) {
const sub = document.createElement("p");
Expand Down

0 comments on commit 63b235a

Please sign in to comment.