diff options
author | Mark Powers <mark@marks.kitchen> | 2021-11-04 21:24:41 -0500 |
---|---|---|
committer | Mark Powers <mark@marks.kitchen> | 2021-11-04 21:24:41 -0500 |
commit | 85a103d6a02a50ce28cbb44c2e693000d9b7388d (patch) | |
tree | 0ffc7ef981d8892f74efc1048cbbb3ce843bc510 /src/server.js | |
parent | bbab3cf95b85b0314e9f47328bb2a38c540a5345 (diff) |
Filter admin paths based on site map urls
Diffstat (limited to 'src/server.js')
-rw-r--r-- | src/server.js | 44 |
1 files changed, 27 insertions, 17 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); } |