diff --git a/lib/guide.js b/lib/guide.js index 9696f9496..4b27b8ee8 100644 --- a/lib/guide.js +++ b/lib/guide.js @@ -1,6 +1,6 @@ -import guides from "storage/guides"; -import authors from "storage/authors"; -import siteConfig from "storage/site"; +import guides from 'storage/guides'; +import authors from 'storage/authors'; +import siteConfig from 'storage/site'; export const getAllGuides = () => { return guides.filter(guide => !guide.draft) diff --git a/next.config.js b/next.config.js index 60dbf35e1..cbc3387d1 100644 --- a/next.config.js +++ b/next.config.js @@ -6,7 +6,7 @@ const { getPageRoutes, getGuideRoutes, getRoadmapRoutes, -} = require("./path-map"); +} = require("./scripts/path-map"); const withMDX = require('@next/mdx')({ extension: /\.(md|mdx)?$/, diff --git a/package.json b/package.json index 2c8453ae3..e90d8bbae 100644 --- a/package.json +++ b/package.json @@ -5,10 +5,9 @@ "license": "BSD-4-Clause", "scripts": { "dev": "next", - "build": "next build", - "start": "next start", - "html": "next build && next export && echo 'roadmap.sh' > out/CNAME && touch out/.nojekyll", + "html": "next build && next export && echo 'roadmap.sh' > out/CNAME && '' > out/.nojekyll", "serve:out": "serve out", + "sitemap": "node scripts/sitemap.js", "deploy": "NODE_DEBUG=gh-pages gh-pages -d out", "test": "jest", "test:watch": "jest --watch" diff --git a/path-map.js b/scripts/path-map.js similarity index 93% rename from path-map.js rename to scripts/path-map.js index e00d48a67..53894671a 100644 --- a/path-map.js +++ b/scripts/path-map.js @@ -1,10 +1,10 @@ const path = require('path'); const glob = require('glob'); -const guides = require('./storage/guides.json'); -const roadmaps = require('./storage/roadmaps'); +const guides = require('../storage/guides.json'); +const roadmaps = require('../storage/roadmaps'); -const PAGES_PATH = path.join(__dirname, 'pages'); +const PAGES_PATH = path.join(__dirname, '../pages'); /** * Generate the page routes from the page files inside `/pages` diff --git a/scripts/sitemap.js b/scripts/sitemap.js new file mode 100644 index 000000000..7154fe094 --- /dev/null +++ b/scripts/sitemap.js @@ -0,0 +1,126 @@ +// This is a development script executed in the build step of pages +const fs = require('fs'); +const path = require('path'); +const guides = require('../storage/guides'); +const { getPageRoutes, getGuideRoutes, getRoadmapRoutes } = require('./path-map'); + +const DOMAIN = 'https://roadmap.sh'; +const PAGES_DIR = path.join(__dirname, '../pages'); +const STORAGE_PATH = path.join(__dirname, '../storage'); +const SITEMAP_PATH = 'static/sitemap.xml'; +const STATIC_PATH = path.join(__dirname, '../static'); + +// Set the header +const xmlHeader = ` +`; + +// Wrap all pages in tags +const xmlUrlWrapper = nodes => `${xmlHeader} +${nodes} +`; + +const getSlugPriority = (pageSlug) => { + if (pageSlug === '/') { + return '1.0'; + } + + const slugPriorities = [ + ['/roadmaps', '/guides'], // 1.0 + ['/signup'], // 0.9 + ['/about'], // 0.8 + ]; + + const foundIndex = slugPriorities.findIndex( + routes => routes.some(route => pageSlug.startsWith(route)) + ); + + if (foundIndex !== -1) { + return parseFloat((10 - foundIndex) / 10) + .toFixed(1); + } + + return 0.5; +}; + +function generateNode({ + slug, + basePath, + fileName, + priority = null, + date = null, + frequency = 'monthly' +}) { + const pagePath = path.join(basePath, fileName); + let pageStats = {}; + try { + pageStats = fs.lstatSync(pagePath); + } catch(e) { + console.log(`File not found: ${pagePath}`); + pageStats = { mtime: (new Date()) } + } + + return ` + ${DOMAIN}${slug} + ${ frequency } + ${date || pageStats.mtime.toISOString()} + ${ priority || getSlugPriority(slug) } + `; +} + +function generateSiteMap() { + const pageRoutes = getPageRoutes(); + const pageSlugs = Object.keys(pageRoutes) + .filter(route => ![ + '/privacy', + '/terms' + ].includes(route)); + + const pagesChunk = pageSlugs.map(pageSlug => { + return generateNode({ + basePath: PAGES_DIR, + fileName: `${pageRoutes[pageSlug].page}.js`, + slug: pageSlug, + }); + }); + + // Chunks for each of the guides + const guideRoutes = getGuideRoutes(); + const guideSlugs = Object.keys(guideRoutes); + const guidesChunk = guideSlugs.map(guideSlug => { + const foundGuide = guides.find(guide => guide.url === guideSlug) || {}; + return generateNode({ + basePath: STORAGE_PATH, + fileName: `${guideSlug}.md`, + slug: guideSlug, + date: foundGuide.updatedAt, + priority: '1.0', + }); + }); + + // Chunks for each of the roadmaps + const roadmapRoutes = getRoadmapRoutes(); + const roadmapSlugs = Object.keys(roadmapRoutes); + const roadmapsChunk = roadmapSlugs.map(roadmapSlug => { + const [, role, year = 'latest'] = roadmapSlug.split('/'); + return generateNode({ + basePath: STATIC_PATH, + fileName: `/roadmaps/${year}/${role}.png`, + slug: roadmapSlug, + priority: '1.0', + }); + }); + + const nodes = [ + ...roadmapsChunk, + ...guidesChunk, + ...pagesChunk, + ]; + + const sitemap = `${xmlUrlWrapper(nodes.join('\n'))}`; + + fs.writeFileSync(SITEMAP_PATH, sitemap); + + console.log(`sitemap.xml with ${nodes.length} entries was written to ${SITEMAP_PATH}`); +} + +generateSiteMap(); diff --git a/static/aras.jpeg b/static/aras.jpeg deleted file mode 100644 index 4b39fd887..000000000 Binary files a/static/aras.jpeg and /dev/null differ diff --git a/static/authors/aras.jpeg b/static/authors/aras.jpeg deleted file mode 100644 index 4b39fd887..000000000 Binary files a/static/authors/aras.jpeg and /dev/null differ diff --git a/static/authors/dan-abramov.jpeg b/static/authors/dan-abramov.jpeg deleted file mode 100644 index b0b1e413d..000000000 Binary files a/static/authors/dan-abramov.jpeg and /dev/null differ diff --git a/static/authors/idnan.jpeg b/static/authors/idnan.jpeg deleted file mode 100644 index 177b27696..000000000 Binary files a/static/authors/idnan.jpeg and /dev/null differ diff --git a/static/authors/ziishaned.png b/static/authors/ziishaned.png deleted file mode 100644 index 89ee1dcbe..000000000 Binary files a/static/authors/ziishaned.png and /dev/null differ diff --git a/static/chris-coyier.jpeg b/static/chris-coyier.jpeg deleted file mode 100644 index 19a51718f..000000000 Binary files a/static/chris-coyier.jpeg and /dev/null differ diff --git a/static/dan-abramov.jpeg b/static/dan-abramov.jpeg deleted file mode 100644 index b0b1e413d..000000000 Binary files a/static/dan-abramov.jpeg and /dev/null differ diff --git a/static/sitemap.xml b/static/sitemap.xml new file mode 100644 index 000000000..b963747b3 --- /dev/null +++ b/static/sitemap.xml @@ -0,0 +1,141 @@ + + + + https://roadmap.sh/frontend + monthly + 2019-11-14T08:22:01.000Z + 1.0 + + + https://roadmap.sh/frontend/latest + monthly + 2019-11-14T08:22:01.000Z + 1.0 + + + https://roadmap.sh/frontend/2018 + monthly + 2019-11-14T08:22:01.000Z + 1.0 + + + https://roadmap.sh/frontend/2017 + monthly + 2019-11-14T08:22:01.000Z + 1.0 + + + https://roadmap.sh/backend + monthly + 2019-11-14T08:22:01.000Z + 1.0 + + + https://roadmap.sh/backend/latest + monthly + 2019-11-14T08:22:01.000Z + 1.0 + + + https://roadmap.sh/backend/2018 + monthly + 2019-11-14T08:22:01.000Z + 1.0 + + + https://roadmap.sh/backend/2017 + monthly + 2019-11-14T08:22:01.000Z + 1.0 + + + https://roadmap.sh/devops + monthly + 2019-11-14T08:22:01.000Z + 1.0 + + + https://roadmap.sh/devops/latest + monthly + 2019-11-14T08:22:01.000Z + 1.0 + + + https://roadmap.sh/devops/2018 + monthly + 2019-11-14T08:22:01.000Z + 1.0 + + + https://roadmap.sh/devops/2017 + monthly + 2019-11-14T08:22:01.000Z + 1.0 + + + https://roadmap.sh/fullstack + monthly + 2019-11-14T17:21:23.153Z + 1.0 + + + https://roadmap.sh/qa-engineer + monthly + 2019-11-14T17:21:23.153Z + 1.0 + + + https://roadmap.sh/guides/design-patterns-for-humans + monthly + 2019-10-09T12:00:00.860Z + 1.0 + + + https://roadmap.sh/guides/journey-to-http2 + monthly + 2018-12-04T12:00:00.860Z + 1.0 + + + https://roadmap.sh/guides/dns-in-one-picture + monthly + 2018-12-04T12:00:00.860Z + 1.0 + + + https://roadmap.sh/guides/http-caching + monthly + 2018-11-29T17:00:00.860Z + 1.0 + + + https://roadmap.sh/about + monthly + 2019-11-14T08:22:01.000Z + 0.8 + + + https://roadmap.sh/guides + monthly + 2019-11-14T08:22:01.000Z + 1.0 + + + https://roadmap.sh/ + monthly + 2019-11-14T08:22:01.000Z + 1.0 + + + https://roadmap.sh/roadmaps + monthly + 2019-11-14T08:22:01.000Z + 1.0 + + + https://roadmap.sh/signup + monthly + 2019-11-14T08:22:01.000Z + 0.9 + + \ No newline at end of file diff --git a/test/path-map.spec.js b/test/path-map.spec.js index 0ab131bd5..43b1692b3 100644 --- a/test/path-map.spec.js +++ b/test/path-map.spec.js @@ -7,7 +7,7 @@ const { getPageRoutes, getGuideRoutes, getRoadmapRoutes -} = require("../path-map"); +} = require("../scripts/path-map"); describe("Build scripts tests", () => { test('it should generate valid pathmap for pages', () => {