Skip to content

Commit

Permalink
Minor fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
aledipa committed Jun 18, 2023
1 parent 1c96e61 commit f949b99
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 7 deletions.
4 changes: 3 additions & 1 deletion 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>
8 changes: 4 additions & 4 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ app.get('/terms', (req, res) => {
app.get('/result', (req, res) => {
(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:")) {
Expand All @@ -43,15 +44,16 @@ app.get('/result', (req, res) => {
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) {
// 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});
// console.log("Search result link 1: " + linkFromTitle(search_results.results[0].title));
} 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});
}
Expand Down Expand Up @@ -93,9 +95,7 @@ function formatSpaces(phrase: string, replacement: string) {
return words.join(replacement);
}


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

}

0 comments on commit f949b99

Please sign in to comment.