-
Notifications
You must be signed in to change notification settings - Fork 57
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #669 from thanhson1085/master
Add sitemap, meta page
- Loading branch information
Showing
8 changed files
with
112 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
const express = require('express') | ||
const router = express.Router() | ||
const db = require('../models/mongodb') | ||
const _ = require('lodash') | ||
|
||
router.get('/sitemap.xml', async (req, res) => { | ||
const domain = 'https://master.tomochain.com' | ||
let routes = (await db.Candidate.find() | ||
.sort({ capacityNumber: -1 }) | ||
.limit(500).lean().exec()).map(c => { | ||
return `${domain}/candidate/${c.candidate}` | ||
}) | ||
routes = _.concat(routes, (await db.Voter.find() | ||
.sort({ capacityNumber: -1 }) | ||
.limit(2000).lean().exec()).map(v => { | ||
return `${domain}/voter/${v.voter}` | ||
})) | ||
const lastmod = (new Date()).toISOString() | ||
const list = routes | ||
.map(route => `<url><loc>${route}</loc><lastmod>${lastmod}</lastmod></url>`) | ||
.join('\r') | ||
|
||
routes = _.concat(routes, `${domain}`) | ||
|
||
res.header('Content-Type', 'application/xml') | ||
/* eslint-disable */ | ||
return res.send(`<?xml version="1.0" encoding="UTF-8"?><urlset xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:image="http://www.google.com/schemas/sitemap-image/1.1" xsi:schemaLocation="http://www.sitemaps.org/schemas/sitemap/0.9 http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd http://www.google.com/schemas/sitemap-image/1.1 http://www.google.com/schemas/sitemap-image/1.1/sitemap-image.xsd" xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">${list}</urlset>`) | ||
/* eslint-enable no-alert */ | ||
}) | ||
|
||
module.exports = router |
Oops, something went wrong.