Skip to content

Commit

Permalink
Fix the about->guide link
Browse files Browse the repository at this point in the history
  • Loading branch information
irh committed Apr 22, 2024
1 parent 37d169b commit 9adf680
Show file tree
Hide file tree
Showing 6 changed files with 88 additions and 13 deletions.
64 changes: 59 additions & 5 deletions website/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion website/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,9 @@ pulldown-cmark = "0.9.1"
# Convert pulldown-cmark Events back to the string they were parsed from
pulldown-cmark-to-cmark = "10.0.1"
# A generic serialization/deserialization framework
serde = "1.0.136"
serde = { version = "1.0.136", features = ["derive"] }
# A native Rust encoder and decoder of TOML-formatted files and streams.
toml = "0.8.12"
# Recursively walk a directory.
walkdir = "2.5.0"
# Easy support for interacting between JS and Rust.
Expand Down
2 changes: 2 additions & 0 deletions website/xtask/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,6 @@ anyhow = { workspace = true }
fs_extra = { workspace = true }
pulldown-cmark = { workspace = true }
pulldown-cmark-to-cmark = { workspace = true }
serde = { workspace = true }
toml = { workspace = true }
walkdir = { workspace = true }
23 changes: 17 additions & 6 deletions website/xtask/src/convert_docs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ use std::{
path::{Path, PathBuf},
};

use crate::docs_info::DocsInfo;

pub fn run() -> Result<()> {
convert_single_page_doc(
"about.md",
Expand Down Expand Up @@ -283,11 +285,11 @@ slug = \"{slug}\"
once(event).chain(None)
}
End(Link(link_type, url, title)) => {
let fixed_url = fix_doc_urls(&url, flags.fix_url_mode).into();
let fixed_url = fix_doc_urls(&url, flags.fix_url_mode).unwrap().into();
once(End(Link(link_type, fixed_url, title))).chain(None)
}
End(FootnoteDefinition(url)) => {
let fixed_url = fix_doc_urls(&url, flags.fix_url_mode).into();
let fixed_url = fix_doc_urls(&url, flags.fix_url_mode).unwrap().into();
once(End(FootnoteDefinition(fixed_url))).chain(None)
}
Text(code) if in_koto_code => {
Expand Down Expand Up @@ -315,11 +317,17 @@ slug = \"{slug}\"
Ok(output_buffer)
}

fn fix_doc_urls(url: &str, mode: FixUrlMode) -> String {
fn fix_doc_urls(url: &str, mode: FixUrlMode) -> Result<String> {
use FixUrlMode::*;

let result = match mode {
TopLevelToLatest => url.replace("./language_guide.md", "/docs/latest/language/"),
TopLevelToLatest => {
let docs_info = DocsInfo::get_info()?;
url.replace(
"./language_guide.md",
&format!("/docs/{}/language/", docs_info.latest,),
)
}
TopLevel => url
.replace("./core_lib", "../core")
.replace("./language_guide.md", "../language/"),
Expand All @@ -333,7 +341,10 @@ fn fix_doc_urls(url: &str, mode: FixUrlMode) -> String {
result
};

result
let result = result
// Strip out .md suffixes
.replace(".md", "")
.replace(".md", "");

Ok(result)
}

1 change: 1 addition & 0 deletions website/xtask/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use std::env::args;
use anyhow::{bail, Result};

mod convert_docs;
mod docs_info;
mod postprocess_playground;
mod version_snapshot;

Expand Down
7 changes: 6 additions & 1 deletion website/xtask/src/version_snapshot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ use std::{
use anyhow::{bail, Context, Result};
use walkdir::WalkDir;

use crate::docs_info::DocsInfo;

pub fn run(version: &str) -> Result<()> {
let docs_target = format!("content/docs/{version}");
let docs_target_path = PathBuf::from(&docs_target);
Expand Down Expand Up @@ -78,7 +80,10 @@ pub fn run(version: &str) -> Result<()> {
let info_path = "content/docs/info.toml";
let mut info_file =
File::create(info_path).with_context(|| format!("failed to create file at {info_path}"))?;
writeln!(info_file, "latest = \"{version}\"")?;
let docs_info = DocsInfo {
latest: version.to_string(),
};
writeln!(info_file, "latest = \"{}\"", toml::to_string(&docs_info)?)?;
println!("docs/info.toml updated");

Ok(())
Expand Down

0 comments on commit 9adf680

Please sign in to comment.