Skip to content

Commit

Permalink
Merge pull request #12 from koto-lang/rename-latest
Browse files Browse the repository at this point in the history
Move docs/latest -> docs/0.14
  • Loading branch information
irh authored Apr 22, 2024
2 parents 926e782 + f192ce3 commit 37d169b
Show file tree
Hide file tree
Showing 33 changed files with 63 additions and 72 deletions.
26 changes: 13 additions & 13 deletions website/content/docs/0.13/language/_index.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@ As an example, this simple script prints a friendly greeting.

````koto
name = 'World'
print 'Hello, $name!'
print 'Hello, {name}!'
````

{% example_playground_link(version = "0.13") %}
name = 'World'
print 'Hello, $name!'
print 'Hello, {name}!'

{% end %}
### Comments
Expand Down Expand Up @@ -1437,21 +1437,21 @@ with `...` available for capturing the rest of the sequence.
match ['a', 'b', 'c'].extend [1, 2, 3]
('a', 'b') then "A list containing 'a' and 'b'"
(1, ...) then "Starts with '1'"
(..., 'y', last) then "Ends with 'y' followed by '$last'"
(..., 'y', last) then "Ends with 'y' followed by '{last}'"
('a', x, others...) then
"Starts with 'a', followed by '{x}', then {size others} others"
unmatched then "other: $unmatched"
unmatched then "other: {unmatched}"
# -> Starts with 'a', followed by 'b', then 4 others
````

{% example_playground_link(version = "0.13") %}
print match ['a', 'b', 'c'].extend [1, 2, 3]
('a', 'b') then "A list containing 'a' and 'b'"
(1, ...) then "Starts with '1'"
(..., 'y', last) then "Ends with 'y' followed by '$last'"
(..., 'y', last) then "Ends with 'y' followed by '{last}'"
('a', x, others...) then
"Starts with 'a', followed by '{x}', then {size others} others"
unmatched then "other: $unmatched"
unmatched then "other: {unmatched}"
# -> Starts with 'a', followed by 'b', then 4 others

{% end %}
Expand Down Expand Up @@ -1770,7 +1770,7 @@ for x in i
{% end %}
### Iterator Consumers

