Optimize feature flag empty UI, and add quick link to Cargo.toml

This commit is contained in:
Folyd 2020-12-08 23:35:32 +08:00
parent f30bc875f4
commit b3d59311d3
2 changed files with 12 additions and 2 deletions

View file

@ -17,6 +17,11 @@ div.nav-container form.landing-search-form-nav {
max-width: 60rem;
}
.feature-flags-content a {
color: var(--color-navbar-standard);
text-decoration: underline;
}
.feature-flags-table {
margin: 0.5rem;
border-collapse: separate;

View file

@ -39,9 +39,14 @@ document.addEventListener("DOMContentLoaded", async () => {
async function enhanceFeatureFlagsMenu(menu) {
// Use rawCrateName to fetch the Cargo.toml, otherwise will get 404.
let response = await fetch(`https://docs.rs/crate/${rawCrateName}/${crateVersion}/source/Cargo.toml`);
let cargoTomUrl = `https://docs.rs/crate/${rawCrateName}/${crateVersion}/source/Cargo.toml`;
let response = await fetch(cargoTomUrl);
let features = parseCargoFeatures(await response.text());
let html = `<div style="padding: 1rem"><p>This crate has no feature flag.</p></div>`;
let html = `<div style="padding: 1rem"><p>
This crate has no explicit-declared feature flag.
<br>
Check its <a href="${cargoTomUrl}">Cargo.toml</a> to learn more.
</p></div>`;
if (features.length > 0) {
let tbody = features.map(([name, flags]) => {
return `<tr class="module-item">