Skip to content

Commit bc172cd

Browse files
committed
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.
1 parent dbd77a1 commit bc172cd

File tree

4 files changed

+13
-9
lines changed

4 files changed

+13
-9
lines changed

Diff for: themes/gatsby-theme-minimal-blog-core/README.md

100644100755
+1
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ npm install @lekoarts/gatsby-theme-minimal-blog-core
4646
| `blogPath` | `/blog` | url for the blog post overview page |
4747
| `tagsPath` | `/tags` | url for the tags overview page and prefix for tags (e.g. `/tags/my-tag`) |
4848
| `postsPath` | `content/posts` | Location of posts |
49+
| `postsPrefix` | `/` | Prefix for all individual blog posts |
4950
| `pagesPath` | `content/pages` | Location of additional pages (optional) |
5051
| `mdx` | `true` | Configure `gatsby-plugin-mdx` (if your website already is using the plugin pass `false` to turn this off) |
5152
| `formatString` | `DD.MM.YYYY` | Configure the date format for Date fields |

Diff for: themes/gatsby-theme-minimal-blog-core/gatsby-node.js

100644100755
+9-9
Original file line numberDiff line numberDiff line change
@@ -62,20 +62,20 @@ exports.createSchemaCustomization = ({ actions, schema }, themeOptions) => {
6262
description: String
6363
canonicalUrl: String
6464
}
65-
65+
6666
type PostTag {
6767
name: String
6868
slug: String
6969
}
70-
70+
7171
interface Page @nodeInterface {
7272
id: ID!
7373
slug: String!
7474
title: String!
7575
excerpt(pruneLength: Int = 160): String!
7676
body: String!
7777
}
78-
78+
7979
type MdxPost implements Node & Post {
8080
slug: String! @slugify
8181
title: String!
@@ -89,14 +89,14 @@ exports.createSchemaCustomization = ({ actions, schema }, themeOptions) => {
8989
description: String
9090
canonicalUrl: String
9191
}
92-
92+
9393
type MdxPage implements Node & Page {
9494
slug: String!
9595
title: String!
9696
excerpt(pruneLength: Int = 140): String! @mdxpassthrough(fieldName: "excerpt")
9797
body: String! @mdxpassthrough(fieldName: "body")
9898
}
99-
99+
100100
type MinimalBlogConfig implements Node {
101101
basePath: String
102102
blogPath: String
@@ -108,12 +108,12 @@ exports.createSchemaCustomization = ({ actions, schema }, themeOptions) => {
108108
showLineNumbers: Boolean
109109
showCopyButton: Boolean
110110
}
111-
111+
112112
type ExternalLink {
113113
name: String!
114114
url: String!
115115
}
116-
116+
117117
type NavigationEntry {
118118
title: String!
119119
slug: String!
@@ -257,7 +257,7 @@ const tagsTemplate = require.resolve(`./src/templates/tags-query.tsx`)
257257
exports.createPages = async ({ actions, graphql, reporter }, themeOptions) => {
258258
const { createPage } = actions
259259

260-
const { basePath, blogPath, tagsPath, formatString } = withDefaults(themeOptions)
260+
const { basePath, blogPath, tagsPath, formatString, postsPrefix } = withDefaults(themeOptions)
261261

262262
createPage({
263263
path: basePath,
@@ -323,7 +323,7 @@ exports.createPages = async ({ actions, graphql, reporter }, themeOptions) => {
323323
if (pages.length > 0) {
324324
pages.forEach((page) => {
325325
createPage({
326-
path: `/${basePath}/${page.slug}`.replace(/\/\/+/g, `/`),
326+
path: `/${basePath}${postsPrefix}${page.slug}`.replace(/\/\/+/g, `/`),
327327
component: pageTemplate,
328328
context: {
329329
slug: page.slug,

Diff for: themes/gatsby-theme-minimal-blog-core/utils/default-options.js

100644100755
+2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ module.exports = (themeOptions) => {
22
const basePath = themeOptions.basePath || `/`
33
const blogPath = themeOptions.blogPath || `/blog`
44
const postsPath = themeOptions.postsPath || `content/posts`
5+
const postsPrefix = themeOptions.postsPrefix || `/`
56
const pagesPath = themeOptions.pagesPath || `content/pages`
67
const tagsPath = themeOptions.tagsPath || `/tags`
78
const externalLinks = themeOptions.externalLinks || []
@@ -14,6 +15,7 @@ module.exports = (themeOptions) => {
1415
basePath,
1516
blogPath,
1617
postsPath,
18+
postsPrefix,
1719
pagesPath,
1820
tagsPath,
1921
externalLinks,

Diff for: themes/gatsby-theme-minimal-blog/README.md

100644100755
+1
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ gatsby new minimal-blog LekoArts/gatsby-starter-minimal-blog
7070
| `blogPath` | `/blog` | url for the blog post overview page |
7171
| `tagsPath` | `/tags` | url for the tags overview page and prefix for tags (e.g. `/tags/my-tag`) |
7272
| `postsPath` | `content/posts` | Location of posts |
73+
| `postsPrefix` | `/` | Prefix for all individual blog posts |
7374
| `pagesPath` | `content/pages` | Location of additional pages (optional) |
7475
| `mdx` | `true` | Configure `gatsby-plugin-mdx` (if your website already is using the plugin pass `false` to turn this off) |
7576
| `formatString` | `DD.MM.YYYY` | Configure the date format for Date fields |

0 commit comments

Comments
 (0)