├── .gitignore
├── README.md
├── app.js
├── components
├── BlogList.jsx
├── BlogSingle.jsx
├── Footer.jsx
├── Header.jsx
├── Loading.jsx
├── Nav.jsx
├── WorkList.jsx
└── WorkSingle.jsx
├── config.js
├── dispatcher
└── AppDispatcher.js
├── dist
├── bundle.js
├── css
│ ├── bootstrap.css
│ ├── bootstrap.min.css
│ ├── clean-blog.css
│ ├── clean-blog.min.css
│ └── cosmic-custom.css
├── fonts
│ ├── glyphicons-halflings-regular.eot
│ ├── glyphicons-halflings-regular.svg
│ ├── glyphicons-halflings-regular.ttf
│ ├── glyphicons-halflings-regular.woff
│ └── glyphicons-halflings-regular.woff2
├── img
│ ├── about-bg.jpg
│ ├── contact-bg.jpg
│ ├── home-bg.jpg
│ ├── post-bg.jpg
│ └── post-sample-image.jpg
└── js
│ ├── bootstrap.js
│ ├── bootstrap.min.js
│ ├── clean-blog.js
│ ├── clean-blog.min.js
│ ├── jquery.js
│ └── jquery.min.js
├── index.html
├── package.json
├── pages
├── Blog.jsx
├── Default.jsx
├── NoMatch.jsx
└── Work.jsx
├── server.js
├── stores
└── AppStore.js
├── tonyspirocom.json
└── webpack.config.js
/.gitignore:
--------------------------------------------------------------------------------
1 | .DS_Store
2 | node_modules
3 |
4 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # tonyspiro.com-react
2 | This app demonstrates how to build a portfolio blog using React on the [Cosmic JS](https://cosmicjs.com) content platform. Uses [React Router](https://github.com/rackt/react-router), Flux and Cosmic JS to load pages fast in a single page application.
3 |
4 | #####[View a demo here](http://tonyspiro-react.cosmicapp.co)
5 |
6 | ### Getting started
7 |
8 | #####Install
9 | ```
10 | git clone https://github.com/tonyspiro/tonyspiro.com-react
11 | cd tonyspiro.com-react
12 | npm install
13 | ```
14 | #####Run webpack dev
15 | ```
16 | npm run dev
17 | ```
18 | Go to [http://localhost:8080/webpack-dev-server](http://localhost:8080/webpack-dev-server)
19 | #####Run production
20 | ```
21 | npm start
22 | ```
23 | Go to [http://localhost:8000](http://localhost:8000)
24 |
25 | ### About the app
26 | * My original website at [http://tonyspiro.com](tonyspiro.com) is built on the WordPress platform. After running benchmark tests with ApacheBench between my WordPress site and this React / Cosmic JS version, the React version clocks in over 10x FASTER to "first paint". This is the real benefit from the React / API set up, less server overhead and faster page load times between "pages". You can really see a significant speed difference on mobile.
27 |
28 | WordPress (26.7 seconds):
29 |
30 |
31 |
32 | React / Cosmic JS (2.3 seconds):
33 |
34 |
35 |
36 | * Benchmarking was performed by running ApacheBench. ```ab -n 100 -c 10 http://tonyspiro.com/``` and ```ab -n 100 -c 10 http://tonyspiro.com:8000/```
37 |
38 | * React Router is used to perform the navigation between "pages". Running ```npm start``` boots a node server that allows for the pages to render properly when loaded in from a url or on page refresh.
39 |
40 | * The [Cosmic JS browser package](https://github.com/cosmicjs/cosmicjs-browser) is used to pull the data from the Cosmic JS API into the app.
41 |
42 | * [Webpack](https://webpack.github.io/) is used for the dev and build process to turn ES6 JS into browser-friendly ES5 JS using the babel-loader.
43 |
44 | * The front end style is based off [a theme from Start Bootstrap](http://startbootstrap.com/template-overviews/clean-blog/).
45 |
46 | ###How I did it
47 | Here are the steps that were taken to build this app:
48 |
49 | 1. I exported the data out of [my WP blog](http://tonyspiro.com) using the [Cosmic JS WP Export plugin](https://github.com/cosmicjs/cosmicjs-wp-export). The exported JSON file is included in this repo at [tonyspirocom.json](https://github.com/tonyspiro/tonyspiro.com-react/blob/master/tonyspirocom.json)
50 | 2. I created a new bucket in [Cosmic JS](https://cosmicjs.com)
51 | 3. I then imported the JSON file into my Cosmic JS bucket
52 | 4. I built the React app and edited [config.js](https://github.com/tonyspiro/tonyspiro.com-react/blob/master/config.js) to point to the correct bucket in Cosmic JS
53 |
--------------------------------------------------------------------------------
/app.js:
--------------------------------------------------------------------------------
1 | // app.js
2 | import React from 'react';
3 | import ReactDOM from 'react-dom';
4 | import { Router, Route, IndexRoute, Link } from 'react-router';
5 | import createBrowserHistory from 'history/lib/createBrowserHistory';
6 | let history = createBrowserHistory();
7 |
8 | // Utilities
9 | import AppStore from './stores/AppStore';
10 | import AppDispatcher from './dispatcher/AppDispatcher';
11 |
12 | // Components
13 | import Nav from './components/Nav';
14 | import Footer from './components/Footer';
15 | import Loading from './components/Loading';
16 |
17 | // Pages
18 | import Blog from './pages/Blog';
19 | import Work from './pages/Work';
20 | import Default from './pages/Default';
21 | import NoMatch from './pages/NoMatch';
22 |
23 |
24 | let getAppState = () => {
25 | return {
26 | data: AppStore.data
27 | };
28 | }
29 |
30 | class App extends React.Component{
31 |
32 | // Method to setState based upon Store changes
33 | _onChange() {
34 | this.setState(getAppState());
35 | }
36 |
37 | constructor() {
38 |
39 | super();
40 |
41 | // API data
42 | AppDispatcher.dispatch({
43 | action: 'init-app'
44 | });
45 |
46 | }
47 |
48 | // Add change listeners to stores
49 | componentDidMount() {
50 | AppStore.addChangeListener(this._onChange.bind(this));
51 | }
52 |
53 | // Remove change listeners from stores
54 | componentWillUnmount() {
55 | AppStore.removeChangeListener(this._onChange.bind(this));
56 | }
57 |
58 | render(){
59 |
60 | if(!AppStore.data.ready){
61 | let style = {
62 | marginTop: 120
63 | }
64 | return (
65 |
Posted by Tony Spiro on { created }
61 |Posted by Tony Spiro on { created }
61 |