Skip to content

Commit d17f1e0

Browse files
author
Bart Hazen
committed
Implement sitemap.
1 parent 3e3261e commit d17f1e0

File tree

7 files changed

+78
-7
lines changed

7 files changed

+78
-7
lines changed

.github/workflows/build_default.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ jobs:
1616

1717
strategy:
1818
matrix:
19-
node-version: [12.x]
19+
node-version: [14.x]
2020

2121
steps:
2222
- uses: actions/checkout@v2
@@ -27,4 +27,5 @@ jobs:
2727
- run: npm install
2828
- run: npm audit fix
2929
- run: npm run build --if-present
30+
- run: npm run sitemap
3031
# - run: npm test --passWithNoTests

.github/workflows/deploy_master.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ jobs:
1616
run: npm audit fix
1717
- name: Build
1818
run: npm run build
19+
- name: Create sitemap
20+
run: npm run sitemap
1921
- name: Archive production artifact
2022
uses: actions/upload-artifact@master
2123
with:

firebase.json

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,23 @@
66
"**/.*",
77
"**/node_modules/**"
88
],
9+
"redirects": [
10+
{
11+
"source": "/sitemap",
12+
"destination": "/sitemap.xml",
13+
"type": 301
14+
},
15+
{
16+
"source": "/sitemap/**",
17+
"destination": "/sitemap.xml",
18+
"type": 302
19+
}
20+
],
921
"rewrites": [
22+
{
23+
"source": "/sitemap.xml",
24+
"destination": "/sitemap.xml"
25+
},
1026
{
1127
"source": "**",
1228
"destination": "/index.html"

package.json

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
"name": "python-create",
33
"version": "0.1.1",
44
"private": true,
5+
"type": "module",
56
"dependencies": {
67
"@material-ui/core": "^4.9.8",
78
"@material-ui/icons": "^4.9.1",
@@ -18,7 +19,9 @@
1819
"react-dom": "^16.13.1",
1920
"react-helmet": "^6.1.0",
2021
"react-markdown": "^4.3.1",
21-
"react-router-dom": "^5.1.2",
22+
"react-router": "^5.2.0",
23+
"react-router-dom": "^5.2.0",
24+
"react-router-sitemap": "^1.2.0",
2225
"react-scripts": "3.4.1",
2326
"react-syntax-highlighter": "^12.2.1",
2427
"typeface-roboto": "0.0.75"
@@ -27,7 +30,8 @@
2730
"start": "react-scripts start",
2831
"build": "react-scripts build",
2932
"test": "react-scripts test",
30-
"eject": "react-scripts eject"
33+
"eject": "react-scripts eject",
34+
"sitemap": "babel-node src/routes/builder.js"
3135
},
3236
"eslintConfig": {
3337
"extends": "react-app"
@@ -43,5 +47,11 @@
4347
"last 1 firefox version",
4448
"last 1 safari version"
4549
]
50+
},
51+
"devDependencies": {
52+
"babel-cli": "^6.26.0",
53+
"babel-preset-es2015": "^6.24.1",
54+
"babel-preset-react": "^6.24.1",
55+
"babel-register": "^6.26.0"
4656
}
4757
}

src/pages/Homepage/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ export default class Homepage extends React.Component {
2525
<Header onDrawerToggle={this.props.handleDrawerToggle} />
2626
<Helmet>
2727
<title>Homepage | Python Create</title>
28-
<meta name="description" content="Python Create offers generators and instructions on using Python optimally. Get help writing your code by the tools we offer." />
28+
<meta name="description" content="Python Create offers generators and instructions on using Python optimally. Get help writing your code with the tools we offer." />
2929
<meta name="robots" content="index, follow" />
3030
</Helmet>
3131
<main className={this.props.classes.main}>

src/routes/builder.js

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import pkg from 'react-router-sitemap';
2+
const { sitemapBuilder } = pkg;
3+
4+
// import { routeDetails } from './index.js';
5+
import path from 'path'; // add path which will be needed for file write
6+
import fs from 'fs'; // import file system object
7+
8+
const paths = [
9+
"/setup-py-generator",
10+
"/"
11+
];
12+
13+
// use your website root address here. Optimally you can
14+
// include dev and production environments with variables
15+
const hostname = 'https://pythoncreate.com';
16+
17+
const dest = path.resolve('./build', 'sitemap.xml');
18+
19+
const sitemap = sitemapBuilder(
20+
hostname,
21+
paths
22+
);
23+
24+
// write sitemap.xml file in /public folder
25+
// Access the sitemap content by converting it with .toString() method
26+
fs.writeFileSync(dest, sitemap.toString())

src/routes/index.js

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,27 @@ import SetupPy from "pages/SetupPy";
66
import Homepage from "pages/Homepage";
77
import RouteWithScene from "./RouteWithScene";
88

9-
export default function Routes() {
9+
export const routes = [
10+
{
11+
path: "/setup-py-generator",
12+
scene: Paperbase,
13+
component: SetupPy
14+
},
15+
{
16+
path: "/",
17+
scene: Paperbase,
18+
component: Homepage
19+
}
20+
];
21+
22+
export default function RoutesSwitch() {
1023
return (
1124
<Switch>
12-
<RouteWithScene path="/setup-py-generator" scene={Paperbase} component={SetupPy} />
13-
<RouteWithScene path="/" scene={Paperbase} component={Homepage} />
25+
{
26+
routes.map((route, index) => (
27+
<RouteWithScene path={route.path} scene={route.scene} component={route.component} key={index} />
28+
))
29+
}
1430
<Redirect to="/" />
1531
</Switch>
1632
);

0 commit comments

Comments
 (0)