@@ -4,6 +4,14 @@ const Markdoc = require('@markdoc/markdoc');
4
4
5
5
const DEFAULT_SCHEMA_PATH = './markdoc' ;
6
6
7
+ // https://stackoverflow.com/questions/53799385/how-can-i-convert-a-windows-path-to-posix-path-using-node-path
8
+ function normalizeAbsolutePath ( s ) {
9
+ return s
10
+ . replace ( / ^ [ a - z A - Z ] : / , '' ) // replace C: for Windows
11
+ . split ( path . sep )
12
+ . join ( path . posix . sep ) ;
13
+ }
14
+
7
15
async function gatherPartials ( ast , schemaDir ) {
8
16
let partials = { } ;
9
17
@@ -16,7 +24,7 @@ async function gatherPartials(ast, schemaDir) {
16
24
typeof file === 'string' &&
17
25
! partials [ file ]
18
26
) {
19
- const filepath = path . join ( schemaDir , file ) ;
27
+ const filepath = path . posix . join ( schemaDir , file ) ;
20
28
// parsing is not done here because then we have to serialize and reload from JSON at runtime
21
29
const content = await fs . promises . readFile ( filepath , { encoding : 'utf8' } ) ;
22
30
@@ -46,7 +54,7 @@ async function load(source) {
46
54
const { mode = 'static' , schemaPath = DEFAULT_SCHEMA_PATH } =
47
55
this . getOptions ( ) || { } ;
48
56
49
- const schemaDir = path . resolve ( schemaPath || DEFAULT_SCHEMA_PATH ) ;
57
+ const schemaDir = path . posix . resolve ( schemaPath || DEFAULT_SCHEMA_PATH ) ;
50
58
51
59
// Grabs the path of the file relative to the `/pages` directory
52
60
// to pass into the app props later.
@@ -113,7 +121,7 @@ async function load(source) {
113
121
const partials = await gatherPartials . call (
114
122
this ,
115
123
ast ,
116
- path . resolve ( schemaDir , 'partials' )
124
+ path . posix . resolve ( schemaDir , 'partials' )
117
125
) ;
118
126
119
127
// IDEA: consider making this an option per-page
@@ -126,7 +134,9 @@ async function load(source) {
126
134
127
135
async function readDir ( variable ) {
128
136
try {
129
- const module = await resolve ( schemaDir , variable ) ;
137
+ const module = normalizeAbsolutePath (
138
+ await resolve ( schemaDir , variable )
139
+ ) ;
130
140
return `import * as ${ variable } from '${ module } '` ;
131
141
} catch ( error ) {
132
142
return `const ${ variable } = {};` ;
@@ -161,7 +171,9 @@ import yaml from 'js-yaml';
161
171
// renderers is imported separately so Markdoc isn't sent to the client
162
172
import Markdoc, {renderers} from '@markdoc/markdoc'
163
173
164
- import {getSchema} from '${ await resolve ( __dirname , './runtime' ) } ';
174
+ import {getSchema} from '${ normalizeAbsolutePath (
175
+ await resolve ( __dirname , './runtime' )
176
+ ) } ';
165
177
/**
166
178
* Schema is imported like this so end-user's code is compiled using build-in babel/webpack configs.
167
179
* This enables typescript/ESnext support
0 commit comments