Skip to content

Commit

Permalink
Fix language links not parsing correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
Builditluc committed Oct 6, 2024
1 parent 3b0425c commit 60d45c6
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
3 changes: 3 additions & 0 deletions src/ui/stateful_list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,9 @@ impl<T> StatefulList<T> {
}

pub fn selected(&self) -> Option<&T> {
if self.state.selected().unwrap_or_default() >= self.items.len() {
return None;
}
self.state.selected().map(|i| &self.items[i])
}
}
15 changes: 14 additions & 1 deletion wiki-api/src/page.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@ use crate::{
use anyhow::{anyhow, Context, Result};
use reqwest::{Client, Response};
use scraper::Html;
use serde::Deserialize;
use serde::{de, Deserialize, Deserializer};
use std::fmt::Display;
use std::str::FromStr;
use tracing::{debug, warn};
use url::Url;

Expand Down Expand Up @@ -101,12 +102,24 @@ struct LanguageLinkInt {
#[serde(rename = "langname")]
name: String,
#[serde(rename = "lang")]
#[serde(deserialize_with = "language_from_str")]
language: Language,
autonym: String,
title: String,
url: Url,
}

fn language_from_str<'de, T, D>(deserializer: D) -> Result<T, D::Error>
where
T: FromStr,
T::Err: Display,
D: Deserializer<'de>,
{
String::deserialize(deserializer)?
.parse()
.map_err(de::Error::custom)
}

#[derive(Debug, Deserialize, Clone, PartialEq, Eq)]
pub struct Section {
#[serde(skip_deserializing)]
Expand Down

0 comments on commit 60d45c6

Please sign in to comment.