|
|
@ -18,7 +18,7 @@ const xmlHeader = `<?xml version="1.0" encoding="UTF-8"?> |
|
|
|
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.sitemaps.org/schemas/sitemap/0.9 http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd">`;
|
|
|
|
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.sitemaps.org/schemas/sitemap/0.9 http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd">`;
|
|
|
|
|
|
|
|
|
|
|
|
// Wrap all pages in <urlset> tags
|
|
|
|
// Wrap all pages in <urlset> tags
|
|
|
|
const xmlUrlWrapper = nodes => `${xmlHeader} |
|
|
|
const xmlUrlWrapper = (nodes) => `${xmlHeader} |
|
|
|
${nodes} |
|
|
|
${nodes} |
|
|
|
</urlset>`; |
|
|
|
</urlset>`; |
|
|
|
|
|
|
|
|
|
|
@ -28,23 +28,17 @@ function getSlugPriority(pageSlug) { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
const slugPriorities = [ |
|
|
|
const slugPriorities = [ |
|
|
|
[ |
|
|
|
['/roadmaps', '/guides', '/watch', '/podcasts'], // 1.0
|
|
|
|
'/roadmaps', |
|
|
|
|
|
|
|
'/guides', |
|
|
|
|
|
|
|
'/watch', |
|
|
|
|
|
|
|
'/podcasts' |
|
|
|
|
|
|
|
], // 1.0
|
|
|
|
|
|
|
|
['/signup'], // 0.9
|
|
|
|
['/signup'], // 0.9
|
|
|
|
['/about'] // 0.8
|
|
|
|
['/about'], // 0.8
|
|
|
|
]; |
|
|
|
]; |
|
|
|
|
|
|
|
|
|
|
|
const foundIndex = slugPriorities.findIndex( |
|
|
|
const foundIndex = slugPriorities.findIndex((routes) => |
|
|
|
routes => routes.some(route => pageSlug.startsWith(route)) |
|
|
|
routes.some((route) => pageSlug.startsWith(route)) |
|
|
|
); |
|
|
|
); |
|
|
|
|
|
|
|
|
|
|
|
if (foundIndex !== -1) { |
|
|
|
if (foundIndex !== -1) { |
|
|
|
return parseFloat((10 - foundIndex) / 10) |
|
|
|
return parseFloat((10 - foundIndex) / 10).toFixed(1); |
|
|
|
.toFixed(1); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return 0.5; |
|
|
|
return 0.5; |
|
|
@ -56,12 +50,12 @@ function getPageRoutes() { |
|
|
|
'**/_*.tsx', // private non-page files e.g. _document.js
|
|
|
|
'**/_*.tsx', // private non-page files e.g. _document.js
|
|
|
|
'**/[[]*[]].tsx', // Ignore dynamic pages i.e. `page/[something].js` files
|
|
|
|
'**/[[]*[]].tsx', // Ignore dynamic pages i.e. `page/[something].js` files
|
|
|
|
'**/[[]*[]]/*.tsx', // Ignore files inside dynamic pages i.e. `[something]/abc.js`
|
|
|
|
'**/[[]*[]]/*.tsx', // Ignore files inside dynamic pages i.e. `[something]/abc.js`
|
|
|
|
'**/components/*.tsx' // Ignore the component files
|
|
|
|
'**/components/*.tsx', // Ignore the component files
|
|
|
|
] |
|
|
|
], |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
const pageRoutes = {}; |
|
|
|
const pageRoutes = {}; |
|
|
|
files.forEach(file => { |
|
|
|
files.forEach((file) => { |
|
|
|
const pageName = file.replace(PAGES_PATH, '').replace('.tsx', ''); |
|
|
|
const pageName = file.replace(PAGES_PATH, '').replace('.tsx', ''); |
|
|
|
const pagePath = pageName.replace('/index', '') || '/'; |
|
|
|
const pagePath = pageName.replace('/index', '') || '/'; |
|
|
|
|
|
|
|
|
|
|
@ -78,7 +72,7 @@ function generateNode(nodeProps) { |
|
|
|
fileName, |
|
|
|
fileName, |
|
|
|
priority = null, |
|
|
|
priority = null, |
|
|
|
date = null, |
|
|
|
date = null, |
|
|
|
frequency = 'monthly' |
|
|
|
frequency = 'monthly', |
|
|
|
} = nodeProps; |
|
|
|
} = nodeProps; |
|
|
|
|
|
|
|
|
|
|
|
const pagePath = path.join(basePath, fileName); |
|
|
|
const pagePath = path.join(basePath, fileName); |
|
|
@ -87,7 +81,7 @@ function generateNode(nodeProps) { |
|
|
|
pageStats = fs.lstatSync(pagePath); |
|
|
|
pageStats = fs.lstatSync(pagePath); |
|
|
|
} catch (e) { |
|
|
|
} catch (e) { |
|
|
|
console.log(`File not found: ${pagePath}`); |
|
|
|
console.log(`File not found: ${pagePath}`); |
|
|
|
pageStats = { mtime: (new Date()) }; |
|
|
|
pageStats = { mtime: new Date() }; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return `<url>
|
|
|
|
return `<url>
|
|
|
@ -100,27 +94,25 @@ function generateNode(nodeProps) { |
|
|
|
|
|
|
|
|
|
|
|
function generateSiteMap() { |
|
|
|
function generateSiteMap() { |
|
|
|
const pageRoutes = getPageRoutes(); |
|
|
|
const pageRoutes = getPageRoutes(); |
|
|
|
const pageSlugs = Object.keys(pageRoutes) |
|
|
|
const pageSlugs = Object.keys(pageRoutes).filter( |
|
|
|
.filter(route => ![ |
|
|
|
(route) => !['/privacy', '/terms'].includes(route) |
|
|
|
'/privacy', |
|
|
|
); |
|
|
|
'/terms' |
|
|
|
|
|
|
|
].includes(route)); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const pagesChunk = pageSlugs.map(pageSlug => { |
|
|
|
const pagesChunk = pageSlugs.map((pageSlug) => { |
|
|
|
return generateNode({ |
|
|
|
return generateNode({ |
|
|
|
basePath: PAGES_DIR, |
|
|
|
basePath: PAGES_DIR, |
|
|
|
fileName: `${pageRoutes[pageSlug].page}.tsx`, |
|
|
|
fileName: `${pageRoutes[pageSlug].page}.tsx`, |
|
|
|
slug: pageSlug |
|
|
|
slug: pageSlug, |
|
|
|
}); |
|
|
|
}); |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
const guidesChunk = guides.map(guide => { |
|
|
|
const guidesChunk = guides.map((guide) => { |
|
|
|
return generateNode({ |
|
|
|
return generateNode({ |
|
|
|
basePath: GUIDES_PATH, |
|
|
|
basePath: GUIDES_PATH, |
|
|
|
fileName: `${guide.id}.md`, |
|
|
|
fileName: `${guide.id}.md`, |
|
|
|
slug: `/guides/${guide.id}`, |
|
|
|
slug: `/guides/${guide.id}`, |
|
|
|
date: guide.updatedAt, |
|
|
|
date: guide.updatedAt, |
|
|
|
priority: '1.0' |
|
|
|
priority: '1.0', |
|
|
|
}); |
|
|
|
}); |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
@ -130,21 +122,19 @@ function generateSiteMap() { |
|
|
|
fileName: roadmap.metaPath.replace('/roadmaps', ''), |
|
|
|
fileName: roadmap.metaPath.replace('/roadmaps', ''), |
|
|
|
slug: `/${roadmap.id}`, |
|
|
|
slug: `/${roadmap.id}`, |
|
|
|
date: roadmap.updatedAt, |
|
|
|
date: roadmap.updatedAt, |
|
|
|
priority: '1.0' |
|
|
|
priority: '1.0', |
|
|
|
}); |
|
|
|
}); |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
const nodes = [ |
|
|
|
const nodes = [...roadmapsChunk, ...guidesChunk, ...pagesChunk]; |
|
|
|
...roadmapsChunk, |
|
|
|
|
|
|
|
...guidesChunk, |
|
|
|
|
|
|
|
...pagesChunk |
|
|
|
|
|
|
|
]; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const sitemap = `${xmlUrlWrapper(nodes.join('\n'))}`; |
|
|
|
const sitemap = `${xmlUrlWrapper(nodes.join('\n'))}`; |
|
|
|
|
|
|
|
|
|
|
|
fs.writeFileSync(SITEMAP_PATH, sitemap); |
|
|
|
fs.writeFileSync(SITEMAP_PATH, sitemap); |
|
|
|
|
|
|
|
|
|
|
|
console.log(`sitemap.xml with ${nodes.length} entries was written to ${SITEMAP_PATH}`); |
|
|
|
console.log( |
|
|
|
|
|
|
|
`sitemap.xml with ${nodes.length} entries was written to ${SITEMAP_PATH}` |
|
|
|
|
|
|
|
); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
generateSiteMap(); |
|
|
|
generateSiteMap(); |
|
|
|