web search done right
initial frontend
Mikkel Denker3c907b60b78d
diff --git a/.gitignore b/.gitignoreindex e9230917..f3303773 100644--- a/.gitignore+++ b/.gitignore@@ -3,3 +3,6 @@.DS_Storeflamegraph.svgdata+static/**/*.css+node_modules+package-lock.jsondiff --git a/Cargo.toml b/Cargo.tomlindex ce791c63..e634fa05 100644--- a/Cargo.toml+++ b/Cargo.toml@@ -15,7 +15,6 @@ bincode = "1.3.3"clap = { version = "3.1.18", features = ["derive"] }encoding_rs = "0.8.31"flate2 = "1.0.23"-htmlescape = "0.3.1"indicatif = { version = "0.16.2", features = ["rayon"] }itertools = "0.10.3"lru = "0.7.6"@@ -40,6 +39,8 @@ tokio = { version = "1.19.2", features = ["full"] }askama = "0.11.1"axum = "0.5.9"anyhow = "1.0.58"+axum-extra = { version = "0.3.4", features = ["spa"] }+html-escape = "0.2.11"[dev-dependencies]maplit = "1.0.2"diff --git a/build.rs b/build.rsnew file mode 100644index 00000000..9f383a77--- /dev/null+++ b/build.rs@@ -0,0 +1,13 @@+use std::process::Command;++fn main() {+ Command::new("npm")+ .args(&["run", "build"])+ .status()+ .unwrap();+ println!("cargo:rerun-if-changed=tailwind.css");+ println!("cargo:rerun-if-changed=package.json");+ println!("cargo:rerun-if-changed=yarn.lock");+ println!("cargo:rerun-if-changed=tailwind.config.js");+ println!("cargo:rerun-if-changed=postcss.config.js");+}diff --git a/justfile b/justfileindex dd580fd0..ccfb9ad6 100644--- a/justfile+++ b/justfile@@ -7,3 +7,6 @@@master:cargo run --release -- configs/webgraph/master.toml++@frontend:+ cargo watch -x 'run -- frontend data/index'\ No newline at end of filediff --git a/package.json b/package.jsonnew file mode 100644index 00000000..012729c2--- /dev/null+++ b/package.json@@ -0,0 +1,9 @@+{+ "license": "ISC",+ "scripts": {+ "build": "npx tailwindcss build -i tailwind.css -o ./static/css/main.css"+ },+ "devDependencies": {+ "tailwindcss": "*"+ }+}\ No newline at end of filediff --git a/src/frontend/index.rs b/src/frontend/index.rsnew file mode 100644index 00000000..39736791--- /dev/null+++ b/src/frontend/index.rs@@ -0,0 +1,28 @@+// Cuely is an open source web search engine.+// Copyright (C) 2022 Cuely ApS+//+// This program is free software: you can redistribute it and/or modify+// it under the terms of the GNU Affero General Public License as+// published by the Free Software Foundation, either version 3 of the+// License, or (at your option) any later version.+//+// This program is distributed in the hope that it will be useful,+// but WITHOUT ANY WARRANTY; without even the implied warranty of+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the+// GNU Affero General Public License for more details.+//+// You should have received a copy of the GNU Affero General Public License+// along with this program. If not, see <https://www.gnu.org/licenses/>.++use super::HtmlTemplate;+use askama::Template;+use axum::response::IntoResponse;++pub async fn route() -> impl IntoResponse {+ let template = IndexTemplate {};+ HtmlTemplate(template)+}++#[derive(Template)]+#[template(path = "index.html")]+struct IndexTemplate {}diff --git a/src/frontend/mod.rs b/src/frontend/mod.rsindex 4811fdb5..20265316 100644--- a/src/frontend/mod.rs+++ b/src/frontend/mod.rs@@ -16,50 +16,22 @@use axum::{Extension, Router};-use crate::index::{Index, RetrievedWebpage};+use crate::index::Index;use anyhow::Result;-use std::collections::HashMap;use std::sync::Arc;-use crate::query::Query;-use crate::ranking::Ranker;use askama::Template;use axum::{- extract,http::StatusCode,response::{Html, IntoResponse, Response},routing::get,};+use axum_extra::routing::SpaRouter;-async fn index(- extract::Query(params): extract::Query<HashMap<String, String>>,- Extension(state): Extension<Arc<State>>,-) -> impl IntoResponse {- let mut search_result = Vec::new();+mod index;+pub mod search;- if let Some(query) = params.get("q") {- let query = Query::parse(query).expect("Failed to parse query");- let ranker = Ranker::new(query.clone());-- let result = state- .index- .search(&query, ranker.collector())- .expect("Search failed");-- search_result = dbg!(result.documents);- }-- let template = IndexTemplate { search_result };- HtmlTemplate(template)-}--#[derive(Template)]-#[template(path = "index.html", escape = "none")]-struct IndexTemplate {- search_result: Vec<RetrievedWebpage>,-}--struct HtmlTemplate<T>(T);+pub struct HtmlTemplate<T>(T);pub struct State {pub index: Index,@@ -87,5 +59,9 @@ pub fn router(index_path: &str) -> Result<Router> {index: search_index,});- Ok(Router::new().route("/", get(index)).layer(Extension(state)))+ Ok(Router::new()+ .route("/", get(index::route))+ .route("/search", get(search::route))+ .merge(SpaRouter::new("/static", "static"))+ .layer(Extension(state)))}diff --git a/src/frontend/search.rs b/src/frontend/search.rsnew file mode 100644index 00000000..9a051cc4--- /dev/null+++ b/src/frontend/search.rs@@ -0,0 +1,112 @@+// Cuely is an open source web search engine.+// Copyright (C) 2022 Cuely ApS+//+// This program is free software: you can redistribute it and/or modify+// it under the terms of the GNU Affero General Public License as+// published by the Free Software Foundation, either version 3 of the+// License, or (at your option) any later version.+//+// This program is distributed in the hope that it will be useful,+// but WITHOUT ANY WARRANTY; without even the implied warranty of+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the+// GNU Affero General Public License for more details.+//+// You should have received a copy of the GNU Affero General Public License+// along with this program. If not, see <https://www.gnu.org/licenses/>.++use axum::Extension;++use crate::{+ index::RetrievedWebpage,+ webpage::{strip_protocol, strip_query},+};+use std::collections::HashMap;+use std::sync::Arc;++use super::{HtmlTemplate, State};+use crate::query::Query;+use crate::ranking::Ranker;+use askama::Template;+use axum::{extract, response::IntoResponse};++pub fn html_escape(s: &str) -> String {+ html_escape::decode_html_entities(s)+ .chars()+ .filter(|c| !matches!(c, '<' | '>' | '&'))+ .collect()+}++pub struct DisplayedWebpage {+ pub title: String,+ pub url: String,+ pub pretty_url: String,+ pub snippet: String,+ pub body: String,+}++const MAX_PRETTY_URL_LEN: usize = 50;+const MAX_TITLE_LEN: usize = 50;++impl From<RetrievedWebpage> for DisplayedWebpage {+ fn from(webpage: RetrievedWebpage) -> Self {+ let mut pretty_url = strip_query(strip_protocol(&webpage.url)).to_string();++ if pretty_url.ends_with('/') {+ pretty_url = pretty_url.chars().take(pretty_url.len() - 1).collect();+ }++ pretty_url = pretty_url.replace('/', " › ");++ if pretty_url.len() > MAX_PRETTY_URL_LEN {+ pretty_url = pretty_url.chars().take(MAX_PRETTY_URL_LEN).collect();+ pretty_url += "...";+ }++ let mut title = html_escape(&webpage.title);++ if title.len() > MAX_TITLE_LEN {+ title = title.chars().take(MAX_TITLE_LEN).collect();+ title += "...";+ }++ Self {+ title,+ url: webpage.url,+ pretty_url,+ snippet: webpage.snippet, // snippet has already been html-escaped.+ body: webpage.body,+ }+ }+}++#[derive(Template)]+#[template(path = "search.html", escape = "none")]+struct SearchTemplate {+ search_result: Vec<DisplayedWebpage>,+}++pub async fn route(+ extract::Query(params): extract::Query<HashMap<String, String>>,+ Extension(state): Extension<Arc<State>>,+) -> impl IntoResponse {+ let mut search_result = Vec::new();++ if let Some(query) = params.get("q") {+ let query = Query::parse(query).expect("Failed to parse query");+ let ranker = Ranker::new(query.clone());++ let result = state+ .index+ .search(&query, ranker.collector())+ .expect("Search failed");++ search_result = result+ .documents+ .into_iter()+ .map(DisplayedWebpage::from)+ .collect();+ }++ let template = SearchTemplate { search_result };+ HtmlTemplate(template)+}diff --git a/src/main.rs b/src/main.rsindex 00913c4e..394a8d56 100644--- a/src/main.rs+++ b/src/main.rs@@ -77,8 +77,7 @@ fn load_toml_config<T: DeserializeOwned, P: AsRef<Path>>(path: P) -> T {toml::from_str(&raw_config).expect("Failed to parse config")}-#[tokio::main]-async fn main() -> Result<()> {+fn main() -> Result<()> {let subscriber = FmtSubscriber::builder().with_max_level(Level::INFO).finish();@@ -120,7 +119,10 @@ async fn main() -> Result<()> {WebgraphEntrypoint::run_locally(&config)?;}},- Commands::Frontend { index_path, host } => frontend::run(&index_path, &host).await?,+ Commands::Frontend { index_path, host } => tokio::runtime::Builder::new_multi_thread()+ .enable_all()+ .build()?+ .block_on(frontend::run(&index_path, &host))?,}Ok(())diff --git a/src/searcher.rs b/src/searcher.rsindex 9c2fba94..7421de7c 100644--- a/src/searcher.rs+++ b/src/searcher.rs@@ -32,15 +32,11 @@ pub struct Searcher {#[cfg(test)]impl From<Index> for Searcher {fn from(index: Index) -> Self {- Self::from_index(index)+ Searcher { index }}}impl Searcher {- fn from_index(index: Index) -> Self {- Searcher { index }- }-pub fn search(&self, query: &str) -> Result<SearchResult> {let query = Query::parse(query)?;let ranker = Ranker::new(query.clone());diff --git a/src/snippet.rs b/src/snippet.rsindex c7355802..8fc9cd9f 100644--- a/src/snippet.rs+++ b/src/snippet.rs@@ -14,21 +14,20 @@// You should have received a copy of the GNU Affero General Public License// along with this program. If not, see <https://www.gnu.org/licenses/>.+use crate::frontend::search::html_escape;use std::cmp::Ordering;use std::collections::BTreeMap;use std::ops::Range;-use htmlescape::encode_minimal;-use tantivy::tokenizer::{TextAnalyzer, Token};-use tantivy::{Document, Score, Searcher};+use tantivy::{Score, Searcher};/// For now we use the snippet generator from tantivy with a minor modification to support our TokenStreamMerger./// In the future we want to implement something closer to the method described in https://cs.pomona.edu/~dkauchak/ir_project/whitepapers/Snippet-IL.pdf./// This will require us to store each paragraph of the webpage separately to get adequate performance./// Implementing SnippetIL will also allow us to correctly add "..." to the snippet.-const DEFAULT_MAX_NUM_CHARS: usize = 150;+const DEFAULT_MAX_NUM_CHARS: usize = 200;#[derive(Debug)]struct FragmentCandidate {@@ -80,14 +79,6 @@ const HIGHLIGHTEN_PREFIX: &str = "<b>";const HIGHLIGHTEN_POSTFIX: &str = "</b>";impl Snippet {- /// Create a new, empty, `Snippet`- fn empty() -> Snippet {- Snippet {- fragment: String::new(),- highlighted: Vec::new(),- }- }-/// Returns a hignlightned html from the `Snippet`.fn to_html(&self) -> String {let mut html = String::new();@@ -98,27 +89,17 @@ impl Snippet {start_from = item.end;continue;}- html.push_str(&encode_minimal(&self.fragment[start_from..item.start]));+ html.push_str(&html_escape(&self.fragment[start_from..item.start]));html.push_str(HIGHLIGHTEN_PREFIX);- html.push_str(&encode_minimal(&self.fragment[item.clone()]));+ html.push_str(&html_escape(&self.fragment[item.clone()]));html.push_str(HIGHLIGHTEN_POSTFIX);start_from = item.end;}- html.push_str(&encode_minimal(+ html.push_str(&html_escape(&self.fragment[start_from..self.fragment.len()],));html}-- /// Returns the fragment of text used in the snippet.- fn fragment(&self) -> &str {- &self.fragment- }-- /// Returns a list of higlighted positions from the `Snippet`.- fn highlighted(&self) -> &[Range<usize>] {- &self.highlighted- }}/// Returns a non-empty list of "good" fragments.@@ -207,7 +188,6 @@ fn select_best_fragment_combination(fragments: &[FragmentCandidate], text: &str)struct SnippetGenerator {terms_text: BTreeMap<String, Score>,tokenizer: TextAnalyzer,- field: tantivy::schema::Field,max_num_chars: usize,}@@ -240,34 +220,15 @@ impl SnippetGenerator {Ok(SnippetGenerator {terms_text,tokenizer,- field,max_num_chars: DEFAULT_MAX_NUM_CHARS,})}- /// Sets a maximum number of chars.- fn set_max_num_chars(&mut self, max_num_chars: usize) {- self.max_num_chars = max_num_chars;- }-#[cfg(test)]fn terms_text(&self) -> &BTreeMap<String, Score> {&self.terms_text}- /// Generates a snippet for the given `Document`.- ///- /// This method extract the text associated to the `SnippetGenerator`'s field- /// and computes a snippet.- fn snippet_from_doc(&self, doc: &Document) -> Snippet {- let text: String = doc- .get_all(self.field)- .flat_map(tantivy::schema::Value::as_text)- .collect::<Vec<&str>>()- .join(" ");- self.snippet(&text)- }-/// Generates a snippet for the given text.fn snippet(&self, text: &str) -> Snippet {let fragment_candidates =@@ -288,7 +249,12 @@ pub fn generate(query: &Query, text: &str, searcher: &tantivy::Searcher) -> Resu.expect("Failed to get body field"),)?;- let snippet = generator.snippet(text);+ let mut snippet = generator.snippet(text);++ if snippet.fragment.is_empty() {+ snippet.fragment = text.chars().take(DEFAULT_MAX_NUM_CHARS).collect();+ }+let highlighted = snippet.to_html() + "...";Ok(highlighted)@@ -347,7 +313,7 @@ Survey in 2016, 2017, and 2018."#;assert_eq!(result.documents.len(), 1);assert_eq!(result.documents[0].snippet,- "<b>Rust</b> is a systems programming <b>language</b> sponsored by\nMozilla which describes it as a "safe, concurrent, practical <b>language</b>", supporting functional and..."+ "<b>Rust</b> is a systems programming <b>language</b> sponsored by\nMozilla which describes it as a \"safe, concurrent, practical <b>language</b>\", supporting functional and\nimperative-procedural paradigms. <b>Rust</b> is...".to_string());}@@ -374,7 +340,7 @@ Survey in 2016, 2017, and 2018."#;assert_eq!(snippet.to_html(),"<b>Rust</b> is a systems programming <b>language</b> sponsored by\nMozilla which \- describes it as a "safe"+ describes it as a \"safe")}@@ -585,24 +551,12 @@ Survey in 2016, 2017, and 2018."#;let searcher = index.reader().unwrap().searcher();let query_parser = tantivy::query::QueryParser::for_index(&index, vec![text_field]);let query = query_parser.parse_query("rust design").unwrap();- let mut snippet_generator =- SnippetGenerator::create(&searcher, &*query, text_field).unwrap();- {- let snippet = snippet_generator.snippet(TEST_TEXT);- assert_eq!(- snippet.to_html(),- "imperative-procedural paradigms. <b>Rust</b> is syntactically similar to \- C++[according to whom?],\nbut its <b>designers</b> intend it to provide better \- memory safety"- );- }+ let snippet_generator = SnippetGenerator::create(&searcher, &*query, text_field).unwrap();{- snippet_generator.set_max_num_chars(90);let snippet = snippet_generator.snippet(TEST_TEXT);assert_eq!(snippet.to_html(),- "<b>Rust</b> is syntactically similar to C++[according to whom?],\nbut its \- <b>designers</b> intend it to"+ "<b>Rust</b> is a systems programming language sponsored by\nMozilla which describes it as a \"safe, concurrent, practical language\", supporting functional and\nimperative-procedural paradigms. <b>Rust</b> is");}Ok(())diff --git a/src/webpage.rs b/src/webpage.rsindex a0ed0e6b..12bc5536 100644--- a/src/webpage.rs+++ b/src/webpage.rs@@ -22,7 +22,7 @@ use tl::Children;use crate::schema::{Field, ALL_FIELDS};-fn strip_protocol(url: &str) -> &'_ str {+pub fn strip_protocol(url: &str) -> &'_ str {let mut start_host = 0;if url.starts_with("http://") || url.starts_with("https://") {start_host = url@@ -34,7 +34,16 @@ fn strip_protocol(url: &str) -> &'_ str {&url[start_host..]}-pub(crate) fn host(url: &str) -> &'_ str {+pub fn strip_query(url: &str) -> &'_ str {+ let mut start_query = url.len();+ if url.contains('?') {+ start_query = url.find('?').expect("The url contains atleast 1 '?'");+ }++ &url[..start_query]+}++pub fn host(url: &str) -> &'_ str {let url = strip_protocol(url);let mut end_host = url.len();@@ -45,7 +54,7 @@ pub(crate) fn host(url: &str) -> &'_ str {&url[..end_host]}-pub(crate) fn is_homepage(url: &str) -> bool {+pub fn is_homepage(url: &str) -> bool {let url = strip_protocol(url);match url.find('/') {Some(idx) => idx == url.len() - 1,@@ -53,7 +62,7 @@ pub(crate) fn is_homepage(url: &str) -> bool {}}-pub(crate) fn domain(url: &str) -> &'_ str {+pub fn domain(url: &str) -> &'_ str {let host = host(url);let num_punctuations: usize = host.chars().map(|c| if c == '.' { 1 } else { 0 }).sum();if num_punctuations > 1 {diff --git a/static/.gitkeep b/static/.gitkeepnew file mode 100644index 00000000..e69de29bdiff --git a/static/Montserrat.woff2 b/static/Montserrat.woff2new file mode 100644index 00000000..a848da15Binary files /dev/null and b/static/Montserrat.woff2 differdiff --git a/static/images/arrow.svg b/static/images/arrow.svgnew file mode 100644index 00000000..ed908cee--- /dev/null+++ b/static/images/arrow.svg@@ -0,0 +1,4 @@+<svg width="17" height="31" viewBox="0 0 17 31" fill="none" xmlns="http://www.w3.org/2000/svg">+<rect y="28.87" width="21" height="2" transform="rotate(-45 0 28.87)" fill="#0B7BFF"/>+<rect x="2" width="21" height="2" transform="rotate(45 2 0)" fill="#0B7BFF"/>+</svg>diff --git a/static/images/logo.svg b/static/images/logo.svgnew file mode 100644index 00000000..2309d56b--- /dev/null+++ b/static/images/logo.svg@@ -0,0 +1,16 @@+<svg width="52" height="52" viewBox="0 0 52 52" fill="none" xmlns="http://www.w3.org/2000/svg">+<g clip-path="url(#clip0_14_10)">+<path fill-rule="evenodd" clip-rule="evenodd" d="M51.6035 44.3857C47.791 47.671 43.0194 50.0184 37.7867 51.1829C35.3708 51.714 32.838 52 30.2293 52C25.9094 52.0028 21.6396 51.2087 17.7096 49.6715C13.7796 48.1344 10.2817 45.89 7.45338 43.0913C2.63621 38.3558 -0.0121917 32.2827 4.21958e-05 26C4.21958e-05 19.4573 2.81238 13.4791 7.45338 8.90872C10.2817 6.10993 13.7796 3.86572 17.7096 2.32852C21.6396 0.791321 25.9094 -0.00283138 30.2293 7.58482e-06C32.838 7.58482e-06 35.3708 0.286007 37.7867 0.81715C43.0194 1.9815 47.791 4.32896 51.6035 7.61429L40.9153 16.8071C39.5157 15.5992 37.8508 14.6409 36.0167 13.9874C34.1826 13.334 32.2155 12.9984 30.2293 13C21.8833 13 15.1147 18.8203 15.1147 26L15.119 26.3343C15.327 33.3617 22.0133 39 30.2293 39C34.4023 39 38.181 37.544 40.9153 35.1929L51.6035 44.3857Z" fill="#0B7BFF"/>+<path fill-rule="evenodd" clip-rule="evenodd" d="M40.9154 16.8071C39.5157 15.5992 37.8508 14.6409 36.0167 13.9874C34.1826 13.334 32.2157 12.9984 30.2293 13C21.8833 13 15.1147 18.8203 15.1147 26C15.1084 22.5869 15.8872 19.2062 17.4067 16.0514C18.9262 12.8966 21.1564 10.0296 23.9698 7.61428C27.7823 4.32895 32.5542 1.98149 37.7867 0.817139L40.9154 16.8071Z" fill="url(#paint0_linear_14_10)"/>+</g>+<defs>+<linearGradient id="paint0_linear_14_10" x1="40.0833" y1="7.58333" x2="15.1667" y2="13" gradientUnits="userSpaceOnUse">+<stop stop-color="#0E7DFF" stop-opacity="0.911017"/>+<stop offset="0.0001" stop-color="#0074FC" stop-opacity="0.65"/>+<stop offset="0.734375" stop-color="white"/>+</linearGradient>+<clipPath id="clip0_14_10">+<rect width="52" height="52" fill="white"/>+</clipPath>+</defs>+</svg>diff --git a/static/images/logo16.png b/static/images/logo16.pngnew file mode 100644index 00000000..16f5501fBinary files /dev/null and b/static/images/logo16.png differdiff --git a/static/images/logo180.png b/static/images/logo180.pngnew file mode 100644index 00000000..6f6fa9adBinary files /dev/null and b/static/images/logo180.png differdiff --git a/static/images/logo32.png b/static/images/logo32.pngnew file mode 100644index 00000000..de94414eBinary files /dev/null and b/static/images/logo32.png differdiff --git a/static/images/logo58.png b/static/images/logo58.pngnew file mode 100644index 00000000..1348ac7dBinary files /dev/null and b/static/images/logo58.png differdiff --git a/static/images/search.svg b/static/images/search.svgnew file mode 100644index 00000000..0732c6ca--- /dev/null+++ b/static/images/search.svg@@ -0,0 +1,3 @@+<svg width="26" height="26" viewBox="0 0 26 26" fill="none" xmlns="http://www.w3.org/2000/svg">+<path d="M11.2667 2.60001C6.49047 2.60001 2.60001 6.49047 2.60001 11.2667C2.60001 16.0429 6.49047 19.9333 11.2667 19.9333C13.3436 19.9333 15.2511 19.1958 16.746 17.9715L21.9206 23.1461C22.0004 23.2293 22.0961 23.2957 22.2019 23.3414C22.3078 23.3872 22.4217 23.4113 22.537 23.4125C22.6523 23.4137 22.7667 23.3918 22.8734 23.3483C22.9802 23.3047 23.0772 23.2402 23.1587 23.1587C23.2402 23.0772 23.3047 22.9802 23.3483 22.8734C23.3918 22.7667 23.4137 22.6523 23.4125 22.537C23.4114 22.4217 23.3872 22.3078 23.3414 22.2019C23.2957 22.0961 23.2293 22.0004 23.1461 21.9206L17.9715 16.746C19.1958 15.2511 19.9333 13.3436 19.9333 11.2667C19.9333 6.49047 16.0429 2.60001 11.2667 2.60001ZM11.2667 4.33334C15.1061 4.33334 18.2 7.42723 18.2 11.2667C18.2 15.1061 15.1061 18.2 11.2667 18.2C7.42723 18.2 4.33334 15.1061 4.33334 11.2667C4.33334 7.42723 7.42723 4.33334 11.2667 4.33334Z" fill="#8A8A8A"/>+</svg>diff --git a/tailwind.config.js b/tailwind.config.jsnew file mode 100644index 00000000..b5a5e968--- /dev/null+++ b/tailwind.config.js@@ -0,0 +1,7 @@+module.exports = {+ content: ["./templates/**/*.html"],+ theme: {+ extend: {},+ },+ plugins: [],+}\ No newline at end of filediff --git a/tailwind.css b/tailwind.cssnew file mode 100644index 00000000..bd6213e1--- /dev/null+++ b/tailwind.css@@ -0,0 +1,3 @@+@tailwind base;+@tailwind components;+@tailwind utilities;\ No newline at end of filediff --git a/templates/base.html b/templates/base.htmlnew file mode 100644index 00000000..38112bf2--- /dev/null+++ b/templates/base.html@@ -0,0 +1,89 @@+<!DOCTYPE html>+<html lang="en">++<head>+ <meta charset="UTF-8" />+ <meta name="viewport" content="width=device-width, initial-scale=1.0" />+ <title>Cuely</title>+ {% block meta %}{% endblock %}+ <link rel="stylesheet" type="text/css" href="/static/css/main.css" />+ <link href="https://fonts.googleapis.com/css2?family=Montserrat:wght@400;500;600;700&display=swap" rel="stylesheet">+ <style>+ html,+ body {+ position: relative;+ width: 100%;+ height: 100%;+ }+++ body {+ font-family: Montserrat, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen-Sans, Ubuntu, Cantarell, "Helvetica Neue", sans-serif;+ color: #333;+ box-sizing: border-box;+ padding: 0;+ margin: 0;+ }+++ a:hover {+ text-decoration: underline;+ }++ label {+ display: block;+ }++ input,+ button,+ select,+ textarea {+ font-family: inherit;+ font-size: inherit;+ -webkit-padding: 0.4em 0;+ padding: 0.4em;+ margin: 0 0 0.5em 0;+ box-sizing: border-box;+ border: 1px solid #ccc;+ border-radius: 2px;+ }++ input:disabled {+ color: #ccc;+ }++ button {+ color: #333;+ background-color: #f4f4f4;+ outline: none;+ }++ button:disabled {+ color: #999;+ }++ button:not(:disabled):active {+ background-color: #ddd;+ }++ button:focus {+ border-color: #666;+ }+++ b {+ font-weight: 600 !important;+ }++ pre>code {+ font-size: 0.8rem;+ }+ </style>+ {% block head %}{% endblock %}+</head>++<body>+ {% block content %}{% endblock %}+</body>++</html>\ No newline at end of filediff --git a/templates/index.html b/templates/index.htmlindex 3cd4b4c8..3212edff 100644--- a/templates/index.html+++ b/templates/index.html@@ -1,11 +1,20 @@-<form method="GET">- <input name="q" />- <input type="submit" />-</form>--{% for item in search_result %}-<div>- <p><a href="{{ item.url }}">{{ item.title }}</a></p>- <p>{{ item.snippet }} </p>+{% extends "base.html" %}+{% import "searchbar.html" as scope %}++{% block content %}+<div class="flex flex-col h-full w-full">++ <div class="flex justify-center items-center flex-col" style="flex-grow: 2;">+ <h1 class="text-5xl uppercase mb-1" style="color: #0b7bff">cuely</h1>++ <h3 class="mb-8" style="color: #828282">Completely Open Search Engine</h3>++ {% call scope::searchbar("autofocus") %}++ </div>++ <div class="flex grow flex-col" style="flex-grow: 1;">+ </div></div>-{% endfor %}\ No newline at end of file++{% endblock %}\ No newline at end of filediff --git a/templates/search.html b/templates/search.htmlnew file mode 100644index 00000000..0ff2db8b--- /dev/null+++ b/templates/search.html@@ -0,0 +1,51 @@+{% extends "base.html" %}+{% import "searchbar.html" as scope %}++{% block content %}++<div class="flex flex-col w-full">+ <div class="flex items-center h-24 border">+ <div class="ml-14 mr-14">+ <img src="/static/images/logo.svg" />+ </div>+ {% call scope::searchbar("") %}+ </div>++ <div class="search-result flex flex-col space-y-3 pt-8 pb-8 pl-40">+ {% for item in search_result %}+ <div class="search-result-item bg-white max-w-2xl p-3">+ <div class="text-sm mb-1">+ <a class="hover:no-underline text-gray-500" href="{{ item.url }}">{{ item.pretty_url }}</a>+ </div>+ <div class="text-lg font-medium mb-1">+ <a class="title-link" href="{{ item.url }}">{{ item.title }}</a>+ </div>+ <div class="text-sm">+ {{ item.snippet }}+ </div>+ </div>+ {% endfor %}+ </div>+</div>++<style>+ .title-link {+ color: #1a0dab;+ }++ .title-link:visited {+ color: #609;+ }++ .search-result {+ text-rendering: optimizeLegibility;+ font-smooth: grayscale;+ -moz-osx-font-smoothing: grayscale;+ }++ .search-result-item {+ border-color: rgb(241 245 249);+ }+</style>++{% endblock %}\ No newline at end of filediff --git a/templates/searchbar.html b/templates/searchbar.htmlnew file mode 100644index 00000000..13e378f3--- /dev/null+++ b/templates/searchbar.html@@ -0,0 +1,39 @@+{% macro searchbar(autofocus) %}+++<style>+ .searchbar {+ border-color: #dadada;+ }++ .searchbar:hover {+ box-shadow: rgba(0, 0, 0, 0.08) 0px 1px 3px 1px,+ rgba(0, 0, 0, 0.08) 0px 1px 3px 1px;+ }++ .searchbar:focus-within {+ border-width: 0px;+ box-shadow: rgba(0, 0, 0, 0.08) 0px 1px 3px 1px,+ rgba(0, 0, 0, 0.08) 0px 1px 3px 1px;+ }+</style>++<form class="w-full md:max-w-2xl pl-1 pr-1 relative" method="GET" action="/search" autocomplete="off">+ <div class="searchbar rounded-full h-12 flex flex-col relative bg-white border">+ <div class="flex h-full">+ <div class="flex ml-4 w-5 items-center">+ <img class="h-5" loading="lazy" src="/static/images/search.svg" />+ </div>+ <input type="text" {{ autofocus }} name="q" class="flex w-full h-full grow focus:ring-0"+ placeholder="Search" style="background-color: transparent; border: none; outline: none;" />++ <div class="flex w-12 h-full justify-center items-center">+ <button type="submit" class="bg-transparent p-0 m-0" style="border: none">+ <img loading="lazy" src="/static/images/arrow.svg" class="h-5 cursor-pointer bg-transparent" />+ </button>+ </div>+ </div>+ </div>+</form>++{% endmacro %}\ No newline at end of file