Skip to content
This repository was archived by the owner on Nov 30, 2024. It is now read-only.

Commit bcd0ff0

Browse files
committed
introduced redux
1 parent 0cf5a5c commit bcd0ff0

File tree

117 files changed

+897
-731
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

117 files changed

+897
-731
lines changed

convert.py

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
import re
44
import yaml
55
import slugify
6-
from datetime import date, datetime
76

7+
from datetime import date, datetime
88
from dateutil.parser import parse
99

1010
datasets = yaml.load(open('static/data/datasets.yml'), Loader=yaml.Loader)
@@ -20,10 +20,7 @@ def unpack_date(s):
2020
dates = list(map(lambda d: parse(d).date(), dates))
2121
return {"start": dates[0], "end": dates[1]}
2222

23-
id = 0
2423
for d in datasets:
25-
id += 1
26-
print(id, d['title'])
2724

2825
desc = d['description']
2926
del d['description']
@@ -36,13 +33,19 @@ def unpack_date(s):
3633
else:
3734
d['dates'] = [unpack_date(d['dates'])]
3835

39-
meta = yaml.dump(d, default_flow_style=False)
4036

41-
slug = slugify.slugify(d['title'])
37+
title = slugify.slugify(d['title'])
4238
dt = d['added'].strftime('%Y%m%d')
43-
path = "src/datasets/{}-{}.md".format(dt, slug)
39+
slug = "{}-{}".format(dt, title)
40+
path = "src/datasets/{}.md".format(slug)
41+
42+
d['slug'] = slug
43+
meta = yaml.dump(d, default_flow_style=False)
44+
4445
fh = open(path, 'w')
4546
fh.write('---\n')
4647
fh.write(meta)
4748
fh.write('---\n\n')
48-
fh.write(desc)
49+
fh.write(desc)
50+
51+
print(slug)

gatsby-browser.js

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,2 @@
1-
/**
2-
* Implement Gatsby's Browser APIs in this file.
3-
*
4-
* See: https://www.gatsbyjs.org/docs/browser-apis/
5-
*/
6-
7-
// You can delete this file if you're not using it
1+
import wrapWithProvider from "./wrap-with-provider"
2+
export const wrapRootElement = wrapWithProvider

gatsby-node.js

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ async function makeDatasets(createPage, graphql, pathPrefix) {
1111
allMarkdownRemark {
1212
nodes {
1313
frontmatter {
14+
slug
1415
title
1516
creator
1617
added
@@ -24,22 +25,19 @@ async function makeDatasets(createPage, graphql, pathPrefix) {
2425
url
2526
}
2627
html
27-
fileAbsolutePath
2828
}
2929
}
3030
}
3131
`)
3232

3333
const datasets = []
3434
for (let dataset of results.data.allMarkdownRemark.nodes) {
35-
const id = Number.parseInt(path.basename(dataset.fileAbsolutePath))
3635
const context = {
37-
id: id,
38-
description: dataset.html,
39-
...dataset.frontmatter
36+
...dataset.frontmatter,
37+
description: dataset.html
4038
}
4139
createPage({
42-
path: `/datasets/${id}/`,
40+
path: `/datasets/${dataset.frontmatter.slug}/`,
4341
component: require.resolve(`./src/templates/dataset.js`),
4442
context: context
4543
})

gatsby-ssr.js

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,2 @@
1-
/**
2-
* Implement Gatsby's SSR (Server Side Rendering) APIs in this file.
3-
*
4-
* See: https://www.gatsbyjs.org/docs/ssr-apis/
5-
*/
6-
7-
// You can delete this file if you're not using it
1+
import wrapWithProvider from "./wrap-with-provider"
2+
export const wrapRootElement = wrapWithProvider

package-lock.json

Lines changed: 12 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@
1414
"prop-types": "^15.7.2",
1515
"react": "^16.12.0",
1616
"react-dom": "^16.12.0",
17-
"react-helmet": "^5.2.1"
17+
"react-helmet": "^5.2.1",
18+
"react-redux": "^7.2.0",
19+
"redux": "^4.0.5"
1820
},
1921
"devDependencies": {
2022
"prettier": "^1.19.1"

src/components/datasets.js

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import React from "react"
2+
import PropTypes from "prop-types"
3+
import { Link } from "gatsby"
4+
import { connect } from "react-redux"
5+
6+
const Counter = ({ count, increment }) => (
7+
<div>
8+
<p>Count: {count}</p>
9+
<button onClick={increment}>Increment</button>
10+
</div>
11+
)
12+
13+
Counter.propTypes = {
14+
count: PropTypes.number.isRequired,
15+
increment: PropTypes.func.isRequired,
16+
}
17+
18+
const mapStateToProps = ({ count }) => {
19+
return { count }
20+
}
21+
22+
const mapDispatchToProps = dispatch => {
23+
return { increment: () => dispatch({ type: `INCREMENT` }) }
24+
}
25+
26+
export default connect(mapStateToProps, mapDispatchToProps)(Counter)

src/components/templates/dataset.js

Lines changed: 0 additions & 9 deletions
This file was deleted.

src/datasets/20161223-2016-united-states-presidential-election-tweet-ids.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ dates:
88
- end: 2016-11-10
99
start: 2016-07-13
1010
published: 2016-11-29
11+
slug: 20161223-2016-united-states-presidential-election-tweet-ids
1112
tags:
1213
- politics
1314
title: 2016 United States Presidential Election Tweet Ids

src/datasets/20161223-cdnpoli-tweets-canadian-politics-2015.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ dates:
66
- end: 2015-10-28
77
start: 2015-08-06
88
published: 2016-01-18
9+
slug: 20161223-cdnpoli-tweets-canadian-politics-2015
910
tags:
1011
- politics
1112
title: '#cdnpoli tweets (Canadian Politics, 2015)'

0 commit comments

Comments
 (0)