Compare commits
6 Commits
f9f4c79ca2
...
master
Author | SHA1 | Date | |
---|---|---|---|
2dc5c2c0d4 | |||
4c45fba5f6 | |||
77bc2f9b41 | |||
0de83070c7 | |||
90dd20b53f | |||
27c1951a3b |
1191
Cargo.lock
generated
1191
Cargo.lock
generated
File diff suppressed because it is too large
Load Diff
@@ -1,7 +1,7 @@
|
|||||||
#![feature(slice_group_by, path_try_exists)]
|
#![feature(slice_group_by, fs_try_exists)]
|
||||||
|
|
||||||
use std::process::exit;
|
use std::process::exit;
|
||||||
use std::fs;
|
use std::path::Path;
|
||||||
|
|
||||||
//mod database;
|
//mod database;
|
||||||
use rocket::routes;
|
use rocket::routes;
|
||||||
@@ -95,7 +95,7 @@ async fn main() {
|
|||||||
views::get_langs,
|
views::get_langs,
|
||||||
views::frontend]);
|
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));
|
app = app.mount("/static", FileServer::from(FRONTEND_DIR));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
10
src/views.rs
10
src/views.rs
@@ -12,15 +12,15 @@ use crate::language::Language;
|
|||||||
use crate::FRONTEND_DIR;
|
use crate::FRONTEND_DIR;
|
||||||
|
|
||||||
#[get("/")]
|
#[get("/")]
|
||||||
pub fn frontend() -> content::Html<String> {
|
pub fn frontend() -> content::RawHtml<String> {
|
||||||
match fs::read_to_string(&format!("{}/{}", FRONTEND_DIR, "index.html")) {
|
match fs::read_to_string(&format!("{}/{}", FRONTEND_DIR, "index.html")) {
|
||||||
Ok(file) => content::Html(file),
|
Ok(file) => content::RawHtml(file),
|
||||||
Err(_) => content::Html(String::from("<h1>No web frontend installed.</h1>"))
|
Err(_) => content::RawHtml(String::from("<h1>No web frontend installed.</h1>"))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[get("/langs/<lang>/words/<word>")]
|
#[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 conn = db.connect();
|
||||||
|
|
||||||
let mut statement = conn.prepare(&format!(
|
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(']');
|
words.push(']');
|
||||||
|
|
||||||
status::Custom(Status::Ok, content::Json(words))
|
status::Custom(Status::Ok, content::RawJson(words))
|
||||||
}
|
}
|
||||||
|
|
||||||
#[get("/langs/<lang>/words?<like>&<limit>&<offset>")]
|
#[get("/langs/<lang>/words?<like>&<limit>&<offset>")]
|
||||||
|
@@ -8,25 +8,25 @@
|
|||||||
background-color: white;
|
background-color: white;
|
||||||
}
|
}
|
||||||
|
|
||||||
#search-form {
|
#header {
|
||||||
z-index: 10;
|
z-index: 15;
|
||||||
background-color: #56517c;
|
background-color: #56517c;
|
||||||
padding: .4em;
|
padding: .4em;
|
||||||
|
height: 3em;
|
||||||
display: flex;
|
display: flex;
|
||||||
height: 3em;
|
height: 3em;
|
||||||
}
|
}
|
||||||
|
|
||||||
#search {
|
#search-form {
|
||||||
width: 3em;
|
flex-basis: 100%;
|
||||||
}
|
}
|
||||||
|
|
||||||
#search-widget {
|
#search-widget {
|
||||||
flex-basis: 100%;
|
height: 100%;
|
||||||
}
|
}
|
||||||
|
|
||||||
#search-bar {
|
#search-bar {
|
||||||
width: 100%;
|
width: 100%;
|
||||||
height: 100%;
|
|
||||||
border: 1px solid lightgray;
|
border: 1px solid lightgray;
|
||||||
padding: .3em;
|
padding: .3em;
|
||||||
}
|
}
|
||||||
|
@@ -15,14 +15,15 @@
|
|||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<div class="containter" id="main">
|
<div class="containter" id="main">
|
||||||
<form class="sticky-top" id="search-form">
|
<div id="header">
|
||||||
<div class="ui-widget" id="search-widget">
|
<form class="sticky-top" id="search-form">
|
||||||
<input id="search-bar" placeholder="Search..." type="text" autocorrect="off" autocapitalize="none" autofocus>
|
<div class="ui-widget" id="search-widget">
|
||||||
</div>
|
<input id="search-bar" placeholder="Search..." type="text" autocorrect="off" autocapitalize="none" autofocus>
|
||||||
<select id="langs">
|
</div>
|
||||||
</select>
|
<input type="submit" style="display: none" />
|
||||||
<!--<button id="menu"></button>-->
|
</form>
|
||||||
</form>
|
<select id="langs"></select>
|
||||||
|
</div>
|
||||||
<div class="container" id="ajax-content">
|
<div class="container" id="ajax-content">
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
@@ -58,7 +58,7 @@ $(document).ready(() => {
|
|||||||
appendTo: '#search-form',
|
appendTo: '#search-form',
|
||||||
source: (request, response) => {
|
source: (request, response) => {
|
||||||
$.ajax({
|
$.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)
|
success: data => response(data)
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
@@ -72,7 +72,7 @@ $(document).ready(() => {
|
|||||||
searchForm.on('submit', e => {
|
searchForm.on('submit', e => {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
|
|
||||||
const word = e.target[0].value
|
const word = e.target[0].value.trim();
|
||||||
|
|
||||||
window.location.hash = `#${word}`;
|
window.location.hash = `#${word}`;
|
||||||
});
|
});
|
||||||
@@ -81,7 +81,8 @@ $(document).ready(() => {
|
|||||||
const word = window.location.hash.replace('#', '');
|
const word = window.location.hash.replace('#', '');
|
||||||
|
|
||||||
if (word) {
|
if (word) {
|
||||||
document.title = `Inflective - ${decodeURIComponent(word)}`;
|
const decodedWord = decodeURIComponent(word);
|
||||||
|
document.title = `Inflective - ${decodedWord}`;
|
||||||
|
|
||||||
$.ajax({
|
$.ajax({
|
||||||
url: `/langs/${selectedLang.code}/words/${word}`,
|
url: `/langs/${selectedLang.code}/words/${word}`,
|
||||||
@@ -94,6 +95,7 @@ $(document).ready(() => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
window.scrollTo(0, 0);
|
window.scrollTo(0, 0);
|
||||||
|
searchBar.val(decodedWord);
|
||||||
searchBar.select();
|
searchBar.select();
|
||||||
searchBar.autocomplete('close');
|
searchBar.autocomplete('close');
|
||||||
// Sometimes autocomplete opens after close was called
|
// Sometimes autocomplete opens after close was called
|
||||||
@@ -183,6 +185,11 @@ $(document).ready(() => {
|
|||||||
} else {
|
} else {
|
||||||
data.forEach(entry => {
|
data.forEach(entry => {
|
||||||
html += `<h1>${entry.word} <span class="pos">(${entry.pos})</span></h1>`
|
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) {
|
if('senses' in entry) {
|
||||||
let tags = [];
|
let tags = [];
|
||||||
entry.senses.forEach(sense => {
|
entry.senses.forEach(sense => {
|
||||||
@@ -226,7 +233,7 @@ $(document).ready(() => {
|
|||||||
if('forms' in entry) {
|
if('forms' in entry) {
|
||||||
if(entry.pos === 'verb') {
|
if(entry.pos === 'verb') {
|
||||||
let conjugation = entry.forms.filter(form =>
|
let conjugation = entry.forms.filter(form =>
|
||||||
'source' in form && form.source === 'Conjugation');
|
'source' in form && form.source === 'conjugation');
|
||||||
|
|
||||||
if(conjugation.length > 0) {
|
if(conjugation.length > 0) {
|
||||||
html += '<h2>Conjugation</h2>';
|
html += '<h2>Conjugation</h2>';
|
||||||
@@ -235,7 +242,7 @@ $(document).ready(() => {
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
let declension = entry.forms.filter(form =>
|
let declension = entry.forms.filter(form =>
|
||||||
'source' in form && form.source === 'Declension');
|
'source' in form && form.source === 'declension');
|
||||||
|
|
||||||
if(declension.length > 0) {
|
if(declension.length > 0) {
|
||||||
html += '<h2>Declension</h2>';
|
html += '<h2>Declension</h2>';
|
||||||
|
Reference in New Issue
Block a user