Compare commits

...

6 Commits

Author SHA1 Message Date
2dc5c2c0d4 Filter transcriptions 2023-03-16 09:12:49 +01:00
4c45fba5f6 Fix missing tables 2023-03-16 08:58:12 +01:00
77bc2f9b41 Fix content type 2023-03-14 10:06:08 +01:00
0de83070c7 Add IPA transcription 2023-03-14 09:41:07 +01:00
90dd20b53f Fix other android issues 2022-07-23 14:25:06 +02:00
27c1951a3b Fix android javascript 2022-07-23 13:11:10 +02:00
6 changed files with 750 additions and 503 deletions

1191
Cargo.lock generated

File diff suppressed because it is too large Load Diff

View File

@@ -1,7 +1,7 @@
#![feature(slice_group_by, path_try_exists)]
#![feature(slice_group_by, fs_try_exists)]
use std::process::exit;
use std::fs;
use std::path::Path;
//mod database;
use rocket::routes;
@@ -95,7 +95,7 @@ async fn main() {
views::get_langs,
views::frontend]);
if let Ok(_) = fs::try_exists(FRONTEND_DIR) {
if let Ok(_) = Path::new(FRONTEND_DIR).try_exists() {
app = app.mount("/static", FileServer::from(FRONTEND_DIR));
}

View File

@@ -12,15 +12,15 @@ use crate::language::Language;
use crate::FRONTEND_DIR;
#[get("/")]
pub fn frontend() -> content::Html<String> {
pub fn frontend() -> content::RawHtml<String> {
match fs::read_to_string(&format!("{}/{}", FRONTEND_DIR, "index.html")) {
Ok(file) => content::Html(file),
Err(_) => content::Html(String::from("<h1>No web frontend installed.</h1>"))
Ok(file) => content::RawHtml(file),
Err(_) => content::RawHtml(String::from("<h1>No web frontend installed.</h1>"))
}
}
#[get("/langs/<lang>/words/<word>")]
pub fn get_entries(db: &State<WordDb>, lang: &str, word: &str) -> status::Custom<content::Json<String>> {
pub fn get_entries(db: &State<WordDb>, lang: &str, word: &str) -> status::Custom<content::RawJson<String>> {
let conn = db.connect();
let mut statement = conn.prepare(&format!(
@@ -46,7 +46,7 @@ pub fn get_entries(db: &State<WordDb>, lang: &str, word: &str) -> status::Custom
}
words.push(']');
status::Custom(Status::Ok, content::Json(words))
status::Custom(Status::Ok, content::RawJson(words))
}
#[get("/langs/<lang>/words?<like>&<limit>&<offset>")]

View File

@@ -8,25 +8,25 @@
background-color: white;
}
#search-form {
z-index: 10;
#header {
z-index: 15;
background-color: #56517c;
padding: .4em;
height: 3em;
display: flex;
height: 3em;
}
#search {
width: 3em;
#search-form {
flex-basis: 100%;
}
#search-widget {
flex-basis: 100%;
height: 100%;
}
#search-bar {
width: 100%;
height: 100%;
border: 1px solid lightgray;
padding: .3em;
}

View File

@@ -15,14 +15,15 @@
</head>
<body>
<div class="containter" id="main">
<div id="header">
<form class="sticky-top" id="search-form">
<div class="ui-widget" id="search-widget">
<input id="search-bar" placeholder="Search..." type="text" autocorrect="off" autocapitalize="none" autofocus>
</div>
<select id="langs">
</select>
<!--<button id="menu"></button>-->
<input type="submit" style="display: none" />
</form>
<select id="langs"></select>
</div>
<div class="container" id="ajax-content">
</div>
</div>

View File

@@ -58,7 +58,7 @@ $(document).ready(() => {
appendTo: '#search-form',
source: (request, response) => {
$.ajax({
url: `/langs/${selectedLang.code}/words?like=${request.term}&limit=20&offset=0`,
url: `/langs/${selectedLang.code}/words?like=${request.term.trim()}&limit=20&offset=0`,
success: data => response(data)
})
},
@@ -72,7 +72,7 @@ $(document).ready(() => {
searchForm.on('submit', e => {
e.preventDefault();
const word = e.target[0].value
const word = e.target[0].value.trim();
window.location.hash = `#${word}`;
});
@@ -81,7 +81,8 @@ $(document).ready(() => {
const word = window.location.hash.replace('#', '');
if (word) {
document.title = `Inflective - ${decodeURIComponent(word)}`;
const decodedWord = decodeURIComponent(word);
document.title = `Inflective - ${decodedWord}`;
$.ajax({
url: `/langs/${selectedLang.code}/words/${word}`,
@@ -94,6 +95,7 @@ $(document).ready(() => {
})
window.scrollTo(0, 0);
searchBar.val(decodedWord);
searchBar.select();
searchBar.autocomplete('close');
// Sometimes autocomplete opens after close was called
@@ -183,6 +185,11 @@ $(document).ready(() => {
} else {
data.forEach(entry => {
html += `<h1>${entry.word} <span class="pos">(${entry.pos})</span></h1>`
if('sounds' in entry) {
html += `<p>${entry.sounds.map(sound => sound.ipa).filter(sound => sound && sound.match(/\/.*\//g)).join(', ')}</p>`;
}
if('senses' in entry) {
let tags = [];
entry.senses.forEach(sense => {
@@ -226,7 +233,7 @@ $(document).ready(() => {
if('forms' in entry) {
if(entry.pos === 'verb') {
let conjugation = entry.forms.filter(form =>
'source' in form && form.source === 'Conjugation');
'source' in form && form.source === 'conjugation');
if(conjugation.length > 0) {
html += '<h2>Conjugation</h2>';
@@ -235,7 +242,7 @@ $(document).ready(() => {
}
} else {
let declension = entry.forms.filter(form =>
'source' in form && form.source === 'Declension');
'source' in form && form.source === 'declension');
if(declension.length > 0) {
html += '<h2>Declension</h2>';