Iterators can be also be *consumed* using functions like
Iterators can also be *consumed* using functions like
[`.to_list()`](../core/iterator#to_list) and [`.to_tuple()`](../core/iterator#to_tuple),
allowing the output of an iterator to be easily captured in a container.

Expand Down Expand Up @@ -2074,7 +2074,7 @@ r.start()
r.end()
# -> null
# Create an unbounded range up to and including 10
# Create an unbounded range up to and including 100
r = ..=100
r.start()
# -> null
Expand Down Expand Up @@ -3486,7 +3486,7 @@ Single values can be assigned to and exported at the same time:
# my_module.koto #
##################
export say_hello = |name| 'Hello, $name!'
export say_hello = |name| 'Hello, {name}!'
##################
##################
Expand All @@ -3502,7 +3502,7 @@ say_hello 'Koto'
# my_module.koto #
##################

export say_hello = |name| 'Hello, $name!'
export say_hello = |name| 'Hello, {name}!'

##################
##################
Expand Down Expand Up @@ -3566,7 +3566,7 @@ the use of `export` is optional when adding entries to the module's metamap.
# my_module.koto #
##################
export say_hello = |name| 'Hello, $name!'
export say_hello = |name| 'Hello, {name}!'
@main = || # Equivalent to export @main =
print '`my_module` initialized'
Expand All @@ -3592,7 +3592,7 @@ say_hello 'Koto'
# my_module.koto #
##################

export say_hello = |name| 'Hello, $name!'
export say_hello = |name| 'Hello, {name}!'

@main = || # Equivalent to export @main =
print '`my_module` initialized'
Expand Down Expand Up @@ -3622,4 +3622,4 @@ e.g. When an `import foo` expression is run, then a `foo.koto` file will be
looked for in the same location as the current script,
and if `foo.koto` isn't found then the runtime will look for `foo/main.koto`.

---
---
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
1 change: 1 addition & 0 deletions website/content/docs/info.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
latest = "0.14"
6 changes: 3 additions & 3 deletions website/content/news/2024-04-18_koto-0.14.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ or you could check out the [language guide][guide].


[about]: /about
[api-docs]: /docs/latest/api
[api-docs]: /docs/0.14/api
[crates]: https://crates.io/crates/koto/0.14.0
[guide]: /docs/latest/language
[lib-docs]:/docs/latest/libs
[guide]: /docs/0.14/language
[lib-docs]:/docs/0.14/libs
12 changes: 6 additions & 6 deletions website/justfile
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,12 @@ update-koto:
git add ../modules/koto
git commit -m "Update to the latest version of Koto"

version-snapshot new old: docs playground-release
cargo xtask version-snapshot {{new}} {{old}}
git add content/docs/latest
git add content/docs/{{old}}
git add static/play-{{new}}
git commit -m "Snapshot of version {{new}}"
version-snapshot version: docs playground-release
cargo xtask version-snapshot {{version}}
git add content/docs/{{version}}
git add static/play-{{version}}
git add content/docs/info.toml
git commit -m "Snapshot of version {{version}}"

watch command:
cargo watch -s "just {{command}}"
Expand Down
6 changes: 5 additions & 1 deletion website/templates/header.html
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
{% set docs_info = load_data(path="content/docs/info.toml") %}

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

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

<li>
<a class="uk-navbar-item uk-text-capitalize" href="/docs">Docs</a>
<a class="uk-navbar-item uk-text-capitalize" href="/docs/{{docs_info["latest"]}}">
Docs
</a>
</li>

<li>
Expand Down
4 changes: 3 additions & 1 deletion website/templates/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

{% block content %}

{% set docs_info = load_data(path="content/docs/info.toml") %}

<section class="uk-section">
<div class="uk-container uk-text-center uk-padding-large">
<img class="uk-img main-logo" src="/koto.svg" />
Expand All @@ -19,7 +21,7 @@
<a
class="uk-button uk-button-default uk-button-large
uk-text-capitalize"
href="/docs/latest/language/"
href="/docs/{{docs_info["latest"]}}/language/"
>Guide</a>
</div>

Expand Down
8 changes: 3 additions & 5 deletions website/xtask/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,9 @@ fn try_main() -> Result<()> {
Some(staging_dir) => postprocess_playground::run(staging_dir),
None => bail!("Missing argument: staging dir"),
},
Some("version-snapshot") => match (args().nth(2).as_ref(), args().nth(3).as_ref()) {
(Some(new_version), Some(old_version)) => {
version_snapshot::run(new_version, old_version)
}
_ => bail!("Missing arguments: new_version old_version"),
Some("version-snapshot") => match args().nth(2).as_ref() {
Some(version) => version_snapshot::run(version),
_ => bail!("Missing argument: version"),
},
Some("help" | "--help") => {
println!("{HELP}");
Expand Down
72 changes: 29 additions & 43 deletions website/xtask/src/version_snapshot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,55 +12,38 @@ use std::{
use anyhow::{bail, Context, Result};
use walkdir::WalkDir;

pub fn run(new_version: &str, old_version: &str) -> Result<()> {
let old_docs_target = format!("content/docs/{old_version}");
let old_docs_target_path = PathBuf::from(&old_docs_target);
let new_docs_target = format!("content/docs/latest");
let new_docs_target_path = PathBuf::from(&new_docs_target);
let playground_target = format!("static/play-{new_version}");
pub fn run(version: &str) -> Result<()> {
let docs_target = format!("content/docs/{version}");
let docs_target_path = PathBuf::from(&docs_target);
let playground_target = format!("static/play-{version}");
let playground_target_path = PathBuf::from(&playground_target);
let copy_options = fs_extra::dir::CopyOptions::new().copy_inside(true);
let copy_options = fs_extra::dir::CopyOptions::new().content_only(true);

// Copy latest -> old
if old_docs_target_path.exists() {
fs::remove_dir_all(&old_docs_target_path)
.with_context(|| format!("failed to remove '{old_docs_target}'"))?;
// Copy next -> version
if docs_target_path.exists() {
fs::remove_dir_all(&docs_target_path)
.with_context(|| format!("failed to remove '{docs_target}'"))?;
}
fs_extra::copy_items(
&[new_docs_target.clone()],
&old_docs_target_path,
&copy_options,
)
.with_context(|| format!("failed to copy docs to '{old_docs_target}'"))?;
println!("Latest docs copied to '{old_docs_target}'");

// Copy next -> latest
if new_docs_target_path.exists() {
fs::remove_dir_all(&new_docs_target_path)
.with_context(|| format!("failed to remove '{new_docs_target}'"))?;
}
fs_extra::copy_items(
&["content/docs/next"],
&new_docs_target_path,
&copy_options,
)
.with_context(|| format!("failed to copy docs to '{new_docs_target}'"))?;
println!("New docs copied to '{new_docs_target}'");
fs::create_dir(&docs_target_path)
.with_context(|| format!("failed to create '{docs_target}'"))?;
fs_extra::dir::copy("content/docs/next", &docs_target, &copy_options)
.with_context(|| format!("failed to copy docs to '{docs_target}'"))?;
println!("Docs copied from docs/next to '{docs_target}'");

// Copy the playground
if playground_target_path.exists() {
fs::remove_dir_all(&playground_target_path)
.with_context(|| format!("failed to remove '{playground_target}'"))?;
}
fs_extra::copy_items(&["static/play"], &playground_target_path, &copy_options)
fs_extra::dir::copy("static/play", &playground_target_path, &copy_options)
.with_context(|| format!("Error while copying the playground to {playground_target}",))?;
println!("Playground copied to '{playground_target}'",);

// Post-process the copied docs
let playground_link_search = "example_playground_link()";
let playground_link_replacement =
format!("example_playground_link(version = \"{new_version}\")");
for f in WalkDir::new(&new_docs_target_path) {
let f = f.with_context(|| format!("error while traversing {new_docs_target}",))?;
let playground_link_replacement = format!("example_playground_link(version = \"{version}\")");
for f in WalkDir::new(&docs_target_path) {
let f = f.with_context(|| format!("error while traversing {docs_target}",))?;
let path = f.path();
if !path.is_file() {
continue;
Expand All @@ -70,10 +53,10 @@ pub fn run(new_version: &str, old_version: &str) -> Result<()> {
fs::remove_file(path)?;
}

if path.parent() == Some(&new_docs_target_path)
if path.parent() == Some(&docs_target_path)
&& path.file_name() == Some(OsStr::new("_index.md"))
{
update_index_title(path, new_version)?;
update_index_title(path, version)?;
continue;
}

Expand All @@ -85,16 +68,19 @@ pub fn run(new_version: &str, old_version: &str) -> Result<()> {

// Post-process the copied playground
let playground_index = PathBuf::from(&format!("{playground_target}/index.html"));
search_and_replace_in_file(
&playground_index,
"/play/",
&format!("/play-{new_version}/"),
)?;
search_and_replace_in_file(&playground_index, "/play/", &format!("/play-{version}/"))?;
println!(
"Updated playground references in '{}'",
playground_index.to_string_lossy()
);

// Write the latest version in docs/info.toml
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}\"")?;
println!("docs/info.toml updated");

Ok(())
}

Expand Down

0 comments on commit 37d169b

Please sign in to comment.