Skip to content

Commit 0d7f2f4

Browse files
committed
Include sitemap
1 parent 3c56cad commit 0d7f2f4

8 files changed

Lines changed: 104 additions & 7 deletions

File tree

.babelrc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"presets": ["env", "react", "stage-0"]
3+
}

package.json

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,11 @@
1414
"new:component": "node src/config/componentGenerator.js",
1515
"new:content": "node src/config/contentGenerator.js",
1616
"content": "./node_modules/.bin/filestojson src/config/filestojson.js",
17+
"sitemap": "./node_modules/.bin/babel-node src/config/sitemap.js",
1718
"precommit": "lint-staged",
1819
"prestart": "npm run content",
1920
"start": "react-scripts start",
20-
"prebuild": "npm run content",
21+
"prebuild": "npm run content && npm run sitemap",
2122
"build": "react-scripts build && react-snap",
2223
"postbuild": "yarn docs:build",
2324
"test": "react-scripts test --env=jsdom --testPathIgnorePatterns=src/config/",
@@ -73,8 +74,12 @@
7374
"@storybook/addon-options": "^3.3.11",
7475
"@storybook/addons": "^3.3.11",
7576
"@storybook/react": "^3.3.11",
77+
"babel-cli": "^6.26.0",
7678
"babel-core": "^6.26.0",
7779
"babel-eslint": "^8.2.1",
80+
"babel-preset-env": "^1.6.1",
81+
"babel-preset-react": "^6.24.1",
82+
"babel-preset-stage-0": "^6.24.1",
7883
"cross-env": "^5.1.3",
7984
"ejs": "^2.5.7",
8085
"enzyme": "^3.3.0",
@@ -87,6 +92,7 @@
8792
"react-snap": "^1.11.3",
8893
"react-test-renderer": "^16.2.0",
8994
"serve": "^6.4.11",
95+
"sitemap": "^1.13.0",
9096
"storybook-router": "^0.3.2",
9197
"stylelint": "^8.4.0",
9298
"stylelint-config-standard": "^18.0.0"

public/google8493ccc1f985f325.html

Lines changed: 0 additions & 1 deletion
This file was deleted.

public/robots.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
User-agent: *
2+
Disallow: /

public/sitemap.xml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:news="http://www.google.com/schemas/sitemap-news/0.9" xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:mobile="http://www.google.com/schemas/sitemap-mobile/1.0" xmlns:image="http://www.google.com/schemas/sitemap-image/1.1" xmlns:video="http://www.google.com/schemas/sitemap-video/1.1">
3+
<url> <loc>http://bernardodiasdacruz.com/</loc> <changefreq>weekly</changefreq> <priority>1.0</priority> </url>
4+
<url> <loc>http://bernardodiasdacruz.com/archive</loc> <changefreq>weekly</changefreq> <priority>0.5</priority> </url>
5+
<url> <loc>http://bernardodiasdacruz.com/search</loc> <changefreq>weekly</changefreq> <priority>0.5</priority> </url>
6+
<url> <loc>http://bernardodiasdacruz.com/about-me</loc> <changefreq>monthly</changefreq> <priority>0.5</priority> </url>
7+
<url> <loc>http://bernardodiasdacruz.com/2018-03-16-how-to-fix-custom-domain-ovewriting-with-gh-pages-deploy-script</loc> <changefreq>weekly</changefreq> <priority>0.8</priority> </url>
8+
<url> <loc>http://bernardodiasdacruz.com/2018-03-16-component-styles-isolation-dealing-with-css-inheritance</loc> <changefreq>weekly</changefreq> <priority>0.8</priority> </url>
9+
<url> <loc>http://bernardodiasdacruz.com/2018-03-13-categories-and-typography</loc> <changefreq>weekly</changefreq> <priority>0.8</priority> </url>
10+
<url> <loc>http://bernardodiasdacruz.com/2018-03-06-inject-google-analytics-tag-manager-in-a-meteor-app</loc> <changefreq>weekly</changefreq> <priority>0.8</priority> </url>
11+
<url> <loc>http://bernardodiasdacruz.com/2018-03-05-fetching-from-instagram-using-facebook-graph-api</loc> <changefreq>weekly</changefreq> <priority>0.8</priority> </url>
12+
<url> <loc>http://bernardodiasdacruz.com/2018-03-05-redesign-and-better-typography</loc> <changefreq>weekly</changefreq> <priority>0.8</priority> </url>
13+
<url> <loc>http://bernardodiasdacruz.com/2018-02-27-opportunity-cost</loc> <changefreq>weekly</changefreq> <priority>0.8</priority> </url>
14+
<url> <loc>http://bernardodiasdacruz.com/2018-02-27-comments-section</loc> <changefreq>weekly</changefreq> <priority>0.8</priority> </url>
15+
<url> <loc>http://bernardodiasdacruz.com/2018-02-26-boilerplate-generators</loc> <changefreq>weekly</changefreq> <priority>0.8</priority> </url>
16+
<url> <loc>http://bernardodiasdacruz.com/2018-02-26-blog-progress</loc> <changefreq>weekly</changefreq> <priority>0.8</priority> </url>
17+
<url> <loc>http://bernardodiasdacruz.com/2018-02-23-hello-world</loc> <changefreq>weekly</changefreq> <priority>0.8</priority> </url>
18+
<url> <loc>http://bernardodiasdacruz.com/category/frontend</loc> <changefreq>weekly</changefreq> <priority>0.8</priority> </url>
19+
<url> <loc>http://bernardodiasdacruz.com/category/integrations</loc> <changefreq>weekly</changefreq> <priority>0.8</priority> </url>
20+
<url> <loc>http://bernardodiasdacruz.com/category/strategy</loc> <changefreq>weekly</changefreq> <priority>0.8</priority> </url>
21+
<url> <loc>http://bernardodiasdacruz.com/category/this-blog</loc> <changefreq>weekly</changefreq> <priority>0.8</priority> </url>
22+
</urlset>

