Skip to content
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
154 changes: 77 additions & 77 deletions gatsby-config.js
Original file line number Diff line number Diff line change
@@ -1,83 +1,83 @@
module.exports = {
graphqlTypegen: true,
siteMetadata: {
title: 'Gatsby + Netlify CMS Starter',
description:
'This repo contains an example business website that is built with Gatsby, and Netlify CMS.It follows the JAMstack architecture by using Git as a single source of truth, and Netlify for continuous deployment, and CDN distribution.',
},
plugins: [
'gatsby-plugin-react-helmet-async',
'gatsby-plugin-fix-fouc',
{
resolve: 'gatsby-plugin-sass',
options: {
sassOptions: {
indentedSyntax: true,
},
},
},
{
// keep as first gatsby-source-filesystem plugin for gatsby image support
resolve: 'gatsby-source-filesystem',
options: {
path: `${__dirname}/static/img`,
name: 'uploads',
},
},
{
resolve: 'gatsby-source-filesystem',
options: {
path: `${__dirname}/src/pages`,
name: 'pages',
},
graphqlTypegen: true,
siteMetadata: {
title: "Gatsby + Netlify CMS Starter",
description:
"This repo contains an example business website that is built with Gatsby, and Netlify CMS.It follows the JAMstack architecture by using Git as a single source of truth, and Netlify for continuous deployment, and CDN distribution.",
},
{
resolve: 'gatsby-source-filesystem',
options: {
path: `${__dirname}/src/img`,
name: 'images',
},
},
`gatsby-plugin-image`,
'gatsby-plugin-sharp',
'gatsby-transformer-sharp',
{
resolve: 'gatsby-transformer-remark',
options: {
plugins: [
'gatsby-remark-relative-images',
{
resolve: 'gatsby-remark-images',
plugins: [
"gatsby-plugin-react-helmet-async",
"gatsby-plugin-fix-fouc",
{
resolve: "gatsby-plugin-sass",
options: {
// It's important to specify the maxWidth (in pixels) of
// the content container as this plugin uses this as the
// base for generating different widths of each image.
maxWidth: 2048,
sassOptions: {
indentedSyntax: true,
},
},
},
{
resolve: 'gatsby-remark-copy-linked-files',
},
{
// keep as first gatsby-source-filesystem plugin for gatsby image support
resolve: "gatsby-source-filesystem",
options: {
destinationDir: 'static',
path: `${__dirname}/static/img`,
name: "uploads",
},
},
],
},
},
{
resolve: 'gatsby-plugin-decap-cms',
options: {
modulePath: `${__dirname}/src/cms/cms.js`,
},
},
{
resolve: 'gatsby-plugin-purgecss', // purges all unused/unreferenced css rules
options: {
develop: true, // Activates purging in npm run develop
purgeOnly: ['/bulma-style.sass'], // applies purging only on the bulma css file
printRejected: true,
},
}, // must be after other CSS plugins
'gatsby-plugin-netlify', // make sure to keep it last in the array
],
}
},
{
resolve: "gatsby-source-filesystem",
options: {
path: `${__dirname}/src/pages`,
name: "pages",
},
},
{
resolve: "gatsby-source-filesystem",
options: {
path: `${__dirname}/src/img`,
name: "images",
},
},
`gatsby-plugin-image`,
"gatsby-plugin-sharp",
"gatsby-transformer-sharp",
{
resolve: "gatsby-transformer-remark",
options: {
plugins: [
"gatsby-remark-relative-images",
{
resolve: "gatsby-remark-images",
options: {
// It's important to specify the maxWidth (in pixels) of
// the content container as this plugin uses this as the
// base for generating different widths of each image.
maxWidth: 2048,
},
},
{
resolve: "gatsby-remark-copy-linked-files",
options: {
destinationDir: "static",
},
},
],
},
},
{
resolve: "gatsby-plugin-decap-cms",
options: {
modulePath: `${__dirname}/src/cms/cms.js`,
},
},
{
resolve: "gatsby-plugin-purgecss", // purges all unused/unreferenced css rules
options: {
develop: true, // Activates purging in npm run develop
purgeOnly: ["/bulma-style.sass"], // applies purging only on the bulma css file
printRejected: true,
},
}, // must be after other CSS plugins
"gatsby-plugin-netlify", // make sure to keep it last in the array
],
};
180 changes: 90 additions & 90 deletions gatsby-node.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
const _ = require('lodash')
const fs = require('fs')
const path = require('path')
const { createFilePath } = require('gatsby-source-filesystem')
const _ = require("lodash");
const fs = require("fs");
const path = require("path");
const { createFilePath } = require("gatsby-source-filesystem");
const {
stringWithDefault,
resolveToArray,
resolveSlug,
resolveSoftwareTools,
} = require('./gatsbyutils/gatsby-resolver-utils')
const { DATASET_PATH } = require('./gatsbyutils/constants')
stringWithDefault,
resolveToArray,
resolveSlug,
resolveSoftwareTools,
} = require("./gatsbyutils/gatsby-resolver-utils");
const { DATASET_PATH } = require("./gatsbyutils/constants");

const read = (p) => fs.readFileSync(path.join(__dirname, p), 'utf8')
const read = (p) => fs.readFileSync(path.join(__dirname, p), "utf8");

/**
* Markdown in /src/pages/ with these templateKeys are data-only
Expand All @@ -21,9 +21,9 @@ const read = (p) => fs.readFileSync(path.join(__dirname, p), 'utf8')
const DATA_ONLY_PAGES = ["software", "dataset", "allenite", "program"];

exports.createSchemaCustomization = ({ actions, schema }) => {
const { createTypes } = actions
const typeDefs = [
`"""
const { createTypes } = actions;
const typeDefs = [
`"""
Nested materials and methods block for idea posts.
"""
type MaterialsAndMethods {
Expand All @@ -49,10 +49,10 @@ exports.createSchemaCustomization = ({ actions, schema }) => {
softwareTool: MarkdownRemark @link(by: "fields.slug")
customDescription: String
}`,
]
createTypes(read('gatsby/schema/base.gql'))
createTypes(typeDefs)
}
];
createTypes(read("gatsby/schema/base.gql"));
createTypes(typeDefs);
};

/**
* Resolvers ensure data shape/presence after queries, or provide
Expand Down Expand Up @@ -116,48 +116,48 @@ exports.createResolvers = ({ createResolvers }) => {
* Skips creating pages for data-only pages.
*/
exports.createPages = ({ actions, graphql }) => {
const { createPage } = actions

return graphql(`
{
allMarkdownRemark(limit: 1000) {
edges {
node {
id
fields {
slug
}
frontmatter {
tags
templateKey
draft
const { createPage } = actions;

return graphql(`
{
allMarkdownRemark(limit: 1000) {
edges {
node {
id
fields {
slug
}
frontmatter {
tags
templateKey
draft
}
}
}
}
}
}
}
}
`).then((result) => {
if (result.errors) {
result.errors.forEach((e) => console.error(e.toString()))
return Promise.reject(result.errors)
}
`).then((result) => {
if (result.errors) {
result.errors.forEach((e) => console.error(e.toString()));
return Promise.reject(result.errors);
}

const posts = result.data.allMarkdownRemark.edges
const posts = result.data.allMarkdownRemark.edges;

posts.forEach((edge) => {
const id = edge.node.id
const templateKey = edge.node.frontmatter.templateKey
posts.forEach((edge) => {
const id = edge.node.id;
const templateKey = edge.node.frontmatter.templateKey;

// Skip creating pages for data-only pages (software, dataset, etc.)
if (DATA_ONLY_PAGES.includes(templateKey)) {
return
}
// Skip creating pages for data-only pages (software, dataset, etc.)
if (DATA_ONLY_PAGES.includes(templateKey)) {
return;
}

// Skip creating pages for drafts
// Toggle boolean flag on dev-example pages during development
if (edge.node.frontmatter.draft === true) {
return
}
// Skip creating pages for drafts
// Toggle boolean flag on dev-example pages during development
if (edge.node.frontmatter.draft === true) {
return;
}

createPage({
path: edge.node.fields.slug,
Expand All @@ -172,41 +172,41 @@ exports.createPages = ({ actions, graphql }) => {
});
});

// Tag pages:
let tags = []
// Iterate through each post, putting all found tags into `tags`
posts.forEach((edge) => {
if (_.get(edge, `node.frontmatter.tags`)) {
tags = tags.concat(edge.node.frontmatter.tags)
}
})
// Eliminate duplicate tags
tags = _.uniq(tags)

// Make tag pages
tags.forEach((tag) => {
const tagPath = `/tags/${_.kebabCase(tag)}/`

createPage({
path: tagPath,
component: path.resolve(`src/templates/tags.tsx`),
context: {
tag,
},
})
})
})
}
// Tag pages:
let tags = [];
// Iterate through each post, putting all found tags into `tags`
posts.forEach((edge) => {
if (_.get(edge, `node.frontmatter.tags`)) {
tags = tags.concat(edge.node.frontmatter.tags);
}
});
// Eliminate duplicate tags
tags = _.uniq(tags);

// Make tag pages
tags.forEach((tag) => {
const tagPath = `/tags/${_.kebabCase(tag)}/`;

createPage({
path: tagPath,
component: path.resolve(`src/templates/tags.tsx`),
context: {
tag,
},
});
});
});
};

exports.onCreateNode = ({ node, actions, getNode }) => {
const { createNodeField } = actions

if (node.internal.type === `MarkdownRemark`) {
const value = createFilePath({ node, getNode })
createNodeField({
name: `slug`,
node,
value,
})
}
}
const { createNodeField } = actions;

if (node.internal.type === `MarkdownRemark`) {
const value = createFilePath({ node, getNode });
createNodeField({
name: `slug`,
node,
value,
});
}
};
14 changes: 7 additions & 7 deletions src/cms/cms.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import CMS from 'decap-cms-app'
import CMS from "decap-cms-app";

import AboutPagePreview from './preview-templates/AboutPagePreview'
import IdeaPostPreview from './preview-templates/IdeaPostPreview'
import IndexPagePreview from './preview-templates/IndexPagePreview'
import AboutPagePreview from "./preview-templates/AboutPagePreview";
import IdeaPostPreview from "./preview-templates/IdeaPostPreview";
import IndexPagePreview from "./preview-templates/IndexPagePreview";

CMS.registerPreviewTemplate('index', IndexPagePreview)
CMS.registerPreviewTemplate('about', AboutPagePreview)
CMS.registerPreviewTemplate('idea', IdeaPostPreview)
CMS.registerPreviewTemplate("index", IndexPagePreview);
CMS.registerPreviewTemplate("about", AboutPagePreview);
CMS.registerPreviewTemplate("idea", IdeaPostPreview);
Loading