Merge pull request #36 from ColinEspinas/remove-old-frontend

Remove old front-end files and routes
This commit is contained in:
Daoud Clarke 2022-01-20 18:06:54 +00:00 committed by GitHub
commit 908a9cf0b6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 1 additions and 422 deletions

View file

@ -6,8 +6,7 @@ from urllib.parse import urlparse
from fastapi import FastAPI
from starlette.middleware.cors import CORSMiddleware
from starlette.responses import FileResponse
from starlette.staticfiles import StaticFiles
from mwmbl.tinysearchengine.hn_top_domains_filtered import DOMAINS
from mwmbl.tinysearchengine.indexer import TinyIndex, Document
@ -15,7 +14,6 @@ from mwmbl.tinysearchengine.indexer import TinyIndex, Document
logger = getLogger(__name__)
STATIC_FILES_PATH = Path(__file__).parent / 'static'
SCORE_THRESHOLD = 0.25
@ -110,10 +108,4 @@ def create(tiny_index: TinyIndex):
ordered_results = order_results(terms, pages)
return ordered_results, terms
@app.get('/')
def index():
return FileResponse(STATIC_FILES_PATH / 'index.html')
app.mount('/', StaticFiles(directory=STATIC_FILES_PATH), name="static")
return app

View file

@ -1,82 +0,0 @@
html {
font-family: Verdana, Geneva, sans-serif;
background: #dcdced;
}
body {
font-size: 1.2rem;
}
p {
width: 100%;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
margin: 3px;
}
div {
margin-top: 15px;
margin-bottom: 15px;
}
.url {
margin-top: 0px;
font-size: 1rem;
}
.container {
width: 100%;
max-width: 1024px;
margin: 0 auto;
}
#search {
display: block;
width: 100%;
outline: none;
font-size: inherit;
border: 2px solid #ccc;
border-width: 4px;
border-radius: 50px;
padding: 10px;
padding-left: 35px;
margin-top: 50px;
}
a {
text-decoration: none;
color: #555555;
}
div .result:hover {
background: #f0f0ff;
}
div .selected {
background: #f0f0ff;
}
div .result {
padding: 10px;
}
span .term {
font-weight: bold;
}
.title {
color: #1a0daa;
/* color: black; */
}
.extract {
}

View file

@ -1,22 +0,0 @@
<html>
<head>
<meta name="referrer" content="no-referrer">
<title>Stoatally Different</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link href="/index.css" rel="stylesheet">
<link rel="search"
type="application/opensearchdescription+xml"
title="Stoatally Different"
href="http://localhost:8000/plugin.xml">
<script src="/index.js"></script>
</head>
<body>
<div class="container">
<form autocomplete="off" id="search-form">
<input type="search" id="search" name="s" value="" autofocus/>
</form>
<div id="results"></div>
</div>
</body>
</html>

View file

@ -1,167 +0,0 @@
ts = {
selected: null,
numItems: 0
};
window.onload = (event) => {
const searchInput = document.getElementById('search');
const length = searchInput.value.length;
searchInput.setSelectionRange(length, length);
searchInput.oninput = debounce(e => {
console.log("Key", e.key);
console.log(searchInput.value);
const encodedValue = encodeURIComponent(searchInput.value);
fetch('/search?s=' + encodedValue).then(response => {
clearResults();
console.log(response);
response.json().then(content => {
console.log(content);
for (const [i, element] of content.entries()) {
addResult(element.title, element.extract, element.url, i);
};
ts.selected = null;
ts.numItems = content.length;
});
});
});
// Handle moving the selected item up and down
document.addEventListener('keydown', (e) => {
console.log("Key press", e);
if (e.key == 'ArrowDown') {
selectNextItem();
e.preventDefault();
} else if (e.key == 'ArrowUp') {
selectPreviousItem();
e.preventDefault();
} else if (e.key == 'Enter') {
// const form = document.getElementById('search-form');
// form.submit();
// event.preventDefault();
}
});
// Handle pressing enter
const form = document.getElementById('search-form');
form.addEventListener("submit", event => {
event.preventDefault();
clickSelected();
});
searchInput.focus();
};
function debounce(callback, timeout = 100){
let timer;
return (...args) => {
clearTimeout(timer);
timer = setTimeout(() => { callback.apply(this, args); }, timeout);
};
}
function selectNextItem() {
if (ts.selected === null) {
ts.selected = 0;
} else if (ts.selected < ts.numItems -1) {
ts.selected++;
}
updateSelected();
}
function clickSelected() {
if (ts.selected !== null) {
const selectedResult = document.getElementById(ts.selected.toString());
selectedResult.click();
}
}
function selectPreviousItem() {
if (ts.selected === null) {
return;
} else if (ts.selected > 0) {
ts.selected--;
} else if (ts.selected == 0) {
ts.selected = null;
}
updateSelected();
}
function updateSelected() {
const results = document.querySelectorAll('.result');
results.forEach(child => {
child.classList.remove('selected');
});
if (ts.selected !== null) {
const selectedResult = document.getElementById(ts.selected.toString());
selectedResult.classList.add('selected');
}
}
function clearResults() {
const results = document.getElementById('results');
results.innerHTML = '';
}
function addResult(title, extract, url, id) {
const par = document.createElement("p");
const titleText = createBoldedSpan(title);
titleText.classList.add('title');
const extractText = createBoldedSpan(extract);
extractText.classList.add('extract');
par.appendChild(titleText);
separator = document.createTextNode(' - ')
par.appendChild(separator);
par.appendChild(extractText);
const div = document.createElement("div");
div.classList.add('result');
div.id = id.toString();
const urlPar = document.createElement("p");
const urlText = document.createTextNode(url);
urlPar.appendChild(urlText);
urlPar.classList.add('url');
div.appendChild(urlPar);
div.appendChild(par);
const link = document.createElement("a");
link.appendChild(div);
link.href = url;
const results = document.getElementById('results');
results.appendChild(link);
}
function createBoldedSpan(title) {
span = document.createElement('span');
title.forEach(element => {
text = document.createTextNode(element.value);
if (element.is_bold) {
b = document.createElement('span');
b.classList.add('term');
b.appendChild(text);
span.appendChild(b);
} else {
span.appendChild(text);
}
});
return span;
}

