@@ -32,6 +32,12 @@ const mapBlogFilePath = path => {
32
32
return path ;
33
33
} ;
34
34
35
+ // Static files are located in /public/static/img/somefile.png
36
+ // within markdown files they are referenced as /static/img/somefile.png
37
+ const mapStaticFilePath = path => {
38
+ return path . replace ( "./public" , "" ) ;
39
+ }
40
+
35
41
// Creates a lookup table of all available pages within the website
36
42
// It will also automatically map urls for dedicated directorys (such as _blogposts)
37
43
// to the correct url
@@ -40,9 +46,18 @@ const createPageIndex = files => {
40
46
return files . reduce ( ( acc , path ) => {
41
47
// We need to consider all the different file formats used in pages
42
48
// Calculate the website url by stripping .re, .bs.js, .md(x), etc.
43
- let url = mapBlogFilePath ( path )
44
- . replace ( / ^ \. \/ / , "/" )
45
- . replace ( / \. r e | \. b s \. j s | \. j s | \. m d ( x ) ? $ / , "" ) ;
49
+ let url ;
50
+ if ( path . startsWith ( "./_blogposts" ) ) {
51
+ url = mapBlogFilePath ( path )
52
+ }
53
+ else if ( path . startsWith ( "./public/static" ) ) {
54
+ url = mapStaticFilePath ( path ) ;
55
+ }
56
+ else {
57
+ url = path ;
58
+ }
59
+
60
+ url = url . replace ( / ^ \. \/ / , "/" ) . replace ( / \. r e | \. b s \. j s | \. j s | \. m d ( x ) ? $ / , "" ) ;
46
61
47
62
// For index we need to special case, since it can be referred as '/' as well
48
63
if ( path . match ( / \. \/ p a g e s \/ i n d e x ( \. r e | \. b s \. j s | \. j s | \. m d ( x ) ) ? $ / ) ) {
@@ -133,9 +148,16 @@ const testFile = (pageMap, test) => {
133
148
let resolved ;
134
149
if ( ! path . isAbsolute ( url ) ) {
135
150
resolved = path . join ( "/" , path . dirname ( filepath ) , parsed . pathname ) ;
136
- } else {
137
- // e.g. /api/javascript/latest/js needs to be prefixed to actual pages dir
138
- resolved = path . join ( "/pages" , parsed . pathname ) ;
151
+ }
152
+ else {
153
+ if ( parsed . pathname . startsWith ( "/static" ) ) {
154
+ console . log ( "Static" ) ;
155
+ resolved = path . join ( parsed . pathname ) ;
156
+ }
157
+ else {
158
+ // e.g. /api/javascript/latest/js needs to be prefixed to actual pages dir
159
+ resolved = path . join ( "/pages" , parsed . pathname ) ;
160
+ }
139
161
}
140
162
141
163
// If there's no page stated the relative link
@@ -191,7 +213,11 @@ const main = () => {
191
213
192
214
// We need to capture all files independently from the test file glob
193
215
const pageMapFiles = glob . sync ( "./{pages,_blogposts}/**/*.{js,mdx}" , { cwd } ) ;
194
- const pageMap = createPageIndex ( pageMapFiles ) ;
216
+ const staticFiles = glob . sync ( "./public/static/**/*.{svg,png,woff2}" , { cwd } ) ;
217
+
218
+ const allFiles = pageMapFiles . concat ( staticFiles ) ;
219
+
220
+ const pageMap = createPageIndex ( allFiles ) ;
195
221
196
222
//console.log(pageMap);
197
223
//return;
0 commit comments