diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/server.js | 44 | ||||
-rw-r--r-- | src/templates/about.html | 2 |
2 files changed, 28 insertions, 18 deletions
diff --git a/src/server.js b/src/server.js index b689ff5..e680266 100644 --- a/src/server.js +++ b/src/server.js @@ -89,29 +89,38 @@ function to_sitemap_xml(host, path, updated){ return `<url><loc>${host}${path}</loc><lastmod>${updated}</lastmod></url>` } -async function sitemap(models) { - urlset = [] - host = "https://marks.kitchen" +async function get_routes(models){ let routes = [ - "/", - "/bread", - "/blog", - "/email", - "/work-square", - "/misc", - "/projects", - "/about", + { "route": "/", "updated": new Date().toISOString() }, + { "route": "/bread", "updated": new Date().toISOString() }, + { "route": "/blog", "updated": new Date().toISOString() }, + { "route": "/email", "updated": new Date().toISOString() }, + { "route": "/work-square", "updated": new Date().toISOString() }, + { "route": "/misc", "updated": new Date().toISOString() }, + { "route": "/projects", "updated": new Date().toISOString() }, + { "route": "/about", "updated": new Date().toISOString() }, ] - routes.forEach(item => { - urlset.push(to_sitemap_xml(host, item, new Date().toISOString())) - }) let posts = (await models.posts.findAll()).map(x => x.get({ plain: true })); posts.forEach(post => { - urlset.push(to_sitemap_xml(host, `/posts/${post.type}/${post.id}`, post.updatedAt.toISOString())) + routes.push( + { "route": `/posts/${post.type}/${post.id}`, "updated": post.updatedAt.toISOString() } + ) }) let tags = (await models.tags.findAll()).map(x => x.get({ plain: true })); tags.forEach(tag => { - urlset.push(to_sitemap_xml(host, `/tags/${tag.text}`, tag.updatedAt.toISOString())) + routes.push( + { "route": `/tags/${tag.text}`, "updated": tag.updatedAt.toISOString() } + ) + }) + return routes +} + +async function sitemap(models) { + let routes = await get_routes(models) + let host = "https://marks.kitchen" + let urlset = [] + routes.forEach(item => { + urlset.push(to_sitemap_xml(host, item.route, item.updated)) }) return `<urlset>${urlset.join("")}</urlset>`; } @@ -264,9 +273,10 @@ function setUpRoutes(models, jwtFunctions, database, templates) { var sessionResult = await database.query("SELECT session, count(id) as c FROM requests GROUP BY session HAVING c > 1", { type: database.QueryTypes.SELECT }) var total = await database.query("select count(distinct session) as t FROM requests", { type: database.QueryTypes.SELECT }) var urlResult = await database.query("SELECT method, url, count(id) as c FROM requests GROUP BY method, url", { type: database.QueryTypes.SELECT }) + let urls = (await get_routes(models)).map(obj => obj.route) + urlResult = urlResult.filter(obj => { return urls.includes(obj.url) }) var logResult = await database.query("SELECT createdAt, session, method, url FROM requests order by createdAt desc limit 15", { type: database.QueryTypes.SELECT }) res.status(200).send({ total: total[0].t, session: sessionResult, url: urlResult, log: logResult }); - next(); } catch (e) { res.status(400).send(e.message); } diff --git a/src/templates/about.html b/src/templates/about.html index b3d504b..800a47a 100644 --- a/src/templates/about.html +++ b/src/templates/about.html @@ -57,7 +57,7 @@ <dd>vim</dd> <dt>Pets<dt> - <dd>One very fluffy black cat</dd> + <dd>One very fluffy black cat, one shorthair kitten</dd> </dl> </div> </body> |