diff --git a/.idea/dictionaries/geometrically.xml b/.idea/dictionaries/geometrically.xml index e5baa72c..4e14c0d8 100644 --- a/.idea/dictionaries/geometrically.xml +++ b/.idea/dictionaries/geometrically.xml @@ -1,6 +1,7 @@ + curseforge serde tantivy diff --git a/Cargo.lock b/Cargo.lock index ed27c302..39ee180c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -30,8 +30,11 @@ dependencies = [ "futures", "http", "log", + "rustls", + "tokio-rustls", "trust-dns-proto", "trust-dns-resolver", + "webpki", ] [[package]] @@ -65,8 +68,9 @@ dependencies = [ "actix-rt", "actix-service", "actix-threadpool", + "actix-tls", "actix-utils", - "base64", + "base64 0.11.0", "bitflags", "brotli2", "bytes", @@ -212,6 +216,10 @@ dependencies = [ "either", "futures", "log", + "rustls", + "tokio-rustls", + "webpki", + "webpki-roots", ] [[package]] @@ -261,6 +269,7 @@ dependencies = [ "net2", "pin-project", "regex 1.3.7", + "rustls", "serde", "serde_json", "serde_urlencoded", @@ -336,7 +345,7 @@ dependencies = [ "actix-http", "actix-rt", "actix-service", - "base64", + "base64 0.11.0", "bytes", "derive_more", "futures-core", @@ -344,6 +353,7 @@ dependencies = [ "mime", "percent-encoding", "rand", + "rustls", "serde", "serde_json", "serde_urlencoded", @@ -371,6 +381,15 @@ dependencies = [ "libc", ] +[[package]] +name = "base64" +version = "0.10.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b25d992356d2eb0ed82172f5248873db5560c4721f564b13cb5193bda5e668e" +dependencies = [ + "byteorder", +] + [[package]] name = "base64" version = "0.11.0" @@ -424,6 +443,12 @@ dependencies = [ "libc", ] +[[package]] +name = "bumpalo" +version = "3.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5356f1d23ee24a1f785a56d1d1a5f0fd5b0f6a0c0fb2412ce11da71649ab78f6" + [[package]] name = "byte-tools" version = "0.3.1" @@ -596,6 +621,7 @@ dependencies = [ "diesel", "dotenv", "handlebars", + "human_format", "meilisearch-sdk", "serde", "serde_derive", @@ -681,9 +707,9 @@ dependencies = [ [[package]] name = "futures-channel" -version = "0.3.4" +version = "0.3.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f0c77d04ce8edd9cb903932b608268b3fffec4163dc053b3b402bf47eac1f1a8" +checksum = "f366ad74c28cca6ba456d95e6422883cfb4b252a83bed929c83abfdbbf2967d5" dependencies = [ "futures-core", "futures-sink", @@ -691,9 +717,9 @@ dependencies = [ [[package]] name = "futures-core" -version = "0.3.4" +version = "0.3.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f25592f769825e89b92358db00d26f965761e094951ac44d3663ef25b7ac464a" +checksum = "59f5fff90fd5d971f936ad674802482ba441b6f09ba5e15fd8b39145582ca399" [[package]] name = "futures-executor" @@ -708,15 +734,15 @@ dependencies = [ [[package]] name = "futures-io" -version = "0.3.4" +version = "0.3.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a638959aa96152c7a4cddf50fcb1e3fede0583b27157c26e67d6f99904090dc6" +checksum = "de27142b013a8e869c14957e6d2edeef89e97c289e69d042ee3a49acd8b51789" [[package]] name = "futures-macro" -version = "0.3.4" +version = "0.3.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9a5081aa3de1f7542a794a397cde100ed903b0630152d0973479018fd85423a7" +checksum = "d0b5a30a4328ab5473878237c447333c093297bded83a4983d10f4deea240d39" dependencies = [ "proc-macro-hack", "proc-macro2", @@ -726,21 +752,24 @@ dependencies = [ [[package]] name = "futures-sink" -version = "0.3.4" +version = "0.3.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3466821b4bc114d95b087b850a724c6f83115e929bc88f1fa98a3304a944c8a6" +checksum = "3f2032893cb734c7a05d85ce0cc8b8c4075278e93b24b66f9de99d6eb0fa8acc" [[package]] name = "futures-task" -version = "0.3.4" +version = "0.3.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7b0a34e53cf6cdcd0178aa573aed466b646eb3db769570841fda0c7ede375a27" +checksum = "bdb66b5f09e22019b1ab0830f7785bcea8e7a42148683f99214f73f8ec21a626" +dependencies = [ + "once_cell", +] [[package]] name = "futures-util" -version = "0.3.4" +version = "0.3.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "22766cf25d64306bedf0384da004d05c9974ab104fcc4528f1236181c18004c5" +checksum = "8764574ff08b701a084482c3c7031349104b07ac897393010494beaa18ce32c6" dependencies = [ "futures-channel", "futures-core", @@ -749,6 +778,7 @@ dependencies = [ "futures-sink", "futures-task", "memchr", + "pin-project", "pin-utils", "proc-macro-hack", "proc-macro-nested", @@ -864,6 +894,12 @@ version = "1.3.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cd179ae861f0c2e53da70d892f5f3029f9594be0c41dc5269cd371691b1dc2f9" +[[package]] +name = "human_format" +version = "1.0.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "86cce260d758a9aa3d7c4b99d55c815a540f8a37514ba6046ab6be402a157cb0" + [[package]] name = "idna" version = "0.2.0" @@ -911,6 +947,15 @@ version = "0.4.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b8b7a7c0c47db5545ed3fef7468ee7bb5b74691498139e4b3f6a20685dc6dd8e" +[[package]] +name = "js-sys" +version = "0.3.39" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fa5a448de267e7358beaf4a5d849518fe9a0c13fce7afd44b06e68550e5562a7" +dependencies = [ + "wasm-bindgen", +] + [[package]] name = "kernel32-sys" version = "0.2.2" @@ -992,15 +1037,18 @@ checksum = "7ffc5c5338469d4d3ea17d269fa8ea3512ad247247c30bd2df69e68309ed0a08" [[package]] name = "meilisearch-sdk" -version = "0.1.1" +version = "0.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6873f8f9b90d8d451bf6e8af732ee1536a5fb69488eeef7fee4eda79ea0369fe" +checksum = "4aaa1ca3bf32c1839814737b37dcf29021c9d2bec66ae36c339c6a3a4ed61ae8" dependencies = [ "log", "minreq", "serde", "serde_json", "urlencoding", + "wasm-bindgen", + "wasm-bindgen-futures", + "web-sys", ] [[package]] @@ -1132,6 +1180,12 @@ dependencies = [ "libc", ] +[[package]] +name = "once_cell" +version = "1.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b631f7e854af39a1739f401cf34a8a013dfe09eac4fa4dba91e9768bd28168d" + [[package]] name = "opaque-debug" version = "0.2.3" @@ -1391,12 +1445,40 @@ dependencies = [ "quick-error", ] +[[package]] +name = "ring" +version = "0.16.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "703516ae74571f24b465b4a1431e81e2ad51336cb0ded733a55a1aa3eccac196" +dependencies = [ + "cc", + "libc", + "once_cell", + "spin", + "untrusted", + "web-sys", + "winapi 0.3.8", +] + [[package]] name = "rustc-demangle" version = "0.1.16" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4c691c0e608126e00913e33f0ccf3727d5fc84573623b8d65b2df340b5201783" +[[package]] +name = "rustls" +version = "0.16.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b25a18b1bf7387f0145e7f8324e700805aade3842dd3db2e74e4cdeb4677c09e" +dependencies = [ + "base64 0.10.1", + "log", + "ring", + "sct", + "webpki", +] + [[package]] name = "ryu" version = "1.0.4" @@ -1418,6 +1500,16 @@ version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d29ab0c6d3fc0ee92fe66e2d99f700eab17a8d57d1c1d3b748380fb20baa78cd" +[[package]] +name = "sct" +version = "0.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e3042af939fca8c3453b7af0f1c66e533a15a86169e39de2657310ade8f98d3c" +dependencies = [ + "ring", + "untrusted", +] + [[package]] name = "serde" version = "1.0.107" @@ -1513,6 +1605,12 @@ dependencies = [ "winapi 0.3.8", ] +[[package]] +name = "spin" +version = "0.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6e63cff320ae2c57904679ba7cb63280a3dc4613885beafb148ee7bf9aa9042d" + [[package]] name = "syn" version = "1.0.18" @@ -1594,6 +1692,18 @@ dependencies = [ "winapi 0.3.8", ] +[[package]] +name = "tokio-rustls" +version = "0.12.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3068d891551949b37681724d6b73666787cc63fa8e255c812a41d2513aff9775" +dependencies = [ + "futures-core", + "rustls", + "tokio", + "webpki", +] + [[package]] name = "tokio-util" version = "0.2.0" @@ -1718,6 +1828,12 @@ version = "0.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "826e7639553986605ec5979c7dd957c7895e93eabed50ab2ffa7f6128a75097c" +[[package]] +name = "untrusted" +version = "0.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a156c684c91ea7d62626509bce3cb4e1d9ed5c4d978f7b4352658f96a4c26b4a" + [[package]] name = "url" version = "2.1.1" @@ -1807,6 +1923,101 @@ version = "0.9.0+wasi-snapshot-preview1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cccddf32554fecc6acb585f82a32a72e28b48f8c4c1883ddfeeeaa96f7d8e519" +[[package]] +name = "wasm-bindgen" +version = "0.2.62" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e3c7d40d09cdbf0f4895ae58cf57d92e1e57a9dd8ed2e8390514b54a47cc5551" +dependencies = [ + "cfg-if", + "wasm-bindgen-macro", +] + +[[package]] +name = "wasm-bindgen-backend" +version = "0.2.62" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c3972e137ebf830900db522d6c8fd74d1900dcfc733462e9a12e942b00b4ac94" +dependencies = [ + "bumpalo", + "lazy_static", + "log", + "proc-macro2", + "quote", + "syn", + "wasm-bindgen-shared", +] + +[[package]] +name = "wasm-bindgen-futures" +version = "0.4.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8a369c5e1dfb7569e14d62af4da642a3cbc2f9a3652fe586e26ac22222aa4b04" +dependencies = [ + "cfg-if", + "js-sys", + "wasm-bindgen", + "web-sys", +] + +[[package]] +name = "wasm-bindgen-macro" +version = "0.2.62" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2cd85aa2c579e8892442954685f0d801f9129de24fa2136b2c6a539c76b65776" +dependencies = [ + "quote", + "wasm-bindgen-macro-support", +] + +[[package]] +name = "wasm-bindgen-macro-support" +version = "0.2.62" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8eb197bd3a47553334907ffd2f16507b4f4f01bbec3ac921a7719e0decdfe72a" +dependencies = [ + "proc-macro2", + "quote", + "syn", + "wasm-bindgen-backend", + "wasm-bindgen-shared", +] + +[[package]] +name = "wasm-bindgen-shared" +version = "0.2.62" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a91c2916119c17a8e316507afaaa2dd94b47646048014bbdf6bef098c1bb58ad" + +[[package]] +name = "web-sys" +version = "0.3.39" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8bc359e5dd3b46cb9687a051d50a2fdd228e4ba7cf6fcf861a5365c3d671a642" +dependencies = [ + "js-sys", + "wasm-bindgen", +] + +[[package]] +name = "webpki" +version = "0.21.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f1f50e1972865d6b1adb54167d1c8ed48606004c2c9d0ea5f1eeb34d95e863ef" +dependencies = [ + "ring", + "untrusted", +] + +[[package]] +name = "webpki-roots" +version = "0.17.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a262ae37dd9d60f60dd473d1158f9fbebf110ba7b6a5051c8160460f6043718b" +dependencies = [ + "webpki", +] + [[package]] name = "widestring" version = "0.4.0" diff --git a/Cargo.toml b/Cargo.toml index 3ec21940..dfe021df 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -7,14 +7,15 @@ edition = "2018" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -actix-web = "2.0" +actix-web = { version = "2.0", features = ["rustls"]} actix-rt = "1.1.1" handlebars = { version = "3.0.0", features = ["dir_source"] } serde_json = "1.0" serde_derive = "1.0.107" serde = {version="1.0", features=["derive"]} -meilisearch-sdk = "0.1.1" +meilisearch-sdk = "0.1.3" actix-files = "0.2.1" diesel = { version = "1.4.4", features = ["postgres", "serde_json", "chrono"] } dotenv = "0.9.0" chrono = "0.4.11" +human_format = "1.0.3" diff --git a/src/helpers/format_human.rs b/src/helpers/format_human.rs new file mode 100644 index 00000000..3f481aff --- /dev/null +++ b/src/helpers/format_human.rs @@ -0,0 +1,18 @@ +extern crate human_format; +use handlebars::*; + +#[derive(Clone, Copy)] +pub struct HumanFormatHelper; + +impl HelperDef for HumanFormatHelper { + fn call<'reg: 'rc, 'rc>(&self, h: &Helper<'reg, 'rc>, r: &'reg Handlebars<'_>, ctx: &'rc Context, rc: &mut RenderContext<'reg, 'rc>, out: &mut dyn Output) -> HelperResult { + let param = h.param(0).and_then(|v| v.value().as_f64()).unwrap_or(0.0); + + let mut formatted = human_format::Formatter::new().format(param); + formatted.retain(|c| !c.is_whitespace()); + + out.write(formatted.to_uppercase().as_ref())?; + + Ok(()) + } +} \ No newline at end of file diff --git a/src/helpers/mod.rs b/src/helpers/mod.rs index d02c7c60..0c271160 100644 --- a/src/helpers/mod.rs +++ b/src/helpers/mod.rs @@ -1,3 +1,5 @@ mod contains; +mod format_human; -pub use contains::ContainsHelper; \ No newline at end of file +pub use contains::ContainsHelper; +pub use format_human::HumanFormatHelper; \ No newline at end of file diff --git a/src/main.rs b/src/main.rs index 2badbecd..fd3972c2 100644 --- a/src/main.rs +++ b/src/main.rs @@ -19,6 +19,7 @@ async fn main() -> std::io::Result<()> { let mut handlebars = Handlebars::new(); handlebars.register_helper("contains", Box::new(helpers::ContainsHelper)); + handlebars.register_helper("format", Box::new(helpers::HumanFormatHelper)); handlebars .register_templates_directory(".hbs", "./templates") .unwrap(); diff --git a/src/routes/search.rs b/src/routes/search.rs index 6cee8904..e6aec9e3 100644 --- a/src/routes/search.rs +++ b/src/routes/search.rs @@ -8,14 +8,58 @@ use actix_web::client; use crate::database::*; use diesel::prelude::*; +use actix_web::client::Connector; +use meilisearch_sdk::settings::Settings; +use meilisearch_sdk::progress::SettingsUpdate; + +#[derive(Serialize, Deserialize, Debug)] +struct Attachment { + url: String, + isDefault: bool, +} + +#[derive(Serialize, Deserialize, Debug)] +struct Category { + name: String, +} + +#[derive(Serialize, Deserialize, Debug)] +struct Author { + name: String, + url: String, +} + +#[derive(Serialize, Deserialize, Debug)] +struct CurseVersion { + gameVersion: String, +} + +#[derive(Serialize, Deserialize, Debug)] +struct CurseForgeMod { + id: i32, + name: String, + authors: Vec, + attachments: Vec, + websiteUrl: String, + summary: String, + downloadCount: f32, + categories: Vec, + gameVersionLatestFiles: Vec +} #[derive(Serialize, Deserialize, Debug)] struct SearchMod { mod_id: i32, + author: String, title: String, description: String, keywords: Vec, versions: Vec, + downloads: i32, + page_url: String, + icon_url: String, + author_url: String, + empty: String, } impl Document for SearchMod { @@ -65,9 +109,9 @@ fn search(web::Query(info): web::Query) -> Vec { let mut search_query = "".to_string(); let mut filters = "".to_string(); - - if let Some(q) = info.q { - search_query = q; + match info.q { + Some(q) => search_query = q, + None => search_query = "empty".to_string() } if let Some(f) = info.f { @@ -100,7 +144,7 @@ pub async fn index_mods(conn : PgConnection) { let mut mods_index = client.get_or_create("mods").unwrap(); let results = mods.load::(&conn).expect("Error loading mods!"); - let mut docs_to_add = vec![]; + let mut docs_to_add : Vec = vec![]; for result in results { let mod_versions = versions.filter(mod_id.eq(result.id)).load::(&conn).expect("Error loading versions!"); @@ -113,25 +157,142 @@ pub async fn index_mods(conn : PgConnection) { docs_to_add.push(SearchMod { mod_id: result.id, + author: result.author, title: result.title, description: result.description, keywords: result.categories, - versions: mod_game_versions + versions: mod_game_versions, + downloads: result.downloads, + page_url: "".to_string(), + icon_url: "".to_string(), + author_url: "".to_string(), + empty: String::from("empty") }); } - let mut client = client::Client::default(); + let mut client = aws::Client::default(); - let mut response = client.get("https://addons-ecs.forgesvc.net/api/v2/addon/search?categoryId=0&gameId=432&index=0&pageSize=100§ionId=6&sort=5") + let mut response = client.get("https://addons-ecs.forgesvc.net/api/v2/addon/search?categoryId=0&gameId=432&index=0&pageSize=25§ionId=6&sort=5") .header("User-Agent", "Actix-web") - .header("Content-Type", "application/json") .send().await.unwrap(); - println!("{:?}", response); let body = response.body().await.unwrap(); - println!("Downloaded: {:?} bytes", body); + println!("{:?}", body.len()); + let curseforge_mods : Vec = serde_json::from_str(std::str::from_utf8(&body).unwrap()).unwrap(); + for curseforge_mod in curseforge_mods { + let mut mod_game_versions = vec![]; + for version in curseforge_mod.gameVersionLatestFiles { + mod_game_versions.push(version.gameVersion); + } + + let mut mod_categories = vec![]; + for category in curseforge_mod.categories { + match &category.name[..] { + "World Gen" => mod_categories.push(String::from("worldgen")), + "Biomes" => mod_categories.push(String::from("worldgen")), + "Ores and Resources" => mod_categories.push(String::from("worldgen")), + "Structures" => mod_categories.push(String::from("worldgen")), + "Dimensions" => mod_categories.push(String::from("worldgen")), + "Mobs" => mod_categories.push(String::from("worldgen")), + "Technology" => mod_categories.push(String::from("technology")), + "Processing" => mod_categories.push(String::from("technology")), + "Player Transport" => mod_categories.push(String::from("technology")), + "Energy, Fluid, and Item Transport" => mod_categories.push(String::from("technology")), + "Farming" => mod_categories.push(String::from("technology")), + "Energy" => mod_categories.push(String::from("technology")), + "Redstone" => mod_categories.push(String::from("technology")), + "Genetics" => mod_categories.push(String::from("technology")), + "Magic" => mod_categories.push(String::from("magic")), + "Storage" => mod_categories.push(String::from("technology")), + "API and Library" => mod_categories.push(String::from("library")), + "Adventure and RPG" => mod_categories.push(String::from("adventure")), + "Map and Information" => mod_categories.push(String::from("adventure")), + "Cosmetic" => mod_categories.push(String::from("decoration")), + "Addons" => mod_categories.push(String::from("misc")), + "Thermal Expansion" => mod_categories.push(String::from("misc")), + "Tinker's Construct" => mod_categories.push(String::from("misc")), + "Industrial Craft" => mod_categories.push(String::from("misc")), + "Thaumcraft" => mod_categories.push(String::from("misc")), + "Buildcraft" => mod_categories.push(String::from("misc")), + "Forestry" => mod_categories.push(String::from("misc")), + "Blood Magic" => mod_categories.push(String::from("misc")), + "Lucky Blocks" => mod_categories.push(String::from("misc")), + "Applied Energistics 2" => mod_categories.push(String::from("misc")), + "CraftTweaker" => mod_categories.push(String::from("misc")), + "Miscellaneous" => mod_categories.push(String::from("misc")), + "Armor, Tools, and Weapons" => mod_categories.push(String::from("technology")), + "Server Utility" => mod_categories.push(String::from("utility")), + "Fabric" => mod_categories.push(String::from("fabric")), + _ => {} + } + } + + let mut mod_attachments = curseforge_mod.attachments; + mod_attachments.retain(|x| x.isDefault); + docs_to_add.push(SearchMod { + mod_id: curseforge_mod.id, + author: (&curseforge_mod.authors[0].name).to_string(), + title: curseforge_mod.name, + description: curseforge_mod.summary, + keywords: mod_categories, + versions: mod_game_versions, + downloads: curseforge_mod.downloadCount as i32, + page_url: curseforge_mod.websiteUrl, + icon_url: (mod_attachments[0].url).to_string(), + author_url: (&curseforge_mod.authors[0].url).to_string(), + empty: String::from("empty") + }) + } + + println!("{:?}", docs_to_add); mods_index.add_documents(docs_to_add, Some("mod_id")).unwrap(); + + //Write Settings + let settings = mods_index.get_settings().unwrap(); + + let mut ranking_rules = vec![ + "typo".to_string(), + "words".to_string(), + "proximity".to_string(), + "attribute".to_string(), + "wordsPosition".to_string(), + "exactness".to_string(), + "desc(downloads)".to_string() + ]; + + let displayed_attributes = vec![ + "mod_id".to_string(), + "author".to_string(), + "title".to_string(), + "description".to_string(), + "keywords".to_string(), + "versions".to_string(), + "downloads".to_string(), + "page_url".to_string(), + "icon_url".to_string(), + "author_url".to_string(), + "empty".to_string(), + ]; + + let searchable_attributes = vec![ + "author".to_string(), + "title".to_string(), + "description".to_string(), + "keywords".to_string(), + "versions".to_string(), + "empty".to_string(), + ]; + + let write_settings = Settings::new() + .with_displayed_attributes(displayed_attributes) + .with_searchable_attributes(searchable_attributes) + .with_accept_new_fields(settings.accept_new_fields.unwrap()) + .with_stop_words(settings.stop_words.unwrap()) + .with_synonyms(settings.synonyms.unwrap()) + .with_ranking_rules(ranking_rules); + + mods_index.set_settings(&write_settings).unwrap(); } \ No newline at end of file diff --git a/static/css/mod.css b/static/css/mod.css index 10978fe2..ed631291 100644 --- a/static/css/mod.css +++ b/static/css/mod.css @@ -119,7 +119,7 @@ .mod-description div { max-width: 1000px; margin: 0 auto; - padding: 10px; + padding: 5px; } .mod-description img { diff --git a/static/css/search.css b/static/css/search.css index 3b3c021b..05e1c2a4 100644 --- a/static/css/search.css +++ b/static/css/search.css @@ -179,6 +179,7 @@ } .result-image { + object-fit: scale-down; padding: 0 10px 0 5px; } @@ -196,6 +197,17 @@ display: flex; flex-direction: row; align-items: baseline; + text-decoration: none; +} + +.result-name { + text-decoration: none; + color: #0b75d8; +} + +.result-author { + text-decoration: none; + color: #2f92d8; } .result-badges { @@ -278,4 +290,13 @@ .cursed-badge { color: white; background-color: palevioletred; +} + +.cursed-badge img { + margin-left: 5px; +} + +.misc-badge { + color: white; + background-color: deepskyblue; } \ No newline at end of file diff --git a/static/images/icon/misc.svg b/static/images/icon/misc.svg new file mode 100644 index 00000000..205a1864 --- /dev/null +++ b/static/images/icon/misc.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/static/js/search.js b/static/js/search.js index 472138c8..b5346105 100644 --- a/static/js/search.js +++ b/static/js/search.js @@ -9,6 +9,7 @@ let category_inputs = { "library": false, "worldgen": false, "cursed": false, + "misc": false, "forge": false, "fabric": false, } @@ -141,9 +142,14 @@ function activateVersion(element) { } function handleSearch() { - let safeName = encodeURIComponent(input.value).replace(/%20/g,'+'); + let queryString = "search"; + + if(input.value.length > 0) { + queryString += "?q=" + encodeURIComponent(input.value).replace(/%20/g,'+'); + } else { + queryString += "?q=empty" + } - let queryString = "search?q=" + safeName; let filterString = ""; let versionString = ""; diff --git a/templates/search.hbs b/templates/search.hbs index 9dcf9117..3c2afd28 100644 --- a/templates/search.hbs +++ b/templates/search.hbs @@ -7,6 +7,7 @@ + Search @@ -72,6 +73,10 @@ cursed

CURSED

+ + misc +

MISC

+
diff --git a/templates/search_results.hbs b/templates/search_results.hbs index f1d3a17e..beac9553 100644 --- a/templates/search_results.hbs +++ b/templates/search_results.hbs @@ -1,15 +1,15 @@ {{#each results}}
- +
-

{{this.title}}

-

by {{this.author}}

+

{{this.title}}

+

by {{this.author}}

{{this.description}}

download -

1.1M

+

{{format this.downloads}}

updated

5/13/20

@@ -76,6 +76,12 @@

CURSED

{{/contains}} + {{#contains this.keywords "misc"}} +
+ misc +

MISC

+
+ {{/contains}}
{{/each}}