My name is Mitchell and I have a passion for software development. I am currently a software engineer and enjoy working on personal projects in my free time.
+ My name is Mitchell and I have a passion for software development. I am currently a software engineer and enjoy working on personal projects in my free time.
+
+ );
}
-}
\ No newline at end of file
+}
diff --git a/client/js/redux/actions.js b/client/js/redux/actions.js
index c28ab2c..2be78f0 100644
--- a/client/js/redux/actions.js
+++ b/client/js/redux/actions.js
@@ -1,20 +1,41 @@
import * as types from "./constants";
+import marked from 'marked';
-function initPreview(posts){
- return{
+function initPreview(posts) {
+ return {
type: types.INIT_PREVIEW,
posts
}
}
+function loadPost(post){
+ return {
+ type: types.LOAD_POST,
+ post
+ }
+}
+
//using redux-thunk we can modify actions before they get called
//in this case we can send the http request here rather in the react component
-export function fetchPreview(){
+export function fetchPreview() {
return (dispatch) => {
return fetch('/public/metadata.json')
.then(response => response.json())
.then(json => {
- dispatch(initPreview(json));
+ dispatch(initPreview(json));
+ })
+ .catch(error => {
+ console.log(error);
+ });
+ }
+}
+
+export function fetchPost(category, post) {
+ return (dispatch) => {
+ return fetch(`/public/posts/${category}/${post}.md`)
+ .then(response => response.text())
+ .then(response => {
+ dispatch(loadPost(response));
})
.catch(error => {
console.log(error);
diff --git a/client/js/redux/constants.js b/client/js/redux/constants.js
index cccdbc4..80a87bb 100644
--- a/client/js/redux/constants.js
+++ b/client/js/redux/constants.js
@@ -1,3 +1,4 @@
//constants
export const INIT_PREVIEW = 'INIT_PREVIEW';
-export const FILTER_PREVIEW = 'FILTER_PREVIEW';
\ No newline at end of file
+export const FILTER_PREVIEW = 'FILTER_PREVIEW';
+export const LOAD_POST = 'LOAD_POST';
diff --git a/client/js/redux/reducers.js b/client/js/redux/reducers.js
index 2e678e6..a1131d1 100644
--- a/client/js/redux/reducers.js
+++ b/client/js/redux/reducers.js
@@ -1,20 +1,29 @@
//just using one reducer - use combineReducers from redux to modularize things
-import {combineReducers} from 'redux';
-import {routerReducer} from 'react-router-redux';
+import {
+ combineReducers
+} from 'redux';
+import {
+ routerReducer
+} from 'react-router-redux';
//import typs
import * as types from './constants';
-//defaults -
+//defaults -
const defaultState = {
- preview: {posts: []},
- filteredPreview: {posts: []}
+ preview: {
+ posts: []
+ },
+ filteredPreview: {
+ posts: []
+ },
+ post: ""
};
//default reducer
-function reducer(state = defaultState, action){
+function reducer(state = defaultState, action) {
//every reducer gets called when an action is called - we check for the type to modify our state accordingly
- switch (action.type){
+ switch (action.type) {
case types.INIT_PREVIEW:
return Object.assign({}, state, {
preview: Object.assign({}, state.preview, action.posts)
@@ -22,9 +31,14 @@ function reducer(state = defaultState, action){
case types.FILTER_PREVIEW:
return Object.assign({}, state, {
filteredPreview: Object.assign({}, state.filteredPreview, action.posts)
+ });
+ case types.LOAD_POST:
+ return Object.assign({}, state, {
+ post: action.post
})
+
}
-
+
//return present state if no actions get called
return state;
}
@@ -34,4 +48,4 @@ const allReducers = combineReducers({
routing: routerReducer
});
-export default allReducers;
\ No newline at end of file
+export default allReducers;
diff --git a/metadata.js b/metadata.js
index 34f556e..6762140 100644
--- a/metadata.js
+++ b/metadata.js
@@ -36,13 +36,12 @@ function parse_dir(dir, folder_name){
} else {
const file = fs.readFileSync(dir+post, 'utf8');
const tokens = marked.lexer(file, null);
- const path = dir + post;
const temp = {
- path: path.slice(1, path.length),
+ filename: post.slice(0, post.length - 3),
category: folder_name,
date: post.slice(0, 10),
- title: marked('
' + tokens[0].text + '
'),
- intro: marked(tokens[1].text)
+ title: tokens[0].text,
+ intro: tokens[1].text
}
json.posts.push(temp);
}
diff --git a/posts/2015-07-21-first-post.md b/posts/Old Posts/2015-07-21-first-post.md
similarity index 98%
rename from posts/2015-07-21-first-post.md
rename to posts/Old Posts/2015-07-21-first-post.md
index 997f918..e47d5d8 100644
--- a/posts/2015-07-21-first-post.md
+++ b/posts/Old Posts/2015-07-21-first-post.md
@@ -42,4 +42,4 @@ Now as easy as that sounds, you have a Node web application running on your mach
Express organizes everything nicely in the [Model View Controller](https://en.wikipedia.org/wiki/Model%E2%80%93view%E2%80%93controller) software pattern. Folders are split up into views, routes, and public files. If you are implementing a database, you would also create a "models" folder. There is also a folder which contains Node modules. When you use NPM to install new modules this is where they will be located.
-Node is a very powerful tool that I plan on exploring more in the future. As development of this site continues, I plan to submit more content similar to this.
\ No newline at end of file
+Node is a very powerful tool that I plan on exploring more in the future. As development of this site continues, I plan to submit more content similar to this.
diff --git a/posts/2015-07-28-how-to-use-git.md b/posts/Old Posts/2015-07-28-how-to-use-git.md
similarity index 100%
rename from posts/2015-07-28-how-to-use-git.md
rename to posts/Old Posts/2015-07-28-how-to-use-git.md
diff --git a/posts/2015-08-13-esp8266.md b/posts/Old Posts/2015-08-13-esp8266.md
similarity index 100%
rename from posts/2015-08-13-esp8266.md
rename to posts/Old Posts/2015-08-13-esp8266.md
diff --git a/posts/2015-10-28-wifi-led.md b/posts/Old Posts/2015-10-28-wifi-led.md
similarity index 100%
rename from posts/2015-10-28-wifi-led.md
rename to posts/Old Posts/2015-10-28-wifi-led.md
diff --git a/posts/2015-12-18-temperature-sensor.md b/posts/Old Posts/2015-12-18-temperature-sensor.md
similarity index 100%
rename from posts/2015-12-18-temperature-sensor.md
rename to posts/Old Posts/2015-12-18-temperature-sensor.md
diff --git a/posts/2015-12-29-esp8266-updates.md b/posts/Old Posts/2015-12-29-esp8266-updates.md
similarity index 100%
rename from posts/2015-12-29-esp8266-updates.md
rename to posts/Old Posts/2015-12-29-esp8266-updates.md
diff --git a/posts/2016-01-01-temperature-sensor-server.md b/posts/Old Posts/2016-01-01-temperature-sensor-server.md
similarity index 100%
rename from posts/2016-01-01-temperature-sensor-server.md
rename to posts/Old Posts/2016-01-01-temperature-sensor-server.md
diff --git a/posts/2016-01-04-hosting-digital-ocean.md b/posts/Old Posts/2016-01-04-hosting-digital-ocean.md
similarity index 100%
rename from posts/2016-01-04-hosting-digital-ocean.md
rename to posts/Old Posts/2016-01-04-hosting-digital-ocean.md
diff --git a/posts/2016-05-22-flashing-esp8266.md b/posts/Old Posts/2016-05-22-flashing-esp8266.md
similarity index 100%
rename from posts/2016-05-22-flashing-esp8266.md
rename to posts/Old Posts/2016-05-22-flashing-esp8266.md