|
4 | 4 | use std::collections::BTreeMap; |
5 | 5 | use std::fmt::Write as _; |
6 | 6 | use std::fs; |
7 | | -use std::path::Path; |
8 | 7 | use std::path::PathBuf; |
9 | 8 |
|
10 | 9 | use anyhow::Context; |
11 | | -use anyhow::bail; |
12 | 10 | use serde::Deserialize; |
13 | 11 | use xshell::Shell; |
14 | 12 | use xshell::cmd; |
15 | 13 |
|
16 | | -/// Marker lines delimiting the generated edition links on the docs landing page. |
17 | | -/// Everything between them is owned by this generator; hand edits there are overwritten. |
18 | | -static INDEX_BEGIN_MARKER: &str = "<!-- BEGIN generated edition links: edit the declarations in \ |
19 | | - `vortex/src/editions/` and run `cargo xtask generate-editions-docs` -->"; |
20 | | -static INDEX_END_MARKER: &str = "<!-- END generated edition links -->"; |
21 | | - |
22 | 14 | /// Header comment stamped on every fully generated page. |
23 | 15 | static GENERATED_HEADER: &str = "<!-- Generated by `cargo xtask generate-editions-docs` from the \ |
24 | 16 | declarations in `vortex/src/editions/`; do not edit. -->"; |
@@ -62,16 +54,11 @@ impl ManifestEdition { |
62 | 54 | fn sibling_link(&self) -> String { |
63 | 55 | format!("[`{}`]({})", self.id, self.file_name()) |
64 | 56 | } |
65 | | - |
66 | | - /// A link to this edition's page from `docs/index.md`. |
67 | | - fn landing_link(&self) -> String { |
68 | | - format!("[`{}`](specs/editions/{})", self.id, self.file_name()) |
69 | | - } |
70 | 57 | } |
71 | 58 |
|
72 | 59 | /// Regenerate the edition registry pages under `docs/specs/editions/` (an index page plus |
73 | | -/// one page per edition) and the edition links on `docs/index.md`, from the edition |
74 | | -/// declarations in the `vortex` crate, via a TOML manifest written under `target/`. |
| 60 | +/// one page per edition) from the edition declarations in the `vortex` crate, via a TOML |
| 61 | +/// manifest written under `target/`. |
75 | 62 | pub fn generate_editions_docs(profile: Option<String>) -> anyhow::Result<()> { |
76 | 63 | let sh = Shell::new()?; |
77 | 64 | let root = PathBuf::from(env!("CARGO_MANIFEST_DIR")).join(".."); |
@@ -125,40 +112,6 @@ pub fn generate_editions_docs(profile: Option<String>) -> anyhow::Result<()> { |
125 | 112 | registry_dir.display() |
126 | 113 | ); |
127 | 114 |
|
128 | | - splice( |
129 | | - &root.join("docs/index.md"), |
130 | | - INDEX_BEGIN_MARKER, |
131 | | - INDEX_END_MARKER, |
132 | | - &render_landing_links(&manifest)?, |
133 | | - )?; |
134 | | - Ok(()) |
135 | | -} |
136 | | - |
137 | | -/// Replace the content between the marker comments in `path` with `content`. |
138 | | -fn splice(path: &Path, begin_marker: &str, end_marker: &str, content: &str) -> anyhow::Result<()> { |
139 | | - let text = fs::read_to_string(path)?; |
140 | | - let (Some(begin), Some(end)) = (text.find(begin_marker), text.find(end_marker)) else { |
141 | | - bail!( |
142 | | - "{} must contain the generated-section BEGIN/END marker comments", |
143 | | - path.display() |
144 | | - ); |
145 | | - }; |
146 | | - if end < begin { |
147 | | - bail!( |
148 | | - "generated-section markers are out of order in {}", |
149 | | - path.display() |
150 | | - ); |
151 | | - } |
152 | | - |
153 | | - let mut spliced = String::new(); |
154 | | - spliced.push_str(&text[..begin + begin_marker.len()]); |
155 | | - spliced.push_str("\n\n"); |
156 | | - spliced.push_str(content); |
157 | | - spliced.push('\n'); |
158 | | - spliced.push_str(&text[end..]); |
159 | | - fs::write(path, spliced)?; |
160 | | - |
161 | | - println!("regenerated the edition links in {}", path.display()); |
162 | 115 | Ok(()) |
163 | 116 | } |
164 | 117 |
|
@@ -277,26 +230,3 @@ fn render_edition( |
277 | 230 | } |
278 | 231 | Ok(md) |
279 | 232 | } |
280 | | - |
281 | | -/// Render the per-family edition links that go between the markers in `docs/index.md`. |
282 | | -fn render_landing_links(manifest: &Manifest) -> anyhow::Result<String> { |
283 | | - let mut md = String::new(); |
284 | | - // Editions arrive sorted by family, so consecutive dedup yields each family once. |
285 | | - let mut families: Vec<&str> = manifest |
286 | | - .editions |
287 | | - .iter() |
288 | | - .map(|edition| edition.family.as_str()) |
289 | | - .collect(); |
290 | | - families.dedup(); |
291 | | - |
292 | | - for family in families { |
293 | | - let links: Vec<String> = manifest |
294 | | - .editions |
295 | | - .iter() |
296 | | - .filter(|edition| edition.family == family) |
297 | | - .map(ManifestEdition::landing_link) |
298 | | - .collect(); |
299 | | - writeln!(md, "- **{family}**: {}", links.join(" · "))?; |
300 | | - } |
301 | | - Ok(md) |
302 | | -} |
0 commit comments