src/config/sitemap.js

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
import path from 'path'
2+
import sm from 'sitemap'
3+
import fs from 'fs'
4+
5+
import config from '.'
6+
import data from '../data.json'
7+
import {
8+
getAllPostsForListing,
9+
getAllCategoriesForListing,
10+
} from '../selectors/data'
11+
12+
const OUTPUT_FILE = path.resolve(__dirname, '..', '..', 'public', 'sitemap.xml')
13+
14+
const postsUrls = getAllPostsForListing({data})
15+
.map(post => ({
16+
url: `${config.PUBLIC_URL}/${post.handle}`,
17+
changefreq: 'weekly',
18+
priority: 0.8,
19+
}))
20+
21+
const categoriesUrls = getAllCategoriesForListing({data})
22+
.map(category => ({
23+
url: `${config.PUBLIC_URL}/category/${category.handle}`,
24+
changefreq: 'weekly',
25+
priority: 0.8,
26+
}))
27+
28+
const sitemap = sm.createSitemap({
29+
hostname: 'http://bernardodiasdacruz.com',
30+
cacheTime: 600000, //600 sec (10 min) cache purge period
31+
urls: [
32+
{ url: '/', changefreq: 'weekly', priority: 1 },
33+
{ url: '/archive', changefreq: 'weekly', priority: 0.5 },
34+
{ url: '/search', changefreq: 'weekly', priority: 0.5 },
35+
{ url: '/about-me', changefreq: 'monthly', priority: 0.5 },
36+
...postsUrls,
37+
...categoriesUrls,
38+
]
39+
})
40+
41+
fs.writeFileSync(OUTPUT_FILE, sitemap.toString())
42+
43+
console.log(`Sitemap written at ${OUTPUT_FILE}`)

src/selectors/data.js

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { pathOr, union } from 'ramda'
22

3-
export const getAllPostData = (state) =>
3+
export const getAllPostsData = (state) =>
44
pathOr({}, ['data', 'posts'], state)
55

66
export const getPostData = (state, post) =>
@@ -36,21 +36,21 @@ export const getAllPostDetails = (state, post) => ({
3636
})
3737

3838
export const getAllPostsForListing = (state) => Object
39-
.keys(getAllPostData(state))
39+
.keys(getAllPostsData(state))
4040
.map(post => ({...getAllPostDetails(state, post)}))
4141

