update index with prerendered table for googlebot & add script to do it

This commit is contained in:
2017-05-28 18:54:01 -04:00
parent d6af8c9ee0
commit 89c99431ec
3 changed files with 416 additions and 29 deletions

24
index.js Normal file
View File

@@ -0,0 +1,24 @@
const cheerio = require('cheerio');
const mustache = require('./js/mustache.js');
const fs = require('fs');
const stores = require('./stores.json');
fs.readFile('./index.html', function (err, data) {
if (err) { throw err; }
const $ = cheerio.load(data);
stores.sort(
function(a, b) {
var aname = a.name.toLowerCase();
var bname = b.name.toLowerCase();
return aname === bname ? 0 : +(aname > bname) || -1;
}
);
$('#Stores').html(mustache.render($('#Table').html(), {rows: stores}));
fs.writeFile('./index.html', $.html(), (err) => {
if (err) throw err;
console.log('Default view updated.');
});
});