Skip to content

Commit 974523e

Browse files
mevenchriskrycho
authored andcommitted
Add relevant titles to pages
- resolves #330. - resolves #531.
1 parent e096077 commit 974523e

File tree

1 file changed

+15
-7
lines changed

1 file changed

+15
-7
lines changed

src/main.rs

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ use std::collections::HashMap;
2323
use std::fs;
2424
use std::fs::File;
2525
use std::io::prelude::*;
26+
use std::iter::FromIterator;
2627
use std::path::{Path, PathBuf};
2728

2829
use rand::seq::SliceRandom;
@@ -61,6 +62,13 @@ struct UsersContext {
6162
data: Vec<Vec<User>>,
6263
}
6364

65+
fn get_title(page_name: &str) -> String {
66+
let mut v: Vec<char> = page_name.replace("-", " ").chars().collect();
67+
v[0] = v[0].to_uppercase().nth(0).unwrap();
68+
let page_name = String::from_iter(v);
69+
format!("{} - Rust programming language", page_name).to_string()
70+
}
71+
6472
#[get("/")]
6573
fn index() -> Template {
6674
#[derive(Serialize)]
@@ -73,7 +81,7 @@ fn index() -> Template {
7381
}
7482

7583
let page = "index".to_string();
76-
let title = format!("Rust - {}", page).to_string();
84+
let title = "Rust programming language".to_string();
7785

7886
let context = Context {
7987
page: page.clone(),
@@ -94,7 +102,7 @@ fn files(file: PathBuf) -> Option<NamedFile> {
94102
#[get("/<category>")]
95103
fn category(category: Category) -> Template {
96104
let page = category.index();
97-
let title = format!("Rust - {}", page).to_string();
105+
let title = get_title(&category.name());
98106
let context = Context {
99107
page: category.name().to_string(),
100108
title,
@@ -107,7 +115,7 @@ fn category(category: Category) -> Template {
107115
#[get("/governance")]
108116
fn governance() -> Template {
109117
let page = "governance/index".to_string();
110-
let title = format!("Rust - {}", page).to_string();
118+
let title = "Governance - Rust programming language".to_string();
111119
let context = GroupContext {
112120
page: page.clone(),
113121
title,
@@ -134,8 +142,8 @@ fn load_governance_data() -> HashMap<String, Vec<Group>> {
134142
#[get("/governance/<t>/<subject>", rank = 2)]
135143
fn team(t: String, subject: String) -> Template {
136144
let page = "governance/group".to_string();
137-
let title = format!("Rust - {}", page).to_string();
138145
let t = get_type_from_string(&t).expect("couldn't figure out group type from path string");
146+
let title = get_title(&format!("{} team", subject));
139147
let context = GroupContext {
140148
page: page.clone(),
141149
title,
@@ -178,7 +186,7 @@ fn load_group_data(t: GroupType, group: &str) -> HashMap<String, Vec<Group>> {
178186
#[get("/production/users")]
179187
fn production() -> Template {
180188
let page = "production/users".to_string();
181-
let title = format!("Rust - {}", page).to_string();
189+
let title = "Users - Rust programming language".to_string();
182190
let context = UsersContext {
183191
page: page.clone(),
184192
title,
@@ -199,7 +207,7 @@ fn load_users_data() -> Vec<Vec<User>> {
199207
#[get("/<category>/<subject>", rank = 4)]
200208
fn subject(category: Category, subject: String) -> Template {
201209
let page = format!("{}/{}", category.name(), subject.as_str()).to_string();
202-
let title = format!("Rust - {}", page).to_string();
210+
let title = get_title(&subject);
203211
let context = Context {
204212
page: subject,
205213
title,
@@ -212,7 +220,7 @@ fn subject(category: Category, subject: String) -> Template {
212220
#[catch(404)]
213221
fn not_found() -> Template {
214222
let page = "404";
215-
let title = format!("Rust - {}", page).to_string();
223+
let title = format!("{} - Rust programming language", page).to_string();
216224
let context = Context {
217225
page: "404".to_string(),
218226
title,

0 commit comments

Comments
 (0)