Skip to content

Commit

Permalink
Oddk/sitemap (#74)
Browse files Browse the repository at this point in the history
  • Loading branch information
mpolidori committed Mar 10, 2023
1 parent 405ce63 commit 46227af
Showing 1 changed file with 5 additions and 7 deletions.
12 changes: 5 additions & 7 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -284,11 +284,9 @@ module.exports = function (app) {
const robotsTxt = fs.readFileSync(robotsPath, 'utf8')

if (!robotsTxt.includes('Sitemap:')) {
const hostname = 'https://' + req.get('host')
const hostname = config.get('SITE_URL')
const sitemapUrl = hostname + '/sitemap.xml'
const wwwHostname = hostname.replace('://', '://www.')
const wwwSitemapUrl = wwwHostname + '/sitemap.xml'
const robotsTxtWithSitemap = robotsTxt + '\nUser-agent: *\nSitemap: ' + sitemapUrl + '\nSitemap: ' + wwwSitemapUrl
const robotsTxtWithSitemap = robotsTxt + '\nUser-agent: *\nSitemap: ' + sitemapUrl

fs.writeFileSync(robotsPath, robotsTxtWithSitemap)
}
Expand All @@ -304,7 +302,7 @@ module.exports = function (app) {
res.header('Content-Type', 'application/xml');
res.header('Content-Encoding', 'gzip');

const hostname = 'https://' + req.get('host')
const hostname = config.get('SITE_URL')

try {
const smStream = new SitemapStream({ hostname: hostname })
Expand All @@ -319,7 +317,7 @@ module.exports = function (app) {

for (let collection of collectionsArray) {
smStream.write({
url: `/collection/${collection.name}`,
url: `/collections/${collection.name}`,
img: collection.image
})
}
Expand All @@ -330,7 +328,7 @@ module.exports = function (app) {

for (let organization of organizationsArray) {
smStream.write({
url: `/organization/${organization.name}`,
url: `/${organization.name}`,
img: organization.image
})
}
Expand Down

0 comments on commit 46227af

Please sign in to comment.