Skip to content

Commit

Permalink
feat(website): added auto-versioning to docs.rs shorthand links
Browse files Browse the repository at this point in the history
  • Loading branch information
arctic-hen7 committed Jul 2, 2022
1 parent a32f1ee commit e727121
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 15 deletions.
15 changes: 10 additions & 5 deletions docs/manifest.json
Original file line number Diff line number Diff line change
@@ -1,22 +1,27 @@
{
"0.1.x": {
"state": "outdated",
"git": "v0.1.4"
"git": "v0.1.4",
"docs_rs": "0.1"
},
"0.2.x": {
"state": "outdated",
"git": "v0.2.3"
"git": "v0.2.3",
"docs_rs": "0.2"
},
"0.3.0-0.3.3": {
"state": "outdated",
"git": "v0.3.3"
"git": "v0.3.3",
"docs_rs": "0.3.3"
},
"0.3.4": {
"state": "stable",
"git": "eccf137032fbe8e6507be9e9317edc16e7576a4f"
"git": "eccf137032fbe8e6507be9e9317edc16e7576a4f",
"docs_rs": "0.3"
},
"0.4.x": {
"state": "beta",
"git": "HEAD"
"git": "HEAD",
"docs_rs": "0.4.0-beta"
}
}
32 changes: 22 additions & 10 deletions website/src/templates/docs/generation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,23 +102,21 @@ impl DocsVersionStatus {
}
/// Information about the current state of the documentation, including which versions are outdated and the like.
pub type DocsManifest = HashMap<String, VersionManifest>;
// pub struct DocsManifest {
// pub stable: String,
// pub outdated: Vec<String>,
// pub beta: Vec<String>,
// /// A map of versions to points in the Git version history.
// pub history_map: HashMap<String, String>,
// }

/// Information about a single version in the documentation manifest.
#[derive(Serialize, Deserialize, Clone)]
#[derive(Serialize, Deserialize, Clone, PartialEq, PartialOrd)]
pub struct VersionManifest {
/// The state of this version.
pub state: VersionState,
/// The location in the Git history to get examples from for this version.
pub git: String,
/// The version to use on docs.rs for this version. This will be interpolated into all docs.rs links
/// in this version's docs.
pub docs_rs: String,
}
/// The possible states a version can be in. Note that there can only be one stable version at a time, and that the special `next`
/// version is not accounted for here.
#[derive(Serialize, Deserialize, Clone, PartialEq, Eq)]
#[derive(Serialize, Deserialize, Clone, PartialEq, Eq, PartialOrd)]
#[serde(rename_all = "snake_case")]
pub enum VersionState {
/// The version is outdated, and should no longer be used if possible.
Expand Down Expand Up @@ -344,7 +342,21 @@ pub async fn get_build_state(

// Parse any links to docs.rs (of the form `[`Error`](=enum.Error@perseus)`, where `perseus` is the package name)
// Versions are interpolated automatically
let docs_rs_version = "latest";
let docs_rs_version = if version == "next" {
// Unfortunately, `latest` doesn't take account of beta versions, so we use either the latest beta version or the stable version
let mut beta_versions = BETA_VERSIONS.values().collect::<Vec<&VersionManifest>>();
beta_versions.sort_by(|a, b| b.partial_cmp(a).unwrap());
if beta_versions.is_empty() {
get_stable_version(&DOCS_MANIFEST).1.docs_rs
} else {
beta_versions[0].docs_rs.to_string()
}
} else {
match &DOCS_MANIFEST.get(version) {
Some(version) => version.docs_rs.to_string(),
None => panic!("docs version '{}' not present in manifest", version),
}
};
let contents = Regex::new(r#"\]\(=(?P<path>.*?)@(?P<pkg>.*?)\)"#)
.unwrap()
.replace_all(
Expand Down

0 comments on commit e727121

Please sign in to comment.