View file

@ -1,48 +0,0 @@
<!DOCTYPE html>
<html lang="en">
<head>
<title>%s</title>
<link rel="search"
type="application/opensearchdescription+xml"
title="Stoatally Different"
href="https://stoatally-different.appspot.com/plugin.xml">
<!--BOOTSTRAP-->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta/css/bootstrap.min.css" integrity="sha384-/Y6pD6FV/Vv2HJnA6t+vslU6fwYXjCFtcEpHbNJ0lyAFsXTsjBbfaDjzALeQsN6M" crossorigin="anonymous">
<link href="typeaheadjs.css" rel="stylesheet">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
</head>
<body>
%s
<div id="remote">
<form action="/search">
<input class="typeahead" type="search" placeholder="Search" name="s">
<!--<input type="search" name="s" />-->
</form>
</div>
<!--BOOTSTRAP-->
<script src="https://code.jquery.com/jquery-3.2.1.slim.min.js" integrity="sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.11.0/umd/popper.min.js" integrity="sha384-b/U6ypiBEHpOf/4+1nzFpr53nxSS+GLCkfwBdFNTxtclqqenISfwAzpKaMNFNmj4" crossorigin="anonymous"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta/js/bootstrap.min.js" integrity="sha384-h0AbiXch4ZDo7tp9hKZ4TsHbi047NrKGLO3SEJAg45jXxnGIfYzk4Si90RDIqNm1" crossorigin="anonymous"></script>
<script src="typeahead.js"></script>
<script>
var bestPictures = new Bloodhound({
datumTokenizer: Bloodhound.tokenizers.obj.whitespace('value'),
queryTokenizer: Bloodhound.tokenizers.whitespace,
remote: {
url: '/complete?q=%%QUERY',
wildcard: '%%QUERY'
}
});
$('#remote .typeahead').typeahead(null, {
name: 'best-pictures',
display: 'value',
source: bestPictures
});
</script>
</body>
</html>

File diff suppressed because one or more lines are too long

View file

@ -1,18 +0,0 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Search results</title>
</head>
<body>
<div id="remote">
<form action="/search">
<input class="typeahead" type="search" placeholder="Search" name="s">
<!--<input type="search" name="s" />-->
</form>
</div>
</body>
</html>

View file

@ -1,58 +0,0 @@
span.twitter-typeahead .tt-menu {
cursor: pointer;
}
.dropdown-menu, span.twitter-typeahead .tt-menu {
position: absolute;
top: 100%;
left: 0;
z-index: 1000;
display: none;
float: left;
min-width: 160px;
padding: 5px 0;
margin: 2px 0 0;
font-size: 1rem;
color: #373a3c;
text-align: left;
list-style: none;
background-color: #fff;
background-clip: padding-box;
border: 1px solid rgba(0, 0, 0, 0.15);
border-radius: 0.25rem; }
span.twitter-typeahead .tt-suggestion {
display: block;
width: 100%;
padding: 3px 20px;
clear: both;
font-weight: normal;
line-height: 1.5;
color: #373a3c;
text-align: inherit;
white-space: nowrap;
background: none;
border: 0; }
span.twitter-typeahead .tt-suggestion:focus, .dropdown-item:hover, span.twitter-typeahead .tt-suggestion:hover {
color: #2b2d2f;
text-decoration: none;
background-color: #f5f5f5; }
span.twitter-typeahead .active.tt-suggestion, span.twitter-typeahead .tt-suggestion.tt-cursor, span.twitter-typeahead .active.tt-suggestion:focus, span.twitter-typeahead .tt-suggestion.tt-cursor:focus, span.twitter-typeahead .active.tt-suggestion:hover, span.twitter-typeahead .tt-suggestion.tt-cursor:hover {
color: #fff;
text-decoration: none;
background-color: #0275d8;
outline: 0; }
span.twitter-typeahead .disabled.tt-suggestion, span.twitter-typeahead .disabled.tt-suggestion:focus, span.twitter-typeahead .disabled.tt-suggestion:hover {
color: #818a91; }
span.twitter-typeahead .disabled.tt-suggestion:focus, span.twitter-typeahead .disabled.tt-suggestion:hover {
text-decoration: none;
cursor: not-allowed;
background-color: transparent;
background-image: none;
filter: "progid:DXImageTransform.Microsoft.gradient(enabled = false)"; }
span.twitter-typeahead {
width: 100%; }
.input-group span.twitter-typeahead {
display: block !important; }
.input-group span.twitter-typeahead .tt-menu {
top: 2.375rem !important; }

File diff suppressed because one or more lines are too long