| 46 | }; |
| 47 | |
| 48 | const compile = function(contents, locals, filename, cb) { |
| 49 | // console.log "Compile", filename, basePath |
| 50 | let str; |
| 51 | const outFile = filename.replace(new RegExp(`.static.(${productSuffix}\\.)?pug$`), '.html'); |
| 52 | // console.log {outFile, filename, basePath} |
| 53 | let out = pug.compileClientWithDependenciesTracked(contents, { |
| 54 | filename: path.join(basePath, 'templates/static', filename), |
| 55 | basedir: basePath, |
| 56 | plugins: [productFallbackPlugin] |
| 57 | }); |
| 58 | |
| 59 | const outFn = pug.compile(contents, { |
| 60 | filename: path.join(basePath, 'templates/static', filename), |
| 61 | basedir: basePath, |
| 62 | plugins: [productFallbackPlugin] |
| 63 | }); |
| 64 | |
| 65 | const translate = function(key, chinaInfra) { |
| 66 | let type = 'text'; |
| 67 | |
| 68 | const html = /^\[html\]/.test(key); |
| 69 | if (html) { key = key.substring(6); } |
| 70 | if (html) { type = 'html'; } |
| 71 | |
| 72 | const content = /^\[content\]/.test(key); |
| 73 | if (content) { key = key.substring(9); } |
| 74 | if (content) { type = 'content'; } |
| 75 | |
| 76 | let t = chinaInfra ? zh.translation : en.translation; |
| 77 | //TODO: Replace with _.property when we get modern lodash |
| 78 | const translationPath = key.split(/[.]/); |
| 79 | while (translationPath.length > 0) { |
| 80 | var k = translationPath.shift(); |
| 81 | t = t[k]; |
| 82 | if (t == null) { return key; } |
| 83 | } |
| 84 | |
| 85 | return out = { |
| 86 | text: t, |
| 87 | type |
| 88 | }; |
| 89 | }; |
| 90 | |
| 91 | const i18n = function(k,v) { |
| 92 | if (Array.from(k).includes('i18n')) { return k.i18n.en[a]; } |
| 93 | return k[v]; |
| 94 | }; |
| 95 | |
| 96 | try { |
| 97 | locals = _.merge({_, i18n}, locals, require('./static-mock')); |
| 98 | // NOTE: do NOT add more build env-driven feature flags here if at all possible. |
| 99 | // NOTE: instead, use showingStaticPagesWhileLoading (in static-mock) to delay/hide UI until features flags loaded |
| 100 | locals.me.useSocialSignOn = () => !(locals.chinaInfra != null ? locals.chinaInfra : false); |
| 101 | locals.me.useGoogleAnalytics = () => !(locals.chinaInfra != null ? locals.chinaInfra : false); |
| 102 | locals.me.useStripe = () => !(locals.chinaInfra != null ? locals.chinaInfra : false); |
| 103 | locals.me.useQiyukf = () => locals.chinaInfra != null ? locals.chinaInfra : false; // Netease Qiyu Live Chat Plugin |
| 104 | locals.me.useDataDog = () => !(locals.chinaInfra != null ? locals.chinaInfra : false); |
| 105 | locals.me.showChinaVideo = () => locals.chinaInfra != null ? locals.chinaInfra : false; |