Skip to content

[WIP] Split classes #12

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 42 additions & 10 deletions gatsby-node.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ exports.onCreateNode = ({ node }) => {

exports.createPages = ({ boundActionCreators, graphql }) => {
const { createPage } = boundActionCreators;

const blogPostTemplate = path.resolve(`src/templates/blog-post.js`);
const indexTemplate = path.resolve(`src/templates/home.js`);
// const req = "/\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}\\+\\d{2}:\\d{2}/g";
Expand Down Expand Up @@ -67,17 +66,50 @@ exports.createPages = ({ boundActionCreators, graphql }) => {
}, // additional data can be passed via context
});
ret.data.allMarkdownRemark.edges.push({
excerpt: node["excerpt"],
frontmatter: node["frontmatter"],
node: {
excerpt: node["excerpt"],
frontmatter: node["frontmatter"],
},
});
}
});
// createPage({
// path: "/",
// component: indexTemplate,
// context: {
// data: ret.data,
// },
// });

// filter posts to offload computation
const { edges: posts } = ret.data.allMarkdownRemark;
var vals = {};
const temp = posts.filter(
(post) =>
post.node.frontmatter.path != null &&
post.node.frontmatter.date != null &&
post.node.frontmatter.title != null &&
post.node.frontmatter.path.indexOf("..") < 0 &&
post.node.frontmatter.path.length > 0
);
temp.map(({ node: post }) => {
// Parse the URL by class
var cut = post.frontmatter.path.split("/");
cut = cut.slice(1);
// If a class and subsection is defined (lecture, disc, etc)
if (cut.length >= 2) {
// Add class to cut if not exists
if (!vals.hasOwnProperty(cut[0])) {
vals[cut[0]] = {};
}
// Add subsection if not exists
if (!vals[cut[0]].hasOwnProperty(cut[1])) {
vals[cut[0]][cut[1]] = [];
}
// Add the post to the data
vals[cut[0]][cut[1]].push(post);
}
});

createPage({
path: "/",
component: indexTemplate,
context: {
data: vals,
},
});
});
};
212 changes: 0 additions & 212 deletions src/pages/index.js

This file was deleted.

54 changes: 3 additions & 51 deletions src/templates/home.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,9 @@ import moment from "moment";
import {
Typography,
Grid,
// Link as MaterialLink,
makeStyles,
Card,
CardContent,
// Paper,
} from "@material-ui/core";
import SEO from "../components/seo";
import Layout from "../components/layout";
Expand All @@ -19,47 +17,20 @@ const useStyles = makeStyles((theme) => ({
maxHeight: 375,
borderRadius: 8,
},
// backgroundColor:
// theme.palette.type === "light"
// ? "#F3F3F7"
// : "#FF0000",
// },

gridRoot: {
justifyContent: "center",
alignItems: "center",
// textAlign: "center",
},
}));

export default function Index(props) {
const classes = useStyles();
const [assortedPosts, setPosts] = React.useState({});
const { pageContext } = props;
const { data } = pageContext;
const { edges: posts } = data.allMarkdownRemark;
const data = pageContext.data;
React.useEffect(() => {
var vals = {};
// const temp = posts.filter(
// post =>
// post.node.frontmatter.path != null &&
// post.node.frontmatter.date != null &&
// post.node.frontmatter.title != null &&
// post.node.frontmatter.path.length > 0
// )
posts.map((post) => {
var cut = post.frontmatter.path.split("/");
cut = cut.slice(1);
if (cut.length >= 2) {
if (!vals.hasOwnProperty(cut[0])) {
vals[cut[0]] = {};
}
if (!vals[cut[0]].hasOwnProperty(cut[1])) {
vals[cut[0]][cut[1]] = [];
}
vals[cut[0]][cut[1]].push(post);
}
});
setPosts(vals);
setPosts(data);
}, []);

const generatePostsBox = (outerKey, postList) => {
Expand Down Expand Up @@ -168,22 +139,3 @@ export default function Index(props) {
</Layout>
);
}

// export const pageQuery = graphql`
// query postsQuery {
// allMarkdownRemark(sort: { order: DESC, fields: [frontmatter___date] }) {
// edges {
// node {
// excerpt(pruneLength: 100)
// html
// id
// frontmatter {
// date(formatString: "MMMM DD, YYYY")
// path
// title
// }
// }
// }
// }
// }
// `