Skip to content
Permalink
Browse files
feat(gatsby-theme-minimal-blog): Add postsPrefix option
Closes #512

This adds an additional option "postsPrefix" to optionally prefix all blog posts. It defaults to '/' so current behavior stays the same.
  • Loading branch information
LekoArts committed Nov 1, 2020
1 parent dbd77a1 commit bc172cd1eea69d9e76dd459c11d174b3ea96ea3d
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 9 deletions.
@@ -46,6 +46,7 @@ npm install @lekoarts/gatsby-theme-minimal-blog-core
| `blogPath` | `/blog` | url for the blog post overview page |
| `tagsPath` | `/tags` | url for the tags overview page and prefix for tags (e.g. `/tags/my-tag`) |
| `postsPath` | `content/posts` | Location of posts |
| `postsPrefix` | `/` | Prefix for all individual blog posts |
| `pagesPath` | `content/pages` | Location of additional pages (optional) |
| `mdx` | `true` | Configure `gatsby-plugin-mdx` (if your website already is using the plugin pass `false` to turn this off) |
| `formatString` | `DD.MM.YYYY` | Configure the date format for Date fields |
@@ -62,20 +62,20 @@ exports.createSchemaCustomization = ({ actions, schema }, themeOptions) => {
description: String
canonicalUrl: String
}
type PostTag {
name: String
slug: String
}
interface Page @nodeInterface {
id: ID!
slug: String!
title: String!
excerpt(pruneLength: Int = 160): String!
body: String!
}
type MdxPost implements Node & Post {
slug: String! @slugify
title: String!
@@ -89,14 +89,14 @@ exports.createSchemaCustomization = ({ actions, schema }, themeOptions) => {
description: String
canonicalUrl: String
}
type MdxPage implements Node & Page {
slug: String!
title: String!
excerpt(pruneLength: Int = 140): String! @mdxpassthrough(fieldName: "excerpt")
body: String! @mdxpassthrough(fieldName: "body")
}
type MinimalBlogConfig implements Node {
basePath: String
blogPath: String
@@ -108,12 +108,12 @@ exports.createSchemaCustomization = ({ actions, schema }, themeOptions) => {
showLineNumbers: Boolean
showCopyButton: Boolean
}
type ExternalLink {
name: String!
url: String!
}
type NavigationEntry {
title: String!
slug: String!
@@ -257,7 +257,7 @@ const tagsTemplate = require.resolve(`./src/templates/tags-query.tsx`)
exports.createPages = async ({ actions, graphql, reporter }, themeOptions) => {
const { createPage } = actions

const { basePath, blogPath, tagsPath, formatString } = withDefaults(themeOptions)
const { basePath, blogPath, tagsPath, formatString, postsPrefix } = withDefaults(themeOptions)

createPage({
path: basePath,
@@ -323,7 +323,7 @@ exports.createPages = async ({ actions, graphql, reporter }, themeOptions) => {
if (pages.length > 0) {
pages.forEach((page) => {
createPage({
path: `/${basePath}/${page.slug}`.replace(/\/\/+/g, `/`),
path: `/${basePath}${postsPrefix}${page.slug}`.replace(/\/\/+/g, `/`),
component: pageTemplate,
context: {
slug: page.slug,
@@ -2,6 +2,7 @@ module.exports = (themeOptions) => {
const basePath = themeOptions.basePath || `/`
const blogPath = themeOptions.blogPath || `/blog`
const postsPath = themeOptions.postsPath || `content/posts`
const postsPrefix = themeOptions.postsPrefix || `/`
const pagesPath = themeOptions.pagesPath || `content/pages`
const tagsPath = themeOptions.tagsPath || `/tags`
const externalLinks = themeOptions.externalLinks || []
@@ -14,6 +15,7 @@ module.exports = (themeOptions) => {
basePath,
blogPath,
postsPath,
postsPrefix,
pagesPath,
tagsPath,
externalLinks,
@@ -70,6 +70,7 @@ gatsby new minimal-blog LekoArts/gatsby-starter-minimal-blog
| `blogPath` | `/blog` | url for the blog post overview page |
| `tagsPath` | `/tags` | url for the tags overview page and prefix for tags (e.g. `/tags/my-tag`) |
| `postsPath` | `content/posts` | Location of posts |
| `postsPrefix` | `/` | Prefix for all individual blog posts |
| `pagesPath` | `content/pages` | Location of additional pages (optional) |
| `mdx` | `true` | Configure `gatsby-plugin-mdx` (if your website already is using the plugin pass `false` to turn this off) |
| `formatString` | `DD.MM.YYYY` | Configure the date format for Date fields |

0 comments on commit bc172cd

Please sign in to comment.