Skip to content

Commit

Permalink
Link to the 'next' docs by default
Browse files Browse the repository at this point in the history
  • Loading branch information
irh committed Dec 16, 2024
1 parent 089d1d5 commit 762b4e2
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 60 deletions.
7 changes: 2 additions & 5 deletions website/templates/header.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
{% set docs_info = load_data(path="content/docs/info.toml") %}
{% set latest = docs_info["latest"] %}

<div uk-sticky="sel-target: .uk-navbar-container cls-active: uk-navbar-sticky">
<nav class="navbar uk-navbar-container uk-navbar">

Expand All @@ -25,7 +22,7 @@
</li>

<li>
<a class="uk-navbar-item uk-text-capitalize" href="/docs/{{latest}}">
<a class="uk-navbar-item uk-text-capitalize" href="/docs/next">
Docs
</a>
</li>
Expand Down Expand Up @@ -58,4 +55,4 @@
</ul>
</div>
</nav>
</div>
</div>
16 changes: 5 additions & 11 deletions website/templates/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,10 @@
</div>

<div class="uk-padding">
<a
class="uk-button uk-button-default uk-button-large
uk-text-capitalize"
href="/about/"
>About</a>
<a
class="uk-button uk-button-default uk-button-large
uk-text-capitalize"
href="/docs/{{docs_info["latest"]}}/language/"
>Guide</a>
<a class="uk-button uk-button-default uk-button-large
uk-text-capitalize" href="/about/">About</a>
<a class="uk-button uk-button-default uk-button-large
uk-text-capitalize" href="/docs/next/language/">Guide</a>
</div>

<div class="uk-container uk-width-1-2">
Expand All @@ -33,4 +27,4 @@
</div>
</section>

{% endblock content %}
{% endblock content %}
21 changes: 8 additions & 13 deletions website/xtask/src/convert_docs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ use std::{
path::{Path, PathBuf},
};

use crate::docs_info::DocsInfo;

pub fn run() -> Result<()> {
convert_single_page_doc(
"about.md",
Expand All @@ -21,7 +19,7 @@ insert_anchor_links = "heading"
"#,
true,
false,
FixUrlMode::TopLevelToLatest,
FixUrlMode::TopLevelToNext,
)?;
convert_single_page_doc(
"language_guide.md",
Expand Down Expand Up @@ -172,8 +170,8 @@ struct ConvertDocFlags {

#[derive(Copy, Clone)]
enum FixUrlMode {
// Adjust doc links to docs/latest
TopLevelToLatest,
// Adjust doc links to docs/next
TopLevelToNext,
// Adjust doc links to neighboring docs version
TopLevel,
// Adjust doc links to neighboring docs version from docs subfolder
Expand Down Expand Up @@ -323,14 +321,11 @@ fn fix_doc_urls(url: &str, mode: FixUrlMode) -> Result<String> {
use FixUrlMode::*;

let result = match mode {
TopLevelToLatest => {
let docs_info = DocsInfo::get_info();
let latest = &docs_info.latest;
url.replace("./language_guide.md", &format!("/docs/{latest}/language/"))
.replace("./cli.md", &format!("/docs/{latest}/cli/"))
.replace("./api.md", &format!("/docs/{latest}/api/"))
.replace("./core_lib", &format!("/docs/{latest}/core/"))
}
TopLevelToNext => url
.replace("./language_guide.md", &format!("/docs/next/language/"))
.replace("./cli.md", &format!("/docs/next/cli/"))
.replace("./api.md", &format!("/docs/next/api/"))
.replace("./core_lib", &format!("/docs/next/core/")),
TopLevel => url
.replace("./core_lib", "../core")
.replace("./language_guide.md", "../language/"),
Expand Down
10 changes: 0 additions & 10 deletions website/xtask/src/docs_info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,3 @@ use serde::{Deserialize, Serialize};
pub struct DocsInfo {
pub latest: String,
}

impl DocsInfo {
pub fn get_info() -> Self {
let info = include_str!(concat!(
env!("CARGO_MANIFEST_DIR"),
"/../content/docs/info.toml"
));
toml::from_str(info).unwrap()
}
}
25 changes: 4 additions & 21 deletions website/xtask/src/postprocess_playground.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
use anyhow::{Context, Result};
use std::{fs, io::Write, path::PathBuf};

use crate::docs_info::DocsInfo;

pub fn run(staging_dir: &str) -> Result<()> {
let index_path: PathBuf = [staging_dir, "index.html"].iter().collect();

let index = fs::read_to_string(&index_path).context("Failed to read index.html")?;
let header = get_header()?;
let header = include_str!(concat!(
env!("CARGO_MANIFEST_DIR"),
"/../templates/header.html"
));
let mobile_nav = concat!(
include_str!(concat!(
env!("CARGO_MANIFEST_DIR"),
Expand All @@ -32,21 +33,3 @@ pub fn run(staging_dir: &str) -> Result<()> {

Ok(())
}

fn get_header() -> Result<String> {
// The header is a Zola template, but the playground isn't rendered with Zola,
// so it needs to be patched manually.
let header_template = include_str!(concat!(
env!("CARGO_MANIFEST_DIR"),
"/../templates/header.html"
));
let latest = DocsInfo::get_info().latest;
let mut result = String::with_capacity(header_template.len());
for line in header_template.lines() {
if line.starts_with("{%") {
continue;
}
result.push_str(&line.replace(r"{{latest}}", &latest));
}
Ok(result)
}

0 comments on commit 762b4e2

Please sign in to comment.