@@ -45,7 +45,9 @@ var pattern_assembler = function () {
45
45
return patternlab . patterns [ i ] ;
46
46
}
47
47
}
48
- console . error ( 'Could not find pattern with partial ' + partialName ) ;
48
+ if ( patternlab . config . debug ) {
49
+ console . error ( 'Could not find pattern with partial ' + partialName ) ;
50
+ }
49
51
return undefined ;
50
52
}
51
53
@@ -92,7 +94,7 @@ var pattern_assembler = function () {
92
94
function addPattern ( pattern , patternlab ) {
93
95
94
96
//add the link to the global object
95
- patternlab . data . link [ pattern . patternPartial ] = '/patterns/' + pattern . patternLink ;
97
+ patternlab . data . link [ pattern . patternPartial ] = '/patterns/' + pattern . patternLink . replace ( '.html' , patternlab . config . outputFileSuffixes . rendered + '.html' ) ;
96
98
97
99
//only push to array if the array doesn't contain this pattern
98
100
var isNew = true ;
@@ -412,27 +414,42 @@ var pattern_assembler = function () {
412
414
function parseDataLinksHelper ( patternlab , obj , key ) {
413
415
var linkRE , dataObjAsString , linkMatches ;
414
416
417
+ //check for link.patternPartial
415
418
linkRE = / l i n k \. [ A - z 0 - 9 - _ ] + / g;
419
+
420
+ //stringify the passed in object
416
421
dataObjAsString = JSON5 . stringify ( obj ) ;
422
+ if ( ! dataObjAsString ) { return obj ; }
423
+
424
+ //find matches
417
425
linkMatches = dataObjAsString . match ( linkRE ) ;
418
426
419
427
if ( linkMatches ) {
420
428
for ( var i = 0 ; i < linkMatches . length ; i ++ ) {
421
429
var dataLink = linkMatches [ i ] ;
422
430
if ( dataLink && dataLink . split ( '.' ) . length >= 2 ) {
431
+
432
+ //get the partial the link refers to
423
433
var linkPatternPartial = dataLink . split ( '.' ) [ 1 ] ;
424
434
var pattern = getPartial ( linkPatternPartial , patternlab ) ;
425
435
if ( pattern !== undefined ) {
436
+
437
+ //get the full built link and replace it
426
438
var fullLink = patternlab . data . link [ linkPatternPartial ] ;
427
439
if ( fullLink ) {
428
440
fullLink = path . normalize ( fullLink ) . replace ( / \\ / g, '/' ) ;
429
441
if ( patternlab . config . debug ) {
430
442
console . log ( 'expanded data link from ' + dataLink + ' to ' + fullLink + ' inside ' + key ) ;
431
443
}
444
+
445
+ //also make sure our global replace didn't mess up a protocol
446
+ fullLink = fullLink . replace ( / : \/ / g, '://' ) ;
432
447
dataObjAsString = dataObjAsString . replace ( dataLink , fullLink ) ;
433
448
}
434
449
} else {
435
- console . log ( 'pattern not found for' , dataLink , 'inside' , key ) ;
450
+ if ( patternlab . config . debug ) {
451
+ console . log ( 'pattern not found for' , dataLink , 'inside' , key ) ;
452
+ }
436
453
}
437
454
}
438
455
}
0 commit comments