Skip to content

Commit

Permalink
Add search page
Browse files Browse the repository at this point in the history
Signed-off-by: Bruno Lesieur <[email protected]>
  • Loading branch information
MachinisteWeb committed Sep 11, 2017
1 parent 5fcf5cd commit 1d82b1b
Show file tree
Hide file tree
Showing 26 changed files with 196 additions and 11 deletions.
Binary file added assets/media/images/attestation-toeic.pdf
Binary file not shown.
Binary file added assets/media/images/certification-ccna.pdf
Binary file not shown.
Binary file added assets/media/images/contrat-b-fine.pdf
Binary file not shown.
Binary file added assets/media/images/contrat-infovive.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/media/images/contrat-knowledge-expert.pdf
Binary file not shown.
Binary file added assets/media/images/contrat-mediawelcome.pdf
Binary file not shown.
Binary file added assets/media/images/diplome-bac-2.pdf
Binary file not shown.
Binary file added assets/media/images/diplome-bac-5.pdf
Binary file not shown.
Binary file added assets/media/images/diplome-bac-s.pdf
Binary file not shown.
Binary file added assets/media/images/diprome-brevet.pdf
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified assets/media/images/upload/m2.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified assets/media/images/upload/mc4.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/media/images/upload/prototypes-mini.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/media/images/upload/prototypes.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions controllers/articles-by-category.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ website.components = {};
} else {
locals.specific.breadcrumb.items[2].href = locals.specific.breadcrumb.items[2].href.replace(/%urn%/g, locals.params.category);
locals.specific.articles.title = locals.specific.articles.titleNoCategory;
locals.specific.titlePage = locals.specific.articles.titleNoCategory;
locals.specific.description = locals.specific.articles.titleNoCategory;
}

Expand Down
62 changes: 62 additions & 0 deletions controllers/articles-by-search.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
/* jslint node: true */
var website = {};

website.components = {};

(function (publics) {
"use strict";

website.components.listOfArticles = require('./modules/list-of-articles');
website.components.markdownRender = require('./modules/markdown-render');
website.components.extendedFormatDate = require('../assets/javascripts/components/extended-format-date');

publics.changeVariations = function (next, locals, request) {
var NA = this,
mongoose = NA.modules.mongoose,
marked = NA.modules.marked,
Article = mongoose.model('article'),
session = request.session;

locals.backend = {};
locals.session = session;

if (locals.query.query) {
website.components.listOfArticles({
Article: Article,
search: locals.query.query,
marked: marked,
session: locals.session,
markdownRender: website.components.markdownRender,
extendedFormatDate: website.components.extendedFormatDate,
locals: locals
}, function (listOfArticles) {
var nbrArticle = listOfArticles.length,
add = (nbrArticle > 1) ? 's' : '';

if (nbrArticle > 0) {
locals.backend.articles = listOfArticles;
locals.specific.breadcrumb.items[2].content = locals.query.query;
locals.specific.breadcrumb.items[2].title = locals.query.query;
locals.specific.breadcrumb.items[2].href = locals.specific.breadcrumb.items[2].href.replace(/%search%/g, locals.query.query.replace(/ /g, '+'));
locals.specific.articles.title = locals.specific.articles.title.replace(/%search%/g, locals.query.query).replace(/%nbr%/g, nbrArticle).replace(/%moreOne%/g, add);
locals.specific.description = locals.specific.articles.title;
locals.specific.titlePage = locals.specific.articles.title;
} else {
locals.specific.breadcrumb.items[2].href = locals.specific.breadcrumb.items[2].href.replace(/%search%/g, locals.query.query.replace(/ /g, '+'));
locals.specific.articles.title = locals.specific.articles.titleNoSearch;
locals.specific.articles.noArticle = locals.specific.articles.noArticle.replace(/%search%/g, locals.query.query);
locals.specific.description = locals.specific.articles.noArticle;
locals.specific.titlePage = locals.specific.articles.titleNoSearch;
}

next();
});
} else {
locals.specific.breadcrumb.items.splice(2, 1);
next();
}
};

}(website));

exports.changeVariations = website.changeVariations;
27 changes: 21 additions & 6 deletions controllers/modules/list-of-articles.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/* jslint node: true */
module.exports = function listOfArticles(params, callback) {
var categoryId = params.categoryId,
search = params.search,
marked = params.marked,
session = params.session,
markdownRender = params.markdownRender,
Expand All @@ -9,6 +10,8 @@ module.exports = function listOfArticles(params, callback) {
date = params.date,
locals = params.locals,
query = {},
options = {},
sort = { 'dates.published': -1 },
min,
max,
minYear,
Expand All @@ -34,17 +37,29 @@ module.exports = function listOfArticles(params, callback) {
min = new Date(minYear, minMonth, 1);
max = new Date(maxYear, maxMonth, 1);

query = {
'dates.published': {
$gte: min,
$lt: max
query['dates.published'] = {
$gte: min,
$lt: max
};
}

if (typeof search !== 'undefined') {
query.$text = {
$search: search
};
options.score = {
$meta: "textScore"
};
sort = {
score: {
$meta:"textScore"
}
};
}

Article
.find(query)
.sort({ 'dates.published': -1 })
.find(query, options)
.sort(sort)
.populate('categories')
.exec(function (error, temp) {
var results = [],
Expand Down
9 changes: 5 additions & 4 deletions databases/mongodb/blog/article.json

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions optimizations.json
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,10 @@
"media/images/upload/javascript-vs-typescript.jpg": "media/images/upload/",
"media/images/upload/types-mini.png": "media/images/upload/",
"media/images/upload/types.jpg": "media/images/upload/",
"media/images/upload/prototypes-mini.png": "media/images/upload/",
"media/images/upload/prototypes.jpg": "media/images/upload/",
"media/images/upload/evaliation-strategy-mini.png": "media/images/upload/",
"media/images/upload/evaliation-strategy.jpg": "media/images/upload/",
"media/images/404.png": "media/images/"
}
}
Expand Down
14 changes: 14 additions & 0 deletions routes.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,20 @@
"redirect": "/feeds/articles.xml",
"statusCode": 301
},
"/recherche/": {
"view": "articles-by-search.htm",
"controller": "articles-by-search.js",
"variation": "articles-by-search.json"
},
"/recherche": {
"redirect": "/recherche/",
"statusCode": 301
},
"/categories/:category/": {
"view": "articles-by-category.htm",
"controller": "articles-by-category.js",
"variation": "articles-by-category.json"
},
"/categories/:category/": {
"view": "articles-by-category.htm",
"controller": "articles-by-category.js",
Expand Down
39 changes: 39 additions & 0 deletions variations/articles-by-search.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
{
"classLayout": "search",
"titlePage": "Recherche par mots-clés",
"description": "Liste des résultats de la recherche pour les mots-clés.",
"breadcrumb": {
"title": "Vous êtes ici :",
"items": [{
"content": "Accueil",
"title": "Accueil",
"href": "./"
}, {
"content": "Recherche",
"title": "Recherche",
"href": "./recherche/"
},
{
"content": "Aucun résultats",
"title": "Aucun résultats",
"href": "./recherche/?query=%search%"
}]
},
"formSearch": {
"query": {
"label": "Recherche",
"placeHolder": "Vos mots-clés",
"errors": {
"empty": "Le champ recherche est vide."
}
},
"submit": {
"label": "Rechercher"
}
},
"articles": {
"title": "%nbr% résultat%moreOne% trouvé%moreOne% pour la recherche « %search% »",
"titleNoSearch": "Aucun résultats trouvés",
"noArticle": "Aucun résultats trouvé pour la recherche « %search% »."
}
}
16 changes: 15 additions & 1 deletion variations/common.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,12 @@
},
"mainTitle": "Menu",
"section": [
{
"content": "Recherche",
"title": "Tous les billets par mots-clés",
"href": "./recherche/",
"class": "search"
},
{
"content": "Catégories",
"title": "Tous les billets par catégories",
Expand Down Expand Up @@ -90,7 +96,7 @@
"content": "Cette page n'existe pas."
},
"copyright": "©2012-2017 <a href=\"http://www.lesieur.name/\" title=\"Site de Bruno Lesieur, Développeur web spécialiste Front-End / Node.js\">Lesieur.name</a>",
"engine": "Site développé en <a href=\"http://nodejs.org/\" title=\"Node.js, le moteur JavaScript côté serveur\">node.js</a> avec <a href=\"https://node-atlas.js.org/\" title=\"Le Framework node.js NodeAtlas\">NodeAtlas</a>",
"engine": "Site développé en <a href=\"http://nodejs.org/\" title=\"Node.js, le moteur JavaScript côté serveur\">Node.js</a> avec <a href=\"https://node-atlas.js.org/\" title=\"Le Framework node.js NodeAtlas\">NodeAtlas</a>",
"listDate": {
"startingYear": "2012",
"titleYear": "Année",
Expand Down Expand Up @@ -137,6 +143,14 @@
"href": "./categories/%urn%/"
}
},
"search": {
"title": "Recherche par mots-clés",
"title2": "Recherché dans",
"link": {
"title": "Tous les articles de la recherche",
"href": "./recherche/%urn%/"
}
},
"summary": {
"title": "Dans cet article"
},
Expand Down
17 changes: 17 additions & 0 deletions views/articles-by-search.htm
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<? include partials/master-head.htm ?>

<? include partials/master-content.htm ?>

<div id="content" class="content">

<? include partials/search.htm ?>
<? if (query.query) { ?>
<? include partials/articles.htm ?>
<? } ?>

</div>

<? include partials/header.htm ?>
<? include partials/footer.htm ?>

<? include partials/master-foot.htm ?>
18 changes: 18 additions & 0 deletions views/partials/search.htm
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<section class="search">
<h1><?- common.search.title ?></h1>

<form class="form-search" action="./recherche/" method="get">
<div class="field query">
<label for="search-query"><?- specific.formSearch.query.label ?></label>
<input type="text" id="search-query" class="search-query" name="query" placeholder="<?= specific.formSearch.query.placeHolder ?>" value="<?= query.query ?>">
<div class="errors">
<div class="empty"><?- specific.formSearch.query.errors.empty ?></div>
</div>
</div>

<div class="submit">
<label><button class="search-button"><?= specific.formSearch.submit.label ?></button></label>
</div>
</form>

</section>

0 comments on commit 1d82b1b

Please sign in to comment.