Skip to content

Commit 7ec6986

Browse files
committed
Add templates
1 parent 74ab992 commit 7ec6986

File tree

11 files changed

+392
-8
lines changed

11 files changed

+392
-8
lines changed

website/config.toml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,12 @@ build_search_index = false
77

88
[markdown]
99
highlight_code = true
10+
highlight_theme = "ayu-mirage"
11+
12+
insert_anchor_links = "heading"
13+
14+
[extra]
15+
logo_path = "images/happy_ferris.svg"
1016

1117
[[extra.menu_items]]
1218
name = "Home"

website/content/_index.md

Lines changed: 143 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,143 @@
1+
+++
2+
+++
3+
4+
Greetings and welcome to Rustlings.
5+
This project contains small exercises to get you used to reading and writing Rust code.
6+
This includes reading and responding to compiler messages!
7+
8+
It is recommended to do the Rustlings exercises in parallel to reading [the official Rust book](https://doc.rust-lang.org/book/), the most comprehensive resource for learning Rust 📚️
9+
10+
<!-- toc -->
11+
12+
## Getting Started
13+
14+
### Installing Rust
15+
16+
Before installing Rustlings, you need to have the **latest version of Rust** installed.
17+
Visit [www.rust-lang.org/tools/install](https://www.rust-lang.org/tools/install) for further instructions on installing Rust.
18+
This will also install _Cargo_, Rust's package/project manager.
19+
20+
> 🐧 If you are on Linux, make sure you have installed `gcc` (for a linker).
21+
>
22+
> Deb: `sudo apt install gcc`
23+
>
24+
> Dnf: `sudo dnf install gcc`
25+
26+
> 🍎 If you are on MacOS, make sure you have installed Xcode and its developer tools by running `xcode-select --install`.
27+
28+
### Installing Rustlings
29+
30+
The following command will download and compile Rustlings:
31+
32+
```bash
33+
cargo install rustlings
34+
```
35+
36+
<details>
37+
<summary><strong>If the installation fails…</strong> (<em>click to expand</em>)</summary>
38+
39+
- Make sure you have the latest Rust version by running `rustup update`
40+
- Try adding the `--locked` flag: `cargo install rustlings --locked`
41+
- Otherwise, please [report the issue](https://github.com/rust-lang/rustlings/issues/new)
42+
43+
</details>
44+
45+
### Initialization
46+
47+
After installing Rustlings, run the following command to initialize the `rustlings/` directory:
48+
49+
```bash
50+
rustlings init
51+
```
52+
53+
<details>
54+
<summary><strong>If the command <code>rustlings</code> can't be found…</strong> (<em>click to expand</em>)</summary>
55+
56+
You are probably using Linux and installed Rust using your package manager.
57+
58+
Cargo installs binaries to the directory `~/.cargo/bin`.
59+
Sadly, package managers often don't add `~/.cargo/bin` to your `PATH` environment variable.
60+
61+
The solution is to …
62+
63+
- either add `~/.cargo/bin` manually to `PATH`
64+
- or to uninstall Rust from the package manager and install it using the official way with `rustup`: https://www.rust-lang.org/tools/install
65+
66+
</details>
67+
68+
Now, go into the newly initialized directory and launch Rustlings for further instructions on getting started with the exercises:
69+
70+
```bash
71+
cd rustlings/
72+
rustlings
73+
```
74+
75+
## Working environment
76+
77+
### Editor
78+
79+
Our general recommendation is [VS Code](https://code.visualstudio.com/) with the [rust-analyzer plugin](https://marketplace.visualstudio.com/items?itemName=rust-lang.rust-analyzer).
80+
But any editor that supports [rust-analyzer](https://rust-analyzer.github.io/) should be enough for working on the exercises.
81+
82+
### Terminal
83+
84+
While working with Rustlings, please use a modern terminal for the best user experience.
85+
The default terminal on Linux and Mac should be sufficient.
86+
On Windows, we recommend the [Windows Terminal](https://aka.ms/terminal).
87+
88+
## Doing exercises
89+
90+
The exercises are sorted by topic and can be found in the subdirectory `exercises/<topic>`.
91+
For every topic, there is an additional `README.md` file with some resources to get you started on the topic.
92+
We highly recommend that you have a look at them before you start 📚️
93+
94+
Most exercises contain an error that keeps them from compiling, and it's up to you to fix it!
95+
Some exercises contain tests that need to pass for the exercise to be done ✅
96+
97+
Search for `TODO` and `todo!()` to find out what you need to change.
98+
Ask for hints by entering `h` in the _watch mode_ 💡
99+
100+
### Watch Mode
101+
102+
After the [initialization](#initialization), Rustlings can be launched by simply running the command `rustlings`.
103+
104+
This will start the _watch mode_ which walks you through the exercises in a predefined order (what we think is best for newcomers).
105+
It will rerun the current exercise automatically every time you change the exercise's file in the `exercises/` directory.
106+
107+
<details>
108+
<summary><strong>If detecting file changes in the <code>exercises/</code> directory fails…</strong> (<em>click to expand</em>)</summary>
109+
110+
> You can add the **`--manual-run`** flag (`rustlings --manual-run`) to manually rerun the current exercise by entering `r` in the watch mode.
111+
>
112+
> Please [report the issue](https://github.com/rust-lang/rustlings/issues/new) with some information about your operating system and whether you run Rustlings in a container or virtual machine (e.g. WSL).
113+
114+
</details>
115+
116+
### Exercise List
117+
118+
In the [watch mode](#watch-mode) (after launching `rustlings`), you can enter `l` to open the interactive exercise list.
119+
120+
The list allows you to…
121+
122+
- See the status of all exercises (done or pending)
123+
- `c`: Continue at another exercise (temporarily skip some exercises or go back to a previous one)
124+
- `r`: Reset status and file of the selected exercise (you need to _reload/reopen_ its file in your editor afterwards)
125+
126+
See the footer of the list for all possible keys.
127+
128+
## Questions?
129+
130+
If you need any help while doing the exercises and the builtin-hints aren't helpful, feel free to ask in the [_Q&A_ category of the discussions](https://github.com/rust-lang/rustlings/discussions/categories/q-a?discussions_q=) if your question wasn't asked yet 💡
131+
132+
## Continuing On
133+
134+
Once you've completed Rustlings, put your new knowledge to good use!
135+
Continue practicing your Rust skills by building your own projects, contributing to Rustlings, or finding other open-source projects to contribute to.
136+
137+
## Uninstalling Rustlings
138+
139+
If you want to remove Rustlings from your system, run the following command:
140+
141+
```bash
142+
cargo uninstall rustlings
143+
```
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
+++
2+
title = "Custom Exercises"
3+
+++
4+
5+
Custom exercises are a set of exercises maintained by the community.
6+
You can use the same `rustlings` program that you installed with `cargo install rustlings` to run them:
7+
8+
- 🇯🇵 [Japanese Rustlings](https://github.com/sotanengel/rustlings-jp):A Japanese translation of the Rustlings exercises.
9+
- 🇨🇳 [Simplified Chinese Rustlings](https://github.com/SandmeyerX/rustlings-zh-cn): A simplified Chinese translation of the Rustlings exercises.
10+
11+
Do you want to create your own set of Rustlings exercises to focus on some specific topic?
12+
Or do you want to translate the original Rustlings exercises?
13+
14+
<!-- toc -->
15+
16+
The support of Rustlings for custom exercises allows you to create your own set of Rustlings exercises to focus on some specific topic.
17+
You could also offer a translation of the original Rustlings exercises as custom exercises.
18+
19+
## Getting started
20+
21+
To create custom exercises, install Rustlings and run `rustlings dev new PROJECT_NAME`.
22+
This command will, similar to `cargo new PROJECT_NAME`, create a template directory called `PROJECT_NAME` with all what you need to get started.
23+
24+
Read the comments in the generated `info.toml` file to understand its format.
25+
It allows you to set a custom welcome and final message and specify the metadata of every exercise.
26+
27+
## Create an exercise
28+
29+
Here is an example of the metadata of one file:
30+
31+
```toml
32+
[[exercises]]
33+
name = "intro1"
34+
hint = """
35+
To finish this exercise, you need to …
36+
This link might help you …"""
37+
```
38+
39+
After entering this in `info.toml`, create the file `intro1.rs` in the `exercises/` directory.
40+
The exercise needs to contain a `main` function, but it can be empty.
41+
Adding tests is recommended.
42+
Look at the official Rustlings exercises for inspiration.
43+
44+
You can optionally add a solution file `intro1.rs` to the `solutions/` directory.
45+
46+
Now, run `rustlings dev check`.
47+
It will tell you about any issues with your exercises.
48+
For example, it will tell you to run `rustlings dev update` to update the `Cargo.toml` file to include the new exercise `intro1`.
49+
50+
`rustlings dev check` will also run your solutions (if you have any) to make sure that they run successfully.
51+
52+
That's it!
53+
You finished your first exercise 🎉
54+
55+
## Publish
56+
57+
Now, add more exercises and publish them as a Git repository.
58+
59+
Users just have to clone that repository and run `rustlings` in it to start working on your set of exercises just like the official ones.
60+
61+
One difference to the official exercises is that the solution files will not be hidden until the user finishes an exercise.
62+
But you can trust the users to not look at the solution too early 😉
63+
64+
## Share
65+
66+
After publishing your set of exercises, open an issue or a pull request in the official Rustlings repository to link to your project in the README 😃

website/input.css

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,22 @@
22

33
@layer base {
44
h1 {
5-
@apply text-4xl mt-3 mb-3 text-gray-50 font-bold;
5+
@apply text-4xl mt-3 mb-3 font-bold;
66
}
77
h2 {
8-
@apply text-3xl mt-4 mb-1.5 text-gray-50 font-bold;
8+
@apply text-3xl mt-4 mb-1.5 font-bold;
99
}
1010
h3 {
11-
@apply text-2xl mt-5 mb-1.5 text-gray-50 font-bold;
11+
@apply text-2xl mt-5 mb-1.5 font-bold;
1212
}
1313
h4 {
14-
@apply text-xl mt-6 mb-1.5 text-gray-50 font-bold;
14+
@apply text-xl mt-6 mb-1.5 font-bold;
1515
}
1616
p {
1717
@apply mb-2;
1818
}
1919
a {
20-
@apply text-[#F74C00] underline hover:decoration-orange-400 transition duration-300;
20+
@apply text-[#FFC832] underline hover:decoration-orange-400 transition duration-300;
2121
}
2222
ul {
2323
@apply mt-2 mb-3 ml-1 list-disc list-inside marker:text-sky-600;
@@ -41,11 +41,11 @@
4141
@apply max-w-full w-full h-full mx-auto my-5 object-contain md:w-3/4 lg:w-3/5 rounded-sm shadow-sm;
4242
}
4343
blockquote {
44-
@apply p-4 my-3 border-s-4 border-gray-300 bg-gray-800 italic;
44+
@apply px-3 pt-2 pb-0.5 my-4 border-s-4 border-white/80 bg-white/7 rounded-sm italic;
4545
}
4646

4747
pre {
48-
@apply px-2 pt-2 pb-px overflow-x-auto text-sm sm:text-base rounded-sm mt-2 mb-4 after:content-[attr(data-lang)] after:text-[8px] after:opacity-40 selection:bg-gray-500/75;
48+
@apply px-2 pt-2 pb-px overflow-x-auto text-sm sm:text-base rounded-sm mt-2 mb-4 after:content-[attr(data-lang)] after:text-[8px] after:opacity-40 selection:bg-white/15;
4949
}
5050
pre code mark {
5151
@apply pb-0.5 pt-1 pr-px text-inherit rounded-xs;

website/justfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@ zola:
22
zola serve --open
33

44
tailwind:
5-
fnm exec --using latest npx @tailwindcss/cli -i input.css -o static/main.css
5+
fnm exec --using latest npx @tailwindcss/cli -w -i input.css -o static/main.css

website/templates/404.html

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{% extends "base.html" %}
2+
3+
{% import "macros.html" as macros %}
4+
5+
{% block content %}
6+
<div class="flex flex-col mx-auto text-center">
7+
<h1>DON'T PANIC!</h1>
8+
<h2>404: Page not found!</h2>
9+
10+
<img class="max-h-[50vh]"
11+
src="{{ get_url(path='images/panic.svg') | safe }}"
12+
alt="">
13+
14+
{{ macros::btn(link=get_url(path="/") , content="Back to the homepage") }}
15+
</div>
16+
{% endblock %}

website/templates/anchor-link.html

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
<a class="text-white no-underline transition-none hover:underline"
2+
href="#{{ id }}"></a>

website/templates/base.html

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8">
5+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
6+
7+
{%- set timestamp = now(timestamp=true) -%}
8+
9+
{%- if page.title -%}
10+
{% set_global title = page.title %}
11+
{%- elif section.title -%}
12+
{% set_global title = section.title %}
13+
{%- else -%}
14+
{% set_global title = config.title %}
15+
{%- endif -%}
16+
17+
{%- if page.description -%}
18+
{% set_global description = page.description %}
19+
{%- elif section.description -%}
20+
{% set_global description = section.description %}
21+
{%- else -%}
22+
{% set_global description = config.description %}
23+
{%- endif -%}
24+
25+
{%- if page.permalink -%}
26+
{% set_global permalink = page.permalink %}
27+
{%- elif section.permalink -%}
28+
{% set_global permalink = section.permalink %}
29+
{%- endif %}
30+
31+
<title>{%- block title -%}{{- title -}}{%- endblock -%}</title>
32+
33+
<meta name="description"
34+
content="{%- block description -%}{{- description -}}{%- endblock -%}">
35+
36+
<link rel="icon"
37+
type="image/x-icon"
38+
href="{{ get_url(path=config.extra.logo_path) | safe }}?v={{ timestamp }}">
39+
40+
<link href="{{ get_url(path='main.css') | safe }}?v={{ timestamp }}"
41+
rel="stylesheet">
42+
43+
<meta property="og:title" content="{{ title }}">
44+
<meta property="og:description" content="{{ description }}">
45+
<meta property="og:image"
46+
content="{{ get_url(path=config.extra.logo_path) | safe }}?v={{ timestamp }}">
47+
{% if permalink %}<meta property="og:url" content="{{ permalink | safe }}">{% endif %}
48+
</head>
49+
50+
<body class="flex flex-col p-3 mx-auto min-h-screen text-lg text-white break-words bg-[#2A3439] lg:px-5 2xl:container">
51+
<header class="flex gap-x-6 items-center py-2 px-2.5 mb-1 bg-black/30 rounded-full">
52+
<a class="transition duration-500 hover:scale-110"
53+
href="{{ get_url(path='/') | safe }}"
54+
aria-hidden="true">
55+
<img class="m-0 w-12 h-12 rounded-full"
56+
src="{{ get_url(path=config.extra.logo_path) | safe }}"
57+
alt="">
58+
</a>
59+
60+
<nav class="flex gap-x-6 items-center font-bold">
61+
{% for menu_item in config.extra.menu_items %}
62+
<a class="p-1 no-underline" href="{{ menu_item.url | safe }}">{{ menu_item.name }}</a>
63+
{% endfor %}
64+
</nav>
65+
</header>
66+
67+
<main class="leading-relaxed">
68+
{% block content %}{% endblock %}
69+
</main>
70+
71+
<footer class="pt-2 pb-3 mt-auto">
72+
<img class="m-0 mx-auto w-20 h-20"
73+
src="{{ get_url(path='images/happy_ferris.svg') | safe }}"
74+
alt="">
75+
76+
<nav class="flex flex-col gap-y-3 justify-around py-3 text-center bg-black/30 rounded-sm sm:flex-row sm:rounded-full">
77+
{% for footer_item in config.extra.footer_items %}
78+
<a class="text-sm no-underline" href="{{ footer_item.url | safe }}">{{ footer_item.name }}</a>
79+
{% endfor %}
80+
</nav>
81+
</footer>
82+
</body>
83+
</html>

website/templates/index.html

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{% extends "base.html" %}
2+
3+
{% import "macros.html" as macros %}
4+
5+
{% block content %}
6+
<div class="m-3">
7+
<h1>Rustlings</h1>
8+
9+
{{ section.content | replace(from="<!-- toc -->", to=macros::toc() ) | safe }}
10+
</div>
11+
{% endblock %}

0 commit comments

Comments
 (0)