1
1
const _ = require ( 'lodash' ) ;
2
2
const chalk = require ( 'chalk' ) ;
3
+ const crypto = require ( 'crypto' ) ;
3
4
const fm = require ( 'json-front-matter' ) ;
4
5
const fs = require ( 'fs' ) ;
5
6
const glob = require ( 'glob' ) ;
@@ -33,18 +34,27 @@ module.exports = globPattern => new Promise((resolve, reject) => {
33
34
reject ( err ) ;
34
35
}
35
36
37
+ const npmPackage = JSON . parse ( fs . readFileSync ( 'package.json' , 'utf8' ) ) ;
38
+
36
39
console . log ( '- Found' , components . length , 'components' ) ;
37
40
38
41
const componentsForNav = { } ;
39
42
components . forEach ( ( component ) => {
40
43
const componentTokens = component . replace ( 'src/components/' , '' ) . split ( '/' ) ;
41
44
const category = componentTokens [ 0 ] ;
42
45
43
- // Check the front matter for screenshot overrides
44
46
const componentHtml = fs . readFileSync ( component , 'utf8' ) ;
45
47
const fmParsed = fm . parse ( componentHtml ) ;
46
48
const frontMatter = fmParsed . attributes || { } ;
47
49
const dir = component . replace ( 'src/' , '' ) . replace ( '.html' , '' ) ;
50
+
51
+ // Compute component signature based on the Tachyons version and the contents of the
52
+ // component itself. This can be used to bust the browser cache of screenshots.
53
+ const md5sum = crypto . createHash ( 'md5' ) ;
54
+ md5sum . update ( npmPackage . version ) ;
55
+ md5sum . update ( componentHtml ) ;
56
+ const signature = md5sum . digest ( 'hex' ) ;
57
+
48
58
componentsForNav [ category ] = componentsForNav [ category ] || [ ] ;
49
59
componentsForNav [ category ] . push ( {
50
60
name : frontMatter . name || getName ( component ) ,
@@ -54,8 +64,9 @@ module.exports = globPattern => new Promise((resolve, reject) => {
54
64
href : `/${ dir } /index.html` ,
55
65
screenshot : {
56
66
path : `${ dir } /${ screenshotBasename } .png` ,
57
- href : `/${ dir } /${ screenshotBasename } .png` ,
67
+ href : `/${ dir } /${ screenshotBasename } .png?version= ${ signature } ` ,
58
68
} ,
69
+ signature,
59
70
frontMatter,
60
71
} ) ;
61
72
} ) ;
0 commit comments