@@ -4,6 +4,7 @@ const mkdirp = require(`mkdirp`)
4
4
const crypto = require ( `crypto` )
5
5
const Debug = require ( `debug` )
6
6
const { createFilePath } = require ( `gatsby-source-filesystem` )
7
+ const { urlResolve } = require ( `gatsby-core-utils` )
7
8
8
9
const debug = Debug ( `gatsby-theme-blog-core` )
9
10
const withDefaults = require ( `./utils/default-options` )
@@ -97,7 +98,7 @@ exports.onCreateNode = async (
97
98
themeOptions
98
99
) => {
99
100
const { createNode, createParentChildLink } = actions
100
- const { contentPath } = withDefaults ( themeOptions )
101
+ const { contentPath, basePath } = withDefaults ( themeOptions )
101
102
102
103
// Make sure it's an MDX node
103
104
if ( node . internal . type !== `Mdx` ) {
@@ -109,12 +110,25 @@ exports.onCreateNode = async (
109
110
const source = fileNode . sourceInstanceName
110
111
111
112
if ( node . internal . type === `Mdx` && source === contentPath ) {
112
- const slug = createFilePath ( {
113
- node : fileNode ,
114
- getNode,
115
- basePath : contentPath ,
116
- } )
117
-
113
+ let slug
114
+ if ( node . frontmatter . slug ) {
115
+ if ( path . isAbsolute ( node . frontmatter . slug ) ) {
116
+ // absolute paths take precedence
117
+ slug = node . frontmatter . slug
118
+ } else {
119
+ // otherwise a relative slug gets turned into a sub path
120
+ slug = urlResolve ( basePath , node . frontmatter . slug )
121
+ }
122
+ } else {
123
+ // otherwise use the filepath function from gatsby-source-filesystem
124
+ const filePath = createFilePath ( {
125
+ node : fileNode ,
126
+ getNode,
127
+ basePath : contentPath ,
128
+ } )
129
+
130
+ slug = urlResolve ( basePath , filePath )
131
+ }
118
132
const fieldData = {
119
133
title : node . frontmatter . title ,
120
134
tags : node . frontmatter . tags || [ ] ,
0 commit comments