Skip to content

Commit

Permalink
Merge branch 'aledipa:main' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
git-malik committed Jul 3, 2023
2 parents 273fa4c + b31209c commit 6353d8d
Show file tree
Hide file tree
Showing 6 changed files with 123 additions and 7 deletions.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# miniWikipedia

miniWikipedia is a website that lets you search every article on Wikipedia and gives you the concise summaries of any topic. It runs in Node.js and TypeScript.
miniWikipedia is a summarised version of the whole Wikipedia encyclopedia. It's a lightweight website and it runs in NodeJS and TypeScript.

<img src="public/img/miniWikipedia_horizontal.svg" width="400" height="100" />

## Manual Installation

Expand Down
36 changes: 34 additions & 2 deletions dist/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/index.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/views/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
</div>

<!-- Scripts -->
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js" type="text/javascript"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js" type="text/javascript"></script>
<script src="script/script.js"></script>
</body>
</html>
50 changes: 50 additions & 0 deletions dist/views/search.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<script src="https://cdn.tailwindcss.com"></script>
<link rel="stylesheet" href="css/style.css">
<link rel="icon" href="img/wikipedia_freepik.png" type="image/png">
<title>miniWikipedia - <%= title %> </title>
</head>
<body>
<!-- NAVBAR -->
<nav class="w-screen h-16 flex pt-2 pl-1 fixed top-0 z-10 bg-[#F9F9F9] grid grid-rows-2 grid-flow-col gap-4">
<!-- TOP-LEFT LOGO -->
<p class="flex justify-start items-end row-start-2 row-span-2">
<a class="ml-2 hover:text-gray-500" href="/">
<img src="img/miniWikipedia_horizontal.svg" class="h-12 mb-2">
</a>
</p>

<!-- input bar -->
<div class="inputBar w-full h-1/5 flex justify-center items-center mt-12 row-start-1 row-end-4">
<form action="/result" method="GET" class="w-full flex justify-end ">
<input type="text" name="search" id="search"
class="w-7/12 h-10 pl-5 text-left text-xl helvetica font-thin outline-0 border-b border-l border-black bg-[#F9F9F9]"
placeholder="Search..." required autocomplete="off">
<div class="suggestions">
<ul></ul>
</div>
<button id="submit" class="w-12 h-24 hover:opacity-70">
<img src="img/search_catalinfertu.png" class="h-8 hover:opacity-70 mb-16 ml-2">
</button>
</form>
</div>
</nav>


<!-- Result -->
<div class="mt-40 h-screen">
<p class="ml-24 georgia font-extrabold text-3xl"> <%= title %> </p>
<p class="ml-24 helvetica font-thin text-s text-gray-400"><i> <%= description %> </i></p>
<br>
<!-- bulleted list of titles -->
<% for (let i = 1; i < search_results.length; i++) { %>
<div class="ml-24 georgia font-thin text-xl text-gray-800 w-7/12"><u><a href="<%= links[i] %>"> <%= search_results[i].title %> </a></u> </div>
<% } %>
</div>
</body>
</html>
36 changes: 34 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,31 @@ app.get('/terms', (req, res) => {

// Handling search request
app.get('/result', (req, res) => {
if (req.query.search == '') { return res.redirect('/'); }
(async () => {
try {
// Tries to give the summary of the search
req.query.search = setPhraseCapitalFirstLetters(req.query.search);
const summary = await wiki.summary(req.query.search, {autoSuggest: false});
if (summary.extract.includes("refer to:")) {
throw new Error("No specific summary found");
}
res.render(__dirname + '/views/result.html', {title:summary.title, description:summary.description, summary:summary.extract});
//Response of type @wikiSummary - contains the intro and the main image
} catch (error) {
const summary = await wiki.summary("HTTP 404", {autoSuggest: false});
res.render(__dirname + '/views/result.html', {title:summary.title, description:summary.description, summary:summary.extract});
// If no summary is found, gives the search results to choose from
const search_results = await wiki.search(req.query.search, {suggestion: true, limit: 10});
if (search_results.results.length > 0) {
var links:Array<string> = [];
for (let i=0; i<search_results.results.length; i++) {
links.push(formatSpaces(linkFromTitle(search_results.results[i].title), '_'));
}
res.render(__dirname + '/views/search.html', {title:req.query.search, description:"Topics referred to by the same term", search_results:search_results.results, links:links});
} else {
// If no search results are found, gives the summary of the "HTTP 404" page
const summary = await wiki.summary("HTTP 404", {autoSuggest: false});
res.render(__dirname + '/views/result.html', {title:summary.title, description:summary.description, summary:summary.extract});
}
//=> Typeof wikiError
}
})();
Expand All @@ -61,6 +77,11 @@ app.post("/suggestion", async (req, res) => {
})();
});

// Handling non existing page request
app.get('*', (req, res) => {
res.redirect('/')
});

// Server listening on given port
app.listen(port, () => console.info('Listening on port ' + port ));

Expand All @@ -73,3 +94,14 @@ function setPhraseCapitalFirstLetters(phrase: string) {
});
return capitalizedWords.join(' ');
}

// Replaces spaces with underscores
function formatSpaces(phrase: string, replacement: string) {
let words = phrase.split(' ');
return words.join(replacement);
}

// Creates the link of the result option
function linkFromTitle(title: string) {
return "/result?search=" + title;
}

0 comments on commit 6353d8d

Please sign in to comment.