Skip to content

Commit

Permalink
Link to character pages
Browse files Browse the repository at this point in the history
  • Loading branch information
Cantido committed Jan 21, 2024
1 parent 424ac22 commit 85b0e5e
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 4 deletions.
1 change: 1 addition & 0 deletions src/birthdays.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ query BirthdaysQuery ($user:String!, $page:Int!) {
name {
full
}
siteUrl
dateOfBirth {
year
month
Expand Down
2 changes: 2 additions & 0 deletions src/http.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ async fn get_index(State(state): State<Arc<AppState<'_>>>) -> Result<Response, R
#[derive(Debug, Serialize)]
struct CharacterHtml {
name: String,
url: String,
til_next_iso: String,
til_next_rounded: String,
birthday: String,
Expand All @@ -111,6 +112,7 @@ impl CharacterHtml {
let til_next = character.birthday().til_next(&now);

Ok(Self {
url: character.url.to_string(),
next_occurrence: next_occurrence.to_string(),
til_next_iso: duration_to_iso(&til_next),
til_next_rounded: format!("{:.0}", til_next),
Expand Down
8 changes: 6 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,14 +130,16 @@ impl fmt::Display for Birthday {
#[derive(Clone, Eq, PartialEq, Hash, Debug, Serialize)]
pub struct Character {
name: String,
url: String,
birthday: Birthday,
}

impl Character {
/// Create a new Character.
pub fn new(name: &str, birthday: Birthday) -> Self {
pub fn new(name: &str, url: &str, birthday: Birthday) -> Self {
Self {
name: name.to_string(),
url: url.to_string(),
birthday,
}
}
Expand Down Expand Up @@ -269,7 +271,9 @@ pub async fn get_waifu_birthdays(username: &str) -> Result<Vec<Character>> {

let name = node.name.as_ref()?.full.as_ref()?.to_string();

let character = Character { name, birthday };
let url = node.site_url.as_ref()?.to_string();

let character = Character { name, url, birthday };

Some(character)
} else {
Expand Down
2 changes: 1 addition & 1 deletion templates/character_list.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<tbody>
{{#each characters}}
<tr>
<td>{{name}}</td>
<td><a href="{{url}}" target="_blank" rel="noopener noreferrer">{{name}}</a></td>
<td><time datetime="{{til_next_iso}}">{{til_next_rounded}}</time></td>
<td><time datetime="{{birthday_iso}}">{{birthday}}</time></td>
<td><time datetime="{{next_occurrence}}">{{next_occurrence}}</time></td>
Expand Down
2 changes: 1 addition & 1 deletion templates/character_list_today.hbs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<ul>
{{#each characters}}
<li>{{name}}</li>
<li><a href="{{url}}" target="_blank" rel="noopener noreferrer">{{name}}</a></li>
{{/each}}
</ul>

0 comments on commit 85b0e5e

Please sign in to comment.