Skip to content

Commit

Permalink
Implement base constants and Gatsby configuration with basic plugins
Browse files Browse the repository at this point in the history
All metadata and constants, like defined in GH-26, are
placed in the corresponding folders for configurations (`src/config`)
and data (`src/data`). Initially this includes information stored in
the `package.json` file of the project and the `nord` package which has
also been installed.
This commit also adds base and important constants that will be used
later on:

- `src/config/internal/constants.js` - Provides internally used
  constants
- `src/config/internal/nodes.js` - Provides internally used data about
  custom Gatsby GraphQL API nodes.
- `src/config/routes/constants.js` - Provides routing constants.
- `src/config/routes/mappings.js` - Provides route mapping constants.

GH-27
  • Loading branch information
arcticicestudio committed Nov 18, 2018
1 parent acf5aee commit b8e9ff2
Show file tree
Hide file tree
Showing 8 changed files with 460 additions and 22 deletions.
81 changes: 81 additions & 0 deletions gatsby-config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
/*
* Copyright (C) 2018-present Arctic Ice Studio <[email protected]>
* Copyright (C) 2018-present Sven Greb <[email protected]>
*
* Project: Nord Docs
* Repository: https://github.com/arcticicestudio/nord-docs
* License: MIT
*/

/**
* @file The Gatsby configuration.
* @author Arctic Ice Studio <[email protected]>
* @author Sven Greb <[email protected]>
* @see https://gatsbyjs.org/docs/gatsby-config
* @since 0.1.0
*/

const { metadataNord, metadataNordDocs } = require("./src/data/project");
const { sourceInstanceTypes } = require("./src/config/internal/nodes");
const {
BASE_DIR_CONTENT,
BASE_DIR_ASSETS_IMAGES,
BASE_DIR_CONFIG,
BASE_DIR_PAGES
} = require("./src/config/internal/constants");
const { BASE_PUBLIC_URL } = require("./src/config/routes/constants");

module.exports = {
siteMetadata: {
nord: { ...metadataNord },
...metadataNordDocs
},
plugins: [
"gatsby-plugin-react-helmet",
"gatsby-plugin-catch-links",
"gatsby-plugin-remove-trailing-slashes",
"gatsby-plugin-no-sourcemaps",
"gatsby-transformer-yaml",
{
resolve: "gatsby-plugin-canonical-urls",
options: {
siteUrl: `${BASE_PUBLIC_URL}`
}
},
{
resolve: "gatsby-source-filesystem",
options: {
name: "images",
path: `${__dirname}/${BASE_DIR_ASSETS_IMAGES}`
}
},
{
resolve: "gatsby-source-filesystem",
options: {
name: `${sourceInstanceTypes.blog.id}`,
path: `${__dirname}/${BASE_DIR_CONTENT}/${sourceInstanceTypes.blog.path}/`
}
},
{
resolve: "gatsby-source-filesystem",
options: {
name: "config",
path: `${__dirname}/${BASE_DIR_CONFIG}/`
}
},
{
resolve: "gatsby-source-filesystem",
options: {
name: `${sourceInstanceTypes.docs.id}`,
path: `${__dirname}/${BASE_DIR_CONTENT}/${sourceInstanceTypes.docs.path}/`
}
},
{
resolve: "gatsby-source-filesystem",
options: {
name: "pages",
path: `${__dirname}/${BASE_DIR_PAGES}/`
}
}
]
};
33 changes: 12 additions & 21 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
"gatsby-plugin-react-helmet": "3.0.2",
"gatsby-plugin-remove-trailing-slashes": "2.0.5",
"gatsby-source-filesystem": "2.0.8",
"gatsby-transformer-yaml": "2.1.5"
"gatsby-transformer-yaml": "2.1.5",
"nord": ">=0.2.1 <1.0.0"
}
}
90 changes: 90 additions & 0 deletions src/config/internal/constants.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
/*
* Copyright (C) 2018-present Arctic Ice Studio <[email protected]>
* Copyright (C) 2018-present Sven Greb <[email protected]>
*
* Project: Nord Docs
* Repository: https://github.com/arcticicestudio/nord-docs
* License: MIT
*/

/**
* @file Provides internally used constants.
* @author Arctic Ice Studio <[email protected]>
* @author Sven Greb <[email protected]>
* @since 0.1.0
*/

