Le domaine ouestline.net pointe sur l’adresse IPV6 2a01:e34:ee6a:b274::1
Ce debian virtuel est utilisé pour des tests avec la possibilité de créer des images à un instant donné pour y revenir si besoin…
Image debian stretch avec VirtualBox
Pour info
1
2
3
4
VBoxManage startvm 'Debian Stretch' --type headless # Lancement VM sans l'application graphique
VBoxManage controlvm 'Debian Stretch' poweroff # Pour arrêter une VM
VBoxManage controlvm 'Debian Stretch' pause # Pour mettre en pause une VM
VBoxManage controlvm 'Debian Stretch' reset # Pour réinitialiser une VM
Connexion SSH
1
ssh dbsuser@192.168.0.47
Passer en root
1
su # sudo -s
Mise à jour
1
apt update && apt upgrade -y
Installer sudo
1
apt install sudo
Visudo pour les accès root via utilisateur dbsuser
Ajouter le contenu de la clé publique vbox-dbs-ed25519.pub au fichier ~/.ssh/authorized_keys
Droit en lecture utilisateur uniquement, chmod 400 ~/.ssh/authorized_keys
Modification configuration serveur ssh , /etc/ssh/sshd_config -> PasswordAuthentication no
Relancer le service sudo systemctl restart sshd
VBox Additions Invité/Debian
Préalable
Configurer votre machine virtuelle pour un accès au réseau partagé. '’Configuration’’ –> ‘‘Dossiers partagés’‘
Ajouter le dossier et cocher '’Montage automatique’‘
Installer les additions client dans un Debian en cours d’exécution dans une machine virtuelle.
Installez gcc ,make et kernel headers (installateur a besoin d’eux pour construire le module du noyau):
sudo apt install gcc make linux-headers-$(uname -r)
Allez dans le menu '’Périphériques’’ –> ‘‘Insérer l’image des additions invité…’‘ de la machine virtuelle en cours d’exécution ,si non présent , le télécharger.
Monter le cd dans la machine virtuelle : sudo mount /dev/cdrom /media/cdrom
Allez dans le dossier monté : cd /media/cdrom
Exécutez : sudo ./VBoxLinuxAdditions.run
Pas d’environnement graphique : ne pas tenir compte de l'erreur'’Could not find the X.Org or XFree86 Window System, skipping.’‘
Il faut ajouter le group vboxsf à votre utilisateur : sudo usermod -a -G vboxsf $USER
Pour la prise en compte, redémarrer la machine virtuelle : sudo reboot
/media/ est le répertoire qui contient le(s) dossier(s) partagé(s)
Gestion machine virtuelle VM
Démarrer la machine virtuelle VM en ligne de commande sans interface graphique VirtualBox
2: enp0s3: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
link/ether 08:00:27:a1:75:8e brd ff:ff:ff:ff:ff:ff
inet 192.168.0.47/24 brd 192.168.0.255 scope global enp0s3
valid_lft forever preferred_lft forever
inet6 2a01:e34:ee6a:b270:a00:27ff:fea1:758e/64 scope global mngtmpaddr dynamic
valid_lft 86089sec preferred_lft 86089sec
inet6 fe80::a00:27ff:fea1:758e/64 scope link
valid_lft forever preferred_lft forever
La carte n’est joignable de l’internet que par son adresse IPV6
NextHop Freebox permet d’attribuer une adresse IPV6
Adresse IPV6 Box fe80::224:d4ff:fea6:aa20
Préfixe 2a01:e34:ee6a:b274::/64
NextHop fe80::a00:27ff:fea1:758e
1
sudo nano /etc/network/interfaces
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
# This file describes the network interfaces available on your system
# and how to activate them. For more information, see interfaces(5).
source /etc/network/interfaces.d/*
# The loopback network interface
auto lo
iface lo inet loopback
# The primary network interface
allow-hotplug enp0s3
iface enp0s3 inet dhcp
# This is an autoconfigured IPv6 interface
# iface enp0s3 inet6 auto
iface enp0s3 inet6 static
address 2a01:e34:ee6a:b274::1
netmask 64
post-up ip -6 route add default via fe80::224:d4ff:fea6:aa20 dev enp0s3
Redémarrer la machine
1
sudo systemctl reboot
Vérifier l’adresse inet6
1
ip addr
1
2
3
4
5
6
7
8
9
10
2: enp0s3: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
link/ether 08:00:27:a1:75:8e brd ff:ff:ff:ff:ff:ff
inet 192.168.0.47/24 brd 192.168.0.255 scope global enp0s3
valid_lft forever preferred_lft forever
inet6 2a01:e34:ee6a:b274::1/64 scope global tentative dadfailed
valid_lft forever preferred_lft forever
inet6 2a01:e34:ee6a:b270:a00:27ff:fea1:758e/64 scope global mngtmpaddr dynamic
valid_lft 84708sec preferred_lft 84708sec
inet6 fe80::a00:27ff:fea1:758e/64 scope link
valid_lft forever preferred_lft forever
Le domaine ouestline.net pointe sur l’adresse IPV6 2a01:e34:ee6a:b274::1
depuis un poste distant ping -6 -c5 2a01:e34:ee6a:b274::1 ping -6 -c5 ouestline.net
OVH
1
2
3
4
5
6
7
$TTL 3600
@ IN SOA dns111.ovh.net. tech.ovh.net. (2018110102 86400 3600 3600000 300)
3600 IN NS ns111.ovh.net.
3600 IN NS dns111.ovh.net.
3600 IN AAAA 2a01:e34:ee6a:b274::1
blog 3600 IN CNAME ouestline.net.
static 3600 IN CNAME ouestline.net.
Passer en root (su, sudo)
Génération des certificats /root/.acme.sh/acme.sh --dns dns_ovh --issue --keylength 4096 -d ouestline.net -d *.ouestline.net
1
2
3
4
[lundi 22 octobre 2018, 18:39:48 (UTC+0200)] Your cert is in /root/.acme.sh/ouestline.net/ouestline.net.cer
[lundi 22 octobre 2018, 18:39:48 (UTC+0200)] Your cert key is in /root/.acme.sh/ouestline.net/ouestline.net.key
[lundi 22 octobre 2018, 18:39:48 (UTC+0200)] The intermediate CA cert is in /root/.acme.sh/ouestline.net/ca.cer
[lundi 22 octobre 2018, 18:39:48 (UTC+0200)] And the full chain certs is there: /root/.acme.sh/ouestline.net/fullchain.cer
server {
listen 80;
listen [::]:80;
## redirect http to https ##
server_name ouestline.net;
return 301 https://$server_name$request_uri;
}
server {
listen 443 ssl http2;
listen [::]:443 ssl http2;
server_name ouestline.net;
root /var/www/ ;
ssl_certificate /etc/ssl/private/ouestline.net.fullchain.cer.pem;
ssl_certificate_key /etc/ssl/private/ouestline.net.key.pem;
ssl_session_timeout 5m;
ssl_session_cache shared:SSL:50m;
# As suggested by Mozilla : https://wiki.mozilla.org/Security/Server_Side_TLS and https://en.wikipedia.org/wiki/Curve25519
# (this doesn't work on jessie though ...?)
# ssl_ecdh_curve secp521r1:secp384r1:prime256v1;
# As suggested by https://cipherli.st/
ssl_ecdh_curve secp384r1;
ssl_prefer_server_ciphers on;
# Ciphers with modern compatibility
#---------------------------------
# https://mozilla.github.io/server-side-tls/ssl-config-generator/?server=nginx-1.6.2&openssl=1.0.1t&hsts=yes&profile=modern
# Uncomment the following to use modern ciphers, but remove compatibility with some old clients (android < 5.0, Internet Explorer < 10, ...)
ssl_protocols TLSv1.2 TLSv1.3;
ssl_ciphers 'TLS13+AESGCM+AES128:EECDH+AESGCM:EECDH+CHACHA20:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-SHA384:ECDHE-RSA-AES256-SHA384:ECDHE-ECDSA-AES128-SHA256:ECDHE-RSA-AES128-SHA256';
# Uncomment the following directive after DH generation
# > openssl dhparam -out /etc/ssl/private/dh2048.pem -outform PEM -2 2048
#ssl_dhparam /etc/ssl/private/dh2048.pem;
# Follows the Web Security Directives from the Mozilla Dev Lab and the Mozilla Obervatory + Partners
# https://wiki.mozilla.org/Security/Guidelines/Web_Security
# https://observatory.mozilla.org/
add_header Strict-Transport-Security "max-age=63072000; includeSubDomains; preload";
add_header Content-Security-Policy "upgrade-insecure-requests";
add_header Content-Security-Policy-Report-Only "default-src https: data: 'unsafe-inline' 'unsafe-eval'";
add_header X-Content-Type-Options nosniff;
add_header X-XSS-Protection "1; mode=block";
add_header X-Download-Options noopen;
add_header X-Permitted-Cross-Domain-Policies none;
add_header X-Frame-Options "SAMEORIGIN";
index index.php;
location ~ \.php$ {
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/run/php/php7.2-fpm.sock; # PHP7.2
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $request_filename;
}
}
Rechargement nginx systemctl reload nginx
script ssh_rc
Exécuter un fichier utilisateur nommé $HOME/.ssh/rc si présent
Pour tous les utilisateurs exécuter un fichier nommé /etc/ssh/sshrc si présent
Installer les utilitaires curl jq figlet
server {
listen 80;
listen [::]:80;
## redirect http to https ##
server_name dev.ouestline.net;
return 301 https://$server_name$request_uri;
}
server {
listen 443 ssl http2;
listen [::]:443 ssl http2;
server_name dev.ouestline.net;
root /var/www/devel/ ;
ssl_certificate /etc/ssl/private/ouestline.net.fullchain.cer.pem;
ssl_certificate_key /etc/ssl/private/ouestline.net.key.pem;
ssl_session_timeout 5m;
ssl_session_cache shared:SSL:50m;
# As suggested by Mozilla : https://wiki.mozilla.org/Security/Server_Side_TLS and https://en.wikipedia.org/wiki/Curve25519
# (this doesn't work on jessie though ...?)
# ssl_ecdh_curve secp521r1:secp384r1:prime256v1;
# As suggested by https://cipherli.st/
ssl_ecdh_curve secp384r1;
ssl_prefer_server_ciphers on;
# Ciphers with modern compatibility
#---------------------------------
# https://mozilla.github.io/server-side-tls/ssl-config-generator/?server=nginx-1.6.2&openssl=1.0.1t&hsts=yes&profile=modern
# Uncomment the following to use modern ciphers, but remove compatibility with some old clients (android < 5.0, Internet Explorer < 10, ...)
ssl_protocols TLSv1.2 TLSv1.3;
ssl_ciphers 'TLS13+AESGCM+AES128:EECDH+AESGCM:EECDH+CHACHA20:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-SHA384:ECDHE-RSA-AES256-SHA384:ECDHE-ECDSA-AES128-SHA256:ECDHE-RSA-AES128-SHA256';
# Uncomment the following directive after DH generation
# > openssl dhparam -out /etc/ssl/private/dh2048.pem -outform PEM -2 2048
#ssl_dhparam /etc/ssl/private/dh2048.pem;
# Follows the Web Security Directives from the Mozilla Dev Lab and the Mozilla Obervatory + Partners
# https://wiki.mozilla.org/Security/Guidelines/Web_Security
# https://observatory.mozilla.org/
add_header Strict-Transport-Security "max-age=63072000; includeSubDomains; preload";
add_header Content-Security-Policy "upgrade-insecure-requests";
add_header Content-Security-Policy-Report-Only "default-src https: data: 'unsafe-inline' 'unsafe-eval'";
add_header X-Content-Type-Options nosniff;
add_header X-XSS-Protection "1; mode=block";
add_header X-Download-Options noopen;
add_header X-Permitted-Cross-Domain-Policies none;
add_header X-Frame-Options "SAMEORIGIN";
location / {
fancyindex on; # Enable fancy indexes.
fancyindex_exact_size off; # Output human-readable file sizes.
}
index index/ index.php;
location ~ \.php$ {
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/run/php/php7.3-fpm.sock; # PHP7.3
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $request_filename;
}
}
Vérifier et relancer
1
2
sudo nginx -t
sudo systemctl restart nginx
Cartographie, les modifications se font en local sur PC1 dossier /home/yannick/media/devel/ouestline/osm-new/
Le développement , dossier /home/yannick/media/devel/
sudo apt install git
cd /srv
git clone https://gitea.yanspm.com/yannick/wikistatic2.0 wikistatic
cd wikistatic
Lancement “bundle” dans le dossier /srv/wikistatic pour la création de l’environnement
1
2
cd /srv/wikistatic
bundle
Les dossiers de l’hôte sont partagés sur la VBox debian (nfs+autofs)
On efface les dossiers actuels (ils peuvent ne pas exister) sudo rm -r /srv/wikistatic/{files,images,_posts}
Montage auto des dossiers pour le site statique ,ajout au fichier /etc/auto.master
1
sudo nano /etc/auto.master
1
2
# ligne à ajouter en fin de fichier
/srv/static /etc/wikistatic.nfs
cd /srv/wikistatic # aller au dossier avant construction
jekyll build # construction du dossier statique _site
1
2
3
4
5
6
7
Configuration file: /srv/wikistatic/_config.yml
Source: /srv/wikistatic
Destination: /srv/wikistatic/_site
Incremental build: disabled. Enable with --incremental
Generating...
done in 15.062 seconds.
Auto-regeneration: disabled. Use --watch to enable.
Générer site automatiquement
Le dossier _site est regénéré à chaque création, modification ou suppression d’un fichier de type markdown dans le dossier _posts
Cette opération doit être lancée et en attente. Un bash et un service vont être utilisés.
Pour lancer le serveur Jekyll au démarrage , créer un bash sous /srv/wikistatic
1
nano /srv/wikistatic/start_jekyll.sh
1
2
3
4
5
#!/bin/sh
# Accès dossier
cd /srv/wikistatic/
# lancement jekyll en mode auto génération sans serveur
/usr/local/bin/bundle exec jekyll build --watch --source "/srv/wikistatic"
Pour lancer le serveur Jekyll au démarrage, utilisation d’un service systemd ATTENTION! , remplacer User=utilisateur par votre nom d’utilisateur (echo $USER)
server {
listen 80;
listen [::]:80;
## redirect http to https ##
server_name static.ouestline.net;
return 301 https://$server_name$request_uri;
}
server {
listen 443 ssl http2;
listen [::]:443 ssl http2;
server_name static.ouestline.net;
root /srv/wikistatic/_site/ ;
ssl_certificate /etc/ssl/private/ouestline.net.fullchain.cer.pem;
ssl_certificate_key /etc/ssl/private/ouestline.net.key.pem;
ssl_session_timeout 5m;
ssl_session_cache shared:SSL:50m;
# As suggested by Mozilla : https://wiki.mozilla.org/Security/Server_Side_TLS and https://en.wikipedia.org/wiki/Curve25519
# (this doesn't work on jessie though ...?)
# ssl_ecdh_curve secp521r1:secp384r1:prime256v1;
# As suggested by https://cipherli.st/
ssl_ecdh_curve secp384r1;
ssl_prefer_server_ciphers on;
# Ciphers with modern compatibility
#---------------------------------
# https://mozilla.github.io/server-side-tls/ssl-config-generator/?server=nginx-1.6.2&openssl=1.0.1t&hsts=yes&profile=modern
# Uncomment the following to use modern ciphers, but remove compatibility with some old clients (android < 5.0, Internet Explorer < 10, ...)
ssl_protocols TLSv1.2 TLSv1.3;
ssl_ciphers 'TLS13+AESGCM+AES128:EECDH+AESGCM:EECDH+CHACHA20:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-SHA384:ECDHE-RSA-AES256-SHA384:ECDHE-ECDSA-AES128-SHA256:ECDHE-RSA-AES128-SHA256';
# Uncomment the following directive after DH generation
# > openssl dhparam -out /etc/ssl/private/dh2048.pem -outform PEM -2 2048
#ssl_dhparam /etc/ssl/private/dh2048.pem;
# Follows the Web Security Directives from the Mozilla Dev Lab and the Mozilla Obervatory + Partners
# https://wiki.mozilla.org/Security/Guidelines/Web_Security
# https://observatory.mozilla.org/
add_header Strict-Transport-Security "max-age=63072000; includeSubDomains; preload";
add_header Content-Security-Policy "upgrade-insecure-requests";
add_header Content-Security-Policy-Report-Only "default-src https: data: 'unsafe-inline' 'unsafe-eval'";
add_header X-Content-Type-Options nosniff;
add_header X-XSS-Protection "1; mode=block";
add_header X-Download-Options noopen;
add_header X-Permitted-Cross-Domain-Policies none;
add_header X-Frame-Options "SAMEORIGIN";
index index/;
}
Recharger le serveur nginx
1
sudo systemctl reload nginx
Ordinateur PC1
Créer un service systemd pour lancer debian vbox
Le but est de lancer l’image virtuelle au démarrage de la machine
Création d’un service utilisateur
cd /srv/basicblog
bundle update github-pages
bundle
Modifier le fichier de configuration
1
nano _config.yml
1
exclude: [start_basicblog.sh]
Créer service basicblog
Le script /srv/basicblog/start_basicblog.sh contenu dans le service
1
2
3
4
5
#!/bin/sh
# Accès dossier
cd /srv/basicblog/
# lancement jekyll en mode auto génération sans serveur
/usr/local/bin/bundle exec jekyll build --watch --source "/srv/basicblog"
On va exécuter un service qui va mettre le générateur “jekyll” en attente de modifications dans le dossier _posts (création, modification ou suppression de fichier markdown)
sudo systemctl daemon-reload
sudo systemctl start basicblog
# Valider le lancement du service basicblog au démarrage
sudo systemctl enable basicblog
#Vérifier
sudo systemctl status basicblog
1
2
3
4
5
6
7
8
● basicblog.service - basicblog Service
Loaded: loaded (/etc/systemd/system/basicblog.service; enabled; vendor preset: enabled)
Active: active (running) since Tue 2019-01-29 20:07:14 CET; 8s ago
Main PID: 18347 (sh)
Tasks: 5 (limit: 4915)
CGroup: /system.slice/basicblog.service
├─18347 /bin/sh /srv/basicblog/start_basicblog.sh
└─18348 ruby2.3 /usr/local/bin/jekyll build --watch --source /srv/basicblog
jekyll génére un dossier statique /srv/basicblog/_site
server {
listen 80;
listen [::]:80;
## redirect http to https ##
server_name blog.ouestline.net;
return 301 https://$server_name$request_uri;
}
server {
listen 443 ssl http2;
listen [::]:443 ssl http2;
server_name blog.ouestline.net;
root /srv/basicblog/_site/ ;
ssl_certificate /etc/ssl/private/ouestline.net.fullchain.cer.pem;
ssl_certificate_key /etc/ssl/private/ouestline.net.key.pem;
ssl_session_timeout 5m;
ssl_session_cache shared:SSL:50m;
# As suggested by Mozilla : https://wiki.mozilla.org/Security/Server_Side_TLS and https://en.wikipedia.org/wiki/Curve25519
# (this doesn't work on jessie though ...?)
# ssl_ecdh_curve secp521r1:secp384r1:prime256v1;
# As suggested by https://cipherli.st/
ssl_ecdh_curve secp384r1;
ssl_prefer_server_ciphers on;
# Ciphers with modern compatibility
#---------------------------------
# https://mozilla.github.io/server-side-tls/ssl-config-generator/?server=nginx-1.6.2&openssl=1.0.1t&hsts=yes&profile=modern
# Uncomment the following to use modern ciphers, but remove compatibility with some old clients (android < 5.0, Internet Explorer < 10, ...)
ssl_protocols TLSv1.2 TLSv1.3;
ssl_ciphers 'TLS13+AESGCM+AES128:EECDH+AESGCM:EECDH+CHACHA20:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-SHA384:ECDHE-RSA-AES256-SHA384:ECDHE-ECDSA-AES128-SHA256:ECDHE-RSA-AES128-SHA256';
# Uncomment the following directive after DH generation
# > openssl dhparam -out /etc/ssl/private/dh2048.pem -outform PEM -2 2048
#ssl_dhparam /etc/ssl/private/dh2048.pem;
# Follows the Web Security Directives from the Mozilla Dev Lab and the Mozilla Obervatory + Partners
# https://wiki.mozilla.org/Security/Guidelines/Web_Security
# https://observatory.mozilla.org/
add_header Strict-Transport-Security "max-age=63072000; includeSubDomains; preload";
add_header Content-Security-Policy "upgrade-insecure-requests";
add_header Content-Security-Policy-Report-Only "default-src https: data: 'unsafe-inline' 'unsafe-eval'";
add_header X-Content-Type-Options nosniff;
add_header X-XSS-Protection "1; mode=block";
add_header X-Download-Options noopen;
add_header X-Permitted-Cross-Domain-Policies none;
add_header X-Frame-Options "SAMEORIGIN";
index index/;
}
sudo mkdir -p /srv/archives/ # dossier de sauvegarde
sudo chown $USER.$USER -R /srv/archives/ # droits
sudo systemctl stop basicblog # arrêt du service
# on archive les fichiers communs à tous les thèmes
cp /srv/basicblog/_includes/video/ /srv/archives/
cp /srv/basicblog/start_basicblog.sh /srv/archives/
sudo rm -r /srv/basicblog/ # effacer le thème en cours
# On installe le nouveau thème
git clone https://github.com/aigarsdz/brume.git /srv/basicblog
# On copie les fichiers communs depuis archives
cp /srv/archives/video/ /srv/basicblog/_includes/
cp /srv/archives/start_basicblog.sh /srv/basicblog/
cp /srv/archives/_config.yml /srv/basicblog/
cp /srv/archives/Gemfile /srv/basicblog/
sudo rm -r /srv/basicblog/{_posts,images,files} # efface les dossiers s'ils existent
# Créer les liens avec le partage NFS
sudo ln -s /srv/nfs/statique/_posts /srv/basicblog/_posts
sudo ln -s /srv/nfs/statique/images /srv/basicblog/images
sudo ln -s /srv/nfs/statique/files /srv/basicblog/files
# On installe
cd /srv/basicblog
sudo gem install jekyll-toc
bundle
sudo systemctl restart basicblog
cd ~
Recherche rapide avec fichier json et lunr.js
Pour rendre la recherche plus rapide , il faut utiliser un fichier json qui sera construit à chaque compilation.
Créez un fichier /basicblog.json à la racine de votre site Jekyll /srv/basicblog/
Chaque fois que vous exécutez le processus de compilation de Jekyll, Jekyll utilisera /basicblog.json pour déterminer où chercher et ce qu’il faut saisir et il génèrera un fichier _site/basicblog.json.
Page/ de recherche
search/ situé sous la racine /srv/basicblog/ du site statique
#### Analyse json via lunr
Chargement et indexation du fichier pour la recherche , fichier javascript **searchplus.js** dans le dossier **js/**
nano /srv/basicblog/assets/js/searchplus.js
```js
$(document).ready(function () {
var idx ;
var nbart = 0;
var fichier_json = 'basicblog.json';
//http://www.pureexample.com/jquery/get-json/
function executerRequete(callback) {
if (nbart === 0) {
/* set no cache */
$.ajaxSetup({ cache: false });
idx = lunr(function () {
this.field('id');
this.field('title');
this.field('content', { boost: 10 });
this.field('url');
});
var/ = [];
// Get the generated search_data.json file so lunr.js can search it locally.
datas = $.getJSON(fichier_json);
// Wait for the data to load and add it to lunr
datas.then(function(loaded_data){
$.each(loaded_data, function(index, d){
idx.add({
id: index,
title: d.title,
content: d.content,
url: d.url
});
nbart=nbart + 1;
/* //stockage item du fichier
/.push("Titre : ", d.title, ", ",
"URL : ", d.url, ", ",
"Catégorie : ", d.categories, "<br>");
// fin */
});
/* // affichage des items
$("#div381")//.join('')).css("background-color", "orange");
*/
// on lance la fonction de callback, le json est chargé et indexé pour la recherche
callback();
});
$.error(function(jqXHR, textStatus, errorThrown){ /* assign handler */
/* alert(jqXHR.responseText) */
alert("error occurred!");
});
} else {
// on lance la fonction de callback avec le json déjà récupéré précédemment
callback();
}
}
$('input#search').focus();
// Event when the key
$('input#search').on('keyup', function () {
//event.preventDefault();
//var query = $("input#search").val(); // Get the value for the text field
var query = $(this).val();
var results = idx.search(query); // Get lunr to perform a search
display_search_results(results); // Hand the results off to be displayed
});
/* fonction affichage des résultats */
function display_search_results(results) {
var $search_results = $("#results");
// Wait for data to load
datas.then(function(loaded_data) {
// Are there any results?
if (results.length) {
$search_results.empty(); // Clear any old results
// Iterate over the results
results.forEach(function(result) {
var item = loaded_data[result.ref];
/*
var appendString = ';
*/
// Build a snippet of HTML for this result
//var appendString = '<li><a href="' + item.url + '">' + item.title + '</a> ' + item.content + '</li>';
var appendString = '<div class="result"><div class="result-body"><a href="'+item.url+'" class="post-title">'+item.title+'</a><div class="post-date small">'+'</div><p>'+item.content+'</p></div>'
// Add the snippet to the collection of results.
$search_results.append(appendString);
});
} else {
// If there are no results, let the user know.
$search_results/('<li>Aucun élément trouvé...</li>');
}
});
}
function lecture() {
//$("#nombre")/(nbart);
}
// on initialise la lecture au premier élément
executerRequete(lecture);
});