4242
export const getAllPostsTags = (state) => {
4343
let tags = []
4444
Object
45-
.keys(getAllPostData(state))
45+
.keys(getAllPostsData(state))
4646
.forEach(post => tags = union(tags, getPostTags(state, post)))
4747
return tags
4848
}
4949

5050
export const getAllPostsCategories = (state) => {
5151
let categories = []
5252
Object
53-
.keys(getAllPostData(state))
53+
.keys(getAllPostsData(state))
5454
.forEach(post => categories = union(categories, [getPostCategory(state, post)]))
5555
return categories
5656
}
@@ -75,6 +75,9 @@ export const getAllArticleDetails = (state, article) => ({
7575
files: getArticleData(state, article),
7676
})
7777

78+
export const getAllCategoriesData = (state) =>
79+
pathOr({}, ['data', 'categories'], state)
80+
7881
export const getCategoryData = (state, category) =>
7982
pathOr({}, ['data', 'categories', category], state)
8083

@@ -95,7 +98,11 @@ export const getAllCategoryDetails = (state, category) => ({
9598
files: getCategoryData(state, category),
9699
})
97100

101+
export const getAllCategoriesForListing = (state) => Object
102+
.keys(getAllCategoriesData(state))
103+
.map(category => ({...getAllCategoryDetails(state, category)}))
104+
98105
export const getAllPostsForListingByCategory = (state, category) => Object
99-
.keys(getAllPostData(state))
106+
.keys(getAllPostsData(state))
100107
.filter(post => category === getPostCategory(state, post))
101108
.map(post => ({...getAllPostDetails(state, post)}))

yarn.lock

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8646,6 +8646,13 @@ signal-exit@^3.0.0, signal-exit@^3.0.2:
86468646
version "3.0.2"
86478647
resolved "https://registry.yarnpkg.com/signal-exit/-/signal-exit-3.0.2.tgz#b5fdc08f1287ea1178628e415e25132b73646c6d"
86488648

8649+
sitemap@^1.13.0:
8650+
version "1.13.0"
8651+
resolved "https://registry.yarnpkg.com/sitemap/-/sitemap-1.13.0.tgz#569cbe2180202926a62a266cd3de09c9ceb43f83"
8652+
dependencies:
8653+
underscore "^1.7.0"
8654+
url-join "^1.1.0"
8655+
86498656
slash@^1.0.0:
86508657
version "1.0.0"
86518658
resolved "https://registry.yarnpkg.com/slash/-/slash-1.0.0.tgz#c41f2f6c39fc16d1cd17ad4b5d896114ae470d55"
@@ -9396,6 +9403,10 @@ ultron@~1.1.0:
93969403
version "1.1.1"
93979404
resolved "https://registry.yarnpkg.com/ultron/-/ultron-1.1.1.tgz#9fe1536a10a664a65266a1e3ccf85fd36302bc9c"
93989405

9406+
underscore@^1.7.0:
9407+
version "1.8.3"
9408+
resolved "https://registry.yarnpkg.com/underscore/-/underscore-1.8.3.tgz#4f3fb53b106e6097fcf9cb4109f2a5e9bdfa5022"
9409+
93999410
underscore@~1.4.4:
94009411
version "1.4.4"
94019412
resolved "https://registry.yarnpkg.com/underscore/-/underscore-1.4.4.tgz#61a6a32010622afa07963bf325203cf12239d604"
@@ -9534,6 +9545,10 @@ urijs@^1.16.1:
95349545
version "1.19.0"
95359546
resolved "https://registry.yarnpkg.com/urijs/-/urijs-1.19.0.tgz#d8aa284d0e7469703a6988ad045c4cbfdf08ada0"
95369547

9548+
url-join@^1.1.0:
9549+
version "1.1.0"
9550+
resolved "https://registry.yarnpkg.com/url-join/-/url-join-1.1.0.tgz#741c6c2f4596c4830d6718460920d0c92202dc78"
9551+
95379552
url-loader@0.6.2, url-loader@^0.6.2:
95389553
version "0.6.2"
95399554
resolved "https://registry.yarnpkg.com/url-loader/-/url-loader-0.6.2.tgz#a007a7109620e9d988d14bce677a1decb9a993f7"

0 commit comments

Comments
 (0)