/**
* The absolute path of the content base directory starting from the project root.
*
* @constant {String}
* @since 0.1.0
*/
const BASE_DIR_CONTENT = "content";

/**
* The absolute path of the sources base directory starting from the project root.
*
* @constant {string}
* @since 0.1.0
*/
const BASE_DIR_SRC = "src";

/**
* The absolute path of the assets base directory starting from the project root.
*
* @constant {string}
* @since 0.1.0
*/
const BASE_DIR_ASSETS = `${BASE_DIR_SRC}/assets`;

/**
* The absolute path of the assets directory for images starting from the project root.
*
* @constant {string}
* @since 0.1.0
*/
const BASE_DIR_ASSETS_IMAGES = `${BASE_DIR_ASSETS}/images`;

/**
* The absolute path of the config base directory starting from the project root.
*
* @constant {string}
* @since 0.1.0
*/
const BASE_DIR_CONFIG = `${BASE_DIR_SRC}/config`;

/**
* The absolute path of the pages base directory starting from the project root.
*
* @constant {string}
* @since 0.1.0
*/
const BASE_DIR_PAGES = `${BASE_DIR_SRC}/pages`;

/**
* The internal type for MDX nodes.
*
* @constant {String}
* @since 0.1.0
* @see https://github.com/mdx-js/mdx
*/
const NODE_TYPE_MDX = "Mdx";

/**
* Regular expression to match the date of a blog post from the file path.
*
* @constant {RegExp}
* @since 0.1.0
*/
const REGEX_BLOG_POST_DATE = /([0-9]+)\/([0-9]+)\/([0-9]+)\/(.+)/;

module.exports = {
BASE_DIR_ASSETS,
BASE_DIR_ASSETS_IMAGES,
BASE_DIR_CONFIG,
BASE_DIR_CONTENT,
BASE_DIR_PAGES,
NODE_TYPE_MDX,
REGEX_BLOG_POST_DATE
};
80 changes: 80 additions & 0 deletions src/config/internal/nodes.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
/*
* Copyright (C) 2018-present Arctic Ice Studio <[email protected]>
* Copyright (C) 2018-present Sven Greb <[email protected]>
*
* Project: Nord Docs
* Repository: https://github.com/arcticicestudio/nord-docs
* License: MIT
*/

/**
* @file Provides internally used data about custom Gatsby GraphQL API nodes.
* @author Arctic Ice Studio <[email protected]>
* @author Sven Greb <[email protected]>
* @since 0.1.0
*/

/**
* The names of the source instance types and their paths relative to the project root path.
*
* @type {Object}
* @since 0.1.0
*/
const sourceInstanceTypes = {
blog: { id: "blog", path: "blog" },
docs: { id: "docs", path: "docs" }
};

/**
* The additional fields added to nodes with the Gatsby Node `onCreateNode` API.
*
* @type {Object}
* @see https://gatsbyjs.org/docs/node-apis
* @see https://next.gatsbyjs.org/docs/node-apis/#onCreateNode
* @since 0.1.0
*/
const nodeFields = {
/**
* The date a blog post has been created.
*/
date: {
name: "date",
type: "string",
targetContentSourceTypes: [sourceInstanceTypes.blog.id]
},
/**
* The content type of the node based on the source instance of the configured `gatsby-source-filesystem` Gatsby
* plugin.
*/
contentSourceType: {
name: "contentSourceType",
type: "string",
targetContentSourceTypes: [...Object.keys(sourceInstanceTypes).map(name => sourceInstanceTypes[name].id)]
},
/**
* The slug of the node without the prepended parent route.
*/
slug: {
name: "slug",
type: "string",
targetContentSourceTypes: [...Object.keys(sourceInstanceTypes).map(name => sourceInstanceTypes[name].id)]
},
/**
* The relative directory of the node.
*/
relativeDirectory: {
name: "relativeDirectory",
type: "string",
targetContentSourceTypes: [...Object.keys(sourceInstanceTypes).map(name => sourceInstanceTypes[name].id)]
},
/**
* The slug of the parent route based on the content source type.
*/
slugParentRoute: {
name: "slugParentRoute",
type: "string",
targetContentSourceTypes: [...Object.keys(sourceInstanceTypes).map(name => sourceInstanceTypes[name].id)]
}
};

module.exports = { nodeFields, sourceInstanceTypes };
Loading

0 comments on commit b8e9ff2

Please sign in to comment.