Skip to content

Commit 04c2307

Browse files
authored
feat: add media URLs to <entry> nodes (#1202)
1 parent a8d61e6 commit 04c2307

File tree

21 files changed

+61
-46
lines changed

21 files changed

+61
-46
lines changed

lib/src/format/json/pronunciation.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,5 @@ pub struct PronunciationJSON {
1212
pub value: String,
1313

1414
#[serde(skip_serializing_if = "Vec::is_empty")]
15-
pub urls: Vec<MediaURLJSON>,
15+
pub media: Vec<MediaURLJSON>,
1616
}

lib/src/format/md/pronunciation.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@ pub fn write_pronunciation(
1919
lines.push(pron_text);
2020

2121
// Add URLs as markdown links if they exist
22-
if !pronunciation.urls.is_empty() {
22+
if !pronunciation.media.is_empty() {
2323
let url_lines: Vec<String> = pronunciation
24-
.urls
24+
.media
2525
.iter()
2626
.map(|url| {
2727
let desc = url.description.as_deref().unwrap_or("Audio");

lib/src/format/sql/pronunciations.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ pub fn insert_pronunciation(
108108
);
109109

110110
// Insert any URLs
111-
for url in &pronunciation.urls {
111+
for url in &pronunciation.media {
112112
let url_id = ID::default();
113113

114114
builder.add_insert(

lib/src/models/entry.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use rkyv::{deserialize, to_bytes};
22

33
use crate::{error::Error, serializable, Etymology};
44

5-
use super::EntryRef;
5+
use super::{EntryRef, MediaURL};
66

77
serializable! {
88
#[serde(rename = "entry")]
@@ -16,6 +16,9 @@ serializable! {
1616

1717
#[serde(default, rename = "ety")]
1818
pub etymologies: Vec<Etymology>,
19+
20+
#[serde(default, rename = "media")]
21+
pub media: Vec<MediaURL>,
1922
}
2023
}
2124

lib/src/models/pronunciation.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,6 @@ serializable! {
1111

1212
#[serde(default, rename = "url")]
1313
#[serde(skip_serializing_if = "Vec::is_empty")]
14-
pub urls: Vec<MediaURL>,
14+
pub media: Vec<MediaURL>,
1515
}
1616
}

lib/tests/merge.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ mod merge_tests {
1313
name: None,
1414
entries: hash_map! {
1515
String::from("dog") => Entry {
16+
media: vec![],
1617
term: "dog".to_string(),
1718
see_also: None,
1819
etymologies: vec![
@@ -51,6 +52,7 @@ mod merge_tests {
5152
entries: hash_map! {
5253
"cat".to_string()=>
5354
Entry {
55+
media: vec![],
5456
see_also: None,
5557
term: "cat".to_string(),
5658
etymologies: vec![Etymology {
@@ -88,6 +90,7 @@ mod merge_tests {
8890
entries: hash_map! {
8991
"dog".to_string() => Entry {
9092
see_also: None,
93+
media: vec![],
9194
term: "dog".to_string(),
9295
etymologies: vec![Etymology {
9396
id: None,
@@ -117,6 +120,7 @@ mod merge_tests {
117120
},
118121
"cat".to_string() => Entry {
119122
see_also: None,
123+
media: vec![],
120124
term: "cat".to_string(),
121125
etymologies: vec![Etymology {
122126
id: None,

lib/tests/pronunciation.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -57,10 +57,10 @@ mod pronunciation_tests {
5757
let pronunciation = &entry.etymologies[0].pronunciations[0];
5858
assert!(matches!(pronunciation.kind, PronunciationKind::Pinyin));
5959
assert_eq!(pronunciation.value, "ni hao");
60-
assert_eq!(pronunciation.urls.len(), 1);
61-
assert_eq!(pronunciation.urls[0].src, "./audio.mp3");
60+
assert_eq!(pronunciation.media.len(), 1);
61+
assert_eq!(pronunciation.media[0].src, "./audio.mp3");
6262
assert_eq!(
63-
pronunciation.urls[0].mime_type,
63+
pronunciation.media[0].mime_type,
6464
Some("audio/mpeg".to_string())
6565
);
6666
}
@@ -81,8 +81,8 @@ mod pronunciation_tests {
8181
let pronunciation = &example.pronunciations[0];
8282
assert!(matches!(pronunciation.kind, PronunciationKind::IPA));
8383
assert_eq!(pronunciation.value, "həˈləʊ wɜːld");
84-
assert_eq!(pronunciation.urls.len(), 1);
85-
assert_eq!(pronunciation.urls[0].src, "./hello.mp3");
84+
assert_eq!(pronunciation.media.len(), 1);
85+
assert_eq!(pronunciation.media[0].src, "./hello.mp3");
8686
}
8787

8888
#[test]

lib/tests/resolve.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ mod resolve_tests {
1515
name: None,
1616
entries: hash_map! {
1717
String::from("dog") => Entry {
18+
media: vec![],
1819
term: "dog".to_string(),
1920
see_also: None,
2021
etymologies: vec![

lib/tests/tags.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ fn test_form_with_tags() {
101101

102102
// Create an entry with the etymology
103103
let entry = Entry {
104+
media: vec![],
104105
term: "word".to_string(),
105106
see_also: None,
106107
etymologies: vec![etymology],

lib/tests/translation.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ fn test_translation_in_entry() {
6767

6868
// Create an entry with the etymology
6969
let entry = Entry {
70+
media: vec![],
7071
term: "hello".to_string(),
7172
see_also: None,
7273
etymologies: vec![etymology],

0 commit comments

Comments
 (0)