Skip to content

Commit 79d1a57

Browse files
committed
Auto merge of #3967 - nipunn1313:rerender_readme, r=Turbo87
admin/render_readmes.rs to correctly identify the readme path Previously, it would try to get a field called `readme_file` which never existed in the Cargo.toml manifest format. This fixes it. https://doc.rust-lang.org/cargo/reference/manifest.html#the-readme-field I believe the confusion arose because the `cargo package` command actually converts the readme contents -> readme field and the Cargo.toml readme field -> `readme_file` field when making the request to crates.io. However, in the admin render_readme backfill, it is opening the original Cargo.toml which has a `readme` field for the path. I manually tested with a local backend/frontend and confirmed that readme paths were being re-rendered correctly. Manual test screenshots: Before this change - after doing a rerender ![image](https://user-images.githubusercontent.com/1300387/135545532-5df746af-77a8-4140-99a8-74b09fe512a1.png) After this change - after doing a rerender ![image](https://user-images.githubusercontent.com/1300387/135545434-9f82ee13-e909-4c1d-8544-8ed6023b7944.png) Repro steps Set up a local dev environment via the [docs/CONTRIBUTING.md](https://github.com/rust-lang/crates.io/blob/master/docs/CONTRIBUTING.md) instructions. Publish a package (I used one called `innercrate`) (using above instructions) with nonroot README ``` ➜ innercrate git:(master) ✗ cat docs/README.md Check out [other file](./Otherfile.md) ➜ innercrate git:(master) ✗ cat docs/Otherfile.md hello world ➜ innercrate git:(master) ✗ grep readme Cargo.toml readme = "docs/README.md" ``` Re-render readmes `cargo run --bin crates-admin -- render-readmes --crate innercrate` Look at http://localhost:4200/crates/innercrate
2 parents f644d04 + ba08285 commit 79d1a57

File tree

1 file changed

+5
-12
lines changed

1 file changed

+5
-12
lines changed

src/admin/render_readmes.rs

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -213,31 +213,24 @@ fn get_readme(
213213
};
214214

215215
let rendered = {
216-
let path = format!(
217-
"{}-{}/{}",
218-
krate_name, version.num, manifest.package.readme?
219-
);
216+
let readme_path = manifest.package.readme.as_ref()?;
217+
let path = format!("{}-{}/{}", krate_name, version.num, readme_path);
220218
let contents = find_file_by_path(&mut entries, Path::new(&path), version, krate_name);
221219
text_to_html(
222220
&contents,
223-
manifest
224-
.package
225-
.readme_file
226-
.as_ref()
227-
.map_or("README.md", |e| &**e),
221+
readme_path,
228222
manifest.package.repository.as_deref(),
229223
)
230224
};
231225
return Some(rendered);
232226

233-
#[derive(Deserialize)]
227+
#[derive(Debug, Deserialize)]
234228
struct Package {
235229
readme: Option<String>,
236-
readme_file: Option<String>,
237230
repository: Option<String>,
238231
}
239232

240-
#[derive(Deserialize)]
233+
#[derive(Debug, Deserialize)]
241234
struct Manifest {
242235
package: Package,
243236
}

0 commit comments

Comments
 (0)