You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@echarts.apache.org by sh...@apache.org on 2020/12/06 12:24:19 UTC
[incubator-echarts-www] branch master updated: use md5 hash for
assets version
This is an automated email from the ASF dual-hosted git repository.
shenyi pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-echarts-www.git
The following commit(s) were added to refs/heads/master by this push:
new 4c4e51f use md5 hash for assets version
4c4e51f is described below
commit 4c4e51f0a6f844b644f52d40cf1e6022ee17f6ae
Author: pissang <bm...@gmail.com>
AuthorDate: Sun Dec 6 20:24:04 2020 +0800
use md5 hash for assets version
---
_jade/components/download.jade | 2 +-
_jade/components/nav.jade | 2 +-
_jade/en/cheat-sheet.jade | 4 ++--
_jade/en/download.jade | 2 +-
_jade/en/index.jade | 2 +-
_jade/en/nav.jade | 2 +-
_jade/en/spreadsheet.jade | 2 +-
_jade/layouts/basic.jade | 4 ++--
_jade/layouts/doc-old.jade | 6 ++---
_jade/layouts/doc.jade | 6 ++---
_jade/layouts/next-doc.jade | 6 ++---
_jade/layouts/next-example-simple.jade | 4 ++--
_jade/layouts/next-example.jade | 4 ++--
_jade/zh/cheat-sheet.jade | 2 +-
_jade/zh/demo.jade | 4 ++--
_jade/zh/examples.jade | 6 ++---
bin/build.js | 43 ++++++++++++++++++++++++++++++++--
package.json | 1 +
18 files changed, 71 insertions(+), 31 deletions(-)
diff --git a/_jade/components/download.jade b/_jade/components/download.jade
index 083ad5d..abbb67d 100644
--- a/_jade/components/download.jade
+++ b/_jade/components/download.jade
@@ -168,7 +168,7 @@ block content
block extra_js
- script(src="#{cdnPayRoot}/#{ecWWWLang}/js/download.js?_v_=#{homeVersion}")
+ script(src="#{getAssetUrl(cdnPayRoot, ecWWWLang + '/js/download.js')}")
script(type='text/javascript').
document.getElementById('nav-download').className = 'active';
diff --git a/_jade/components/nav.jade b/_jade/components/nav.jade
index d055084..27aed5a 100644
--- a/_jade/components/nav.jade
+++ b/_jade/components/nav.jade
@@ -1,2 +1,2 @@
include ./nav-mixin
-+nav(host, cdnPayRoot, cdnPayVersionParam)
++nav(host, cdnPayRoot, cdnPayVersion)
diff --git a/_jade/en/cheat-sheet.jade b/_jade/en/cheat-sheet.jade
index 775c26e..c846ec8 100644
--- a/_jade/en/cheat-sheet.jade
+++ b/_jade/en/cheat-sheet.jade
@@ -60,5 +60,5 @@ block extra_js
script(type='text/javascript').
document.getElementById('nav-resources').className = 'active';
- script(src='#{cdnThirdParty.echartsMinJS_4_8_0}')
- script(src='#{cdnPayRoot}/#{ecWWWLang}/js/cheat-sheet-en.js?_v_=#{homeVersion}')
+ script(src="#{cdnThirdParty.echartsMinJS_4_8_0}")
+ script(src="#{getAssetUrl(cdnPayRoot, ecWWWLang + '/js/cheat-sheet-en.js')}")
diff --git a/_jade/en/download.jade b/_jade/en/download.jade
index 81399b2..9152489 100644
--- a/_jade/en/download.jade
+++ b/_jade/en/download.jade
@@ -73,7 +73,7 @@ block content
include ./footer
block extra_js
- script(src="#{cdnPayRoot}/#{ecWWWLang}/js/download.js?_v_=#{homeVersion}")
+ script(src="#{getAssetUrl(cdnPayRoot, ecWWWLang + '/js/download.js')}")
script(type='text/javascript').
document.getElementById('nav-download').className = 'active';
diff --git a/_jade/en/index.jade b/_jade/en/index.jade
index 9c4f14a..7f24ca9 100644
--- a/_jade/en/index.jade
+++ b/_jade/en/index.jade
@@ -169,5 +169,5 @@ block extra_js
elements_selector: ".lazy"
};
script(src='https://cdn.jsdelivr.net/npm/vanilla-lazyload@12.0.0/dist/lazyload.min.js')
- script(src='#{cdnPayRoot}/#{ecWWWLang}/js/index.js?_v_=#{homeVersion}')
+ script(src="#{getAssetUrl(cdnPayRoot, ecWWWLang + '/js/index.js')}")
<script async defer src="https://buttons.github.io/buttons.js"></script>
diff --git a/_jade/en/nav.jade b/_jade/en/nav.jade
index df09095..b00166f 100644
--- a/_jade/en/nav.jade
+++ b/_jade/en/nav.jade
@@ -1,3 +1,3 @@
nav(role="navigation", class="navbar navbar-default navbar-fixed-top")
include ./nav-mixin
- +nav(host, cdnPayRoot, cdnPayVersionParam)
+ +nav(host, cdnPayRoot, cdnPayVersion)
diff --git a/_jade/en/spreadsheet.jade b/_jade/en/spreadsheet.jade
index c284968..932aa1f 100644
--- a/_jade/en/spreadsheet.jade
+++ b/_jade/en/spreadsheet.jade
@@ -6,7 +6,7 @@ block variablesLang
block extra_head
title Spreadsheet Tool - Apache ECharts (incubating)
link(rel="stylesheet", type="text/css", href="#{cdnPayRoot}/#{ecWWWLang}/vendors/handsontable/0.26.1/dist/handsontable.full.min.css?_v_=#{cdnPayVersion}")
- link(rel="stylesheet", type="text/css", href="#{cdnPayRoot}/#{ecWWWLang}/css/spreadsheet.css?_v_=#{homeVersion}")
+ link(rel="stylesheet", type="text/css", href="#{getAssetUrl(cdnPayRoot, ecWWWLang + '/css/spreadsheet.css')}")
script(src="vendors/esl.js")
diff --git a/_jade/layouts/basic.jade b/_jade/layouts/basic.jade
index 2be0bcf..6a2bc0e 100644
--- a/_jade/layouts/basic.jade
+++ b/_jade/layouts/basic.jade
@@ -24,7 +24,7 @@ html(lang='#{htmlAttrLang}')
script(src='https://oss.maxcdn.com/respond/1.4.2/respond.min.js')
<![endif]-->
- link(rel='stylesheet', type='text/css', href='#{cdnPayRoot}/#{ecWWWLang}/css/main.css?_v_=#{homeVersion}')
+ link(rel='stylesheet', type='text/css', href="#{getAssetUrl(cdnPayRoot, ecWWWLang + '/css/main.css')}")
script.
window.EC_WWW_LANG = '#{ecWWWLang}';
@@ -71,7 +71,7 @@ html(lang='#{htmlAttrLang}')
block content
script(type='text/javascript', src='#{cdnThirdParty.bootstrapJS}')
- script(type='text/javascript', src='#{cdnPayRoot}/#{ecWWWLang}/js/common.js?_v_=#{homeVersion}')
+ script(type='text/javascript', src="#{getAssetUrl(cdnPayRoot, ecWWWLang + '/js/common.js')}")
block extra_js
diff --git a/_jade/layouts/doc-old.jade b/_jade/layouts/doc-old.jade
index 2b8dcd8..72725e2 100644
--- a/_jade/layouts/doc-old.jade
+++ b/_jade/layouts/doc-old.jade
@@ -2,7 +2,7 @@ extends basic
block extra_head
title ECharts Documentation
- link(rel="stylesheet", type="text/css", href="css/ecOption.css?_v_=#{homeVersion}")
+ link(rel="stylesheet", type="text/css", href="css/ecOption.css")
link(rel="stylesheet", type="text/css", href="vendors/prettify/prettify.css")
link(rel="stylesheet", type="text/css", href="vendors/perfect-scrollbar/0.6.8/css/perfect-scrollbar.min.css")
link(rel="stylesheet", type="text/css", href="vendors/jquery-autocomplete/jquery.auto-complete.css")
@@ -54,7 +54,7 @@ block extra_js
var vendorPath = '../vendors';
define('globalArgs', extend({
- version: '#{homeVersion}',
+ version: '',
basePath: './',
// Schema url is added by each doc page
schemaUrl: '',
@@ -81,7 +81,7 @@ block extra_js
hasher: vendorPath + '/hasher/1.2.0/hasher.min',
perfectScrollbar: vendorPath + '/perfect-scrollbar/0.6.8/js/perfect-scrollbar'
},
- urlArgs: '_v_=#{homeVersion}'
+ urlArgs: ''
});
require(['docTool/main'], function (main) {
diff --git a/_jade/layouts/doc.jade b/_jade/layouts/doc.jade
index 4668654..a040b98 100644
--- a/_jade/layouts/doc.jade
+++ b/_jade/layouts/doc.jade
@@ -8,7 +8,7 @@ block extra_head
overflow-x: hidden;
}
link(rel="stylesheet", href="#{cdnThirdParty.elementUICSS}")
- link(rel="stylesheet", href="#{cdnPayRoot}/#{ecWWWLang}/css/doc-bundle.css?_v_=#{homeVersion}")
+ link(rel="stylesheet", href="#{getAssetUrl(cdnPayRoot, ecWWWLang + '/css/doc-bundle.css')}")
block content
@@ -45,7 +45,7 @@ block extra_js
script(src="#{cdnThirdParty.codeMirrorJS}")
script(src="#{cdnThirdParty.codeMirrorJSModeJS}")
script(src="#{cdnThirdParty.beautifierJS}")
- script(src="#{cdnPayRoot}/#{ecWWWLang}/js/doc-bundle.js?_v_=#{homeVersion}")
+ script(src="#{getAssetUrl(cdnPayRoot, ecWWWLang + '/js/doc-bundle.js')}")
script(type="text/javascript").
window.EC_WWW_CDN_PAY_ROOT = '#{cdnPayRoot}';
@@ -53,6 +53,6 @@ block extra_js
script(type="text/javascript").
document.getElementById('nav-doc').className = 'active';
- window.globalArgsExtra.version = '#{homeVersion}';
+ window.globalArgsExtra.version = '#{docHash}';
echartsDoc.init('#ec-doc-main', window.globalArgsExtra);
diff --git a/_jade/layouts/next-doc.jade b/_jade/layouts/next-doc.jade
index 97d2a67..1c08e97 100644
--- a/_jade/layouts/next-doc.jade
+++ b/_jade/layouts/next-doc.jade
@@ -8,7 +8,7 @@ block extra_head
overflow-x: hidden;
}
link(rel="stylesheet", href="#{cdnThirdParty.elementUICSS}")
- link(rel="stylesheet", href="#{cdnPayRoot}/next/#{ecWWWLang}/css/doc-bundle.css?_v_=#{homeVersion}")
+ link(rel="stylesheet", href="#{getAssetUrl(cdnPayRoot, 'next/' + ecWWWLang + '/css/doc-bundle.css')}")
block content
@@ -29,7 +29,7 @@ block extra_js
script(src="#{cdnThirdParty.codeMirrorJS}")
script(src="#{cdnThirdParty.codeMirrorJSModeJS}")
script(src="#{cdnThirdParty.beautifierJS}")
- script(src="#{cdnPayRoot}/next/#{ecWWWLang}/js/doc-bundle.js?_v_=#{homeVersion}")
+ script(src="#{getAssetUrl(cdnPayRoot, 'next/' + ecWWWLang + '/js/doc-bundle.js')}")
script(type="text/javascript").
window.EC_WWW_CDN_PAY_ROOT = '#{cdnPayRoot}';
@@ -37,6 +37,6 @@ block extra_js
script(type="text/javascript").
document.getElementById('nav-ec5').className = 'active';
- window.globalArgsExtra.version = '#{homeVersion}';
+ window.globalArgsExtra.version = '#{nextDocHash}';
echartsDoc.init('#ec-doc-main', window.globalArgsExtra);
diff --git a/_jade/layouts/next-example-simple.jade b/_jade/layouts/next-example-simple.jade
index ca5981b..aa4252f 100644
--- a/_jade/layouts/next-example-simple.jade
+++ b/_jade/layouts/next-example-simple.jade
@@ -8,7 +8,7 @@ block extra_head
overflow-x: hidden;
}
link(rel="stylesheet", href="#{cdnThirdParty.elementUICSS}")
- link(rel="stylesheet", href="#{cdnPayRoot}/next/examples/css/example-bundle.css?_v_=#{homeVersion}")
+ link(rel="stylesheet", href="#{getAssetUrl(cdnPayRoot, 'next/examples/css/example-bundle.css')}")
block content
@@ -17,7 +17,7 @@ block content
block extra_js
script(src="#{cdnThirdParty.vueJS}")
script(src="#{cdnThirdParty.elementUIJS}")
- script(src="#{cdnPayRoot}/next/examples/js/example-bundle.js?_v_=#{homeVersion}")
+ script(src="#{getAssetUrl(cdnPayRoot, 'next/examples/js/example-bundle.js')}")
script(type="text/javascript").
window.EC_WWW_CDN_PAY_ROOT = '#{cdnPayRoot}';
diff --git a/_jade/layouts/next-example.jade b/_jade/layouts/next-example.jade
index a1d2b9c..7869763 100644
--- a/_jade/layouts/next-example.jade
+++ b/_jade/layouts/next-example.jade
@@ -8,7 +8,7 @@ block extra_head
overflow-x: hidden;
}
link(rel="stylesheet", href="#{cdnThirdParty.elementUICSS}")
- link(rel="stylesheet", href="#{cdnPayRoot}/next/examples/css/example-bundle.css?_v_=#{homeVersion}")
+ link(rel="stylesheet", href="#{getAssetUrl(cdnPayRoot, 'next/examples/css/example-bundle.css')}")
block content
@@ -26,7 +26,7 @@ block content
block extra_js
script(src="#{cdnThirdParty.vueJS}")
script(src="#{cdnThirdParty.elementUIJS}")
- script(src="#{cdnPayRoot}/next/examples/js/example-bundle.js?_v_=#{homeVersion}")
+ script(src="#{getAssetUrl(cdnPayRoot, 'next/examples/js/example-bundle.js')}")
script(type="text/javascript").
window.EC_WWW_CDN_PAY_ROOT = '#{cdnPayRoot}';
diff --git a/_jade/zh/cheat-sheet.jade b/_jade/zh/cheat-sheet.jade
index 94442b8..c89aff7 100644
--- a/_jade/zh/cheat-sheet.jade
+++ b/_jade/zh/cheat-sheet.jade
@@ -58,4 +58,4 @@ block extra_js
document.getElementById('nav-resources').className = 'active';
script(src='#{cdnThirdParty.echartsMinJS_4_8_0}')
- script(src='#{cdnPayRoot}/#{ecWWWLang}/js/cheat-sheet.js?_v_=#{homeVersion}')
\ No newline at end of file
+ script(type='text/javascript', src="#{getAssetUrl(cdnPayRoot, ecWWWLang + '/js/cheat-sheet.js')}")
\ No newline at end of file
diff --git a/_jade/zh/demo.jade b/_jade/zh/demo.jade
index cf1a5ce..44edaf8 100644
--- a/_jade/zh/demo.jade
+++ b/_jade/zh/demo.jade
@@ -31,8 +31,8 @@ block extra_js
var GALLERY_VIEW_PATH = GALLERY_PATH + 'view.html?c=';
var GALLERY_THUMB_PATH = GALLERY_PATH + 'data/thumb/';
- script(type='text/javascript', src='#{cdnPayRoot}/#{ecWWWLang}/js/config.js?_v_=#{homeVersion}')
- script(type='text/javascript', src='#{cdnPayRoot}/#{ecWWWLang}/js/examples-nav.js?_v_=#{homeVersion}')
+ script(type='text/javascript', src="#{getAssetUrl(cdnPayRoot, ecWWWLang + '/js/config.js')}")
+ script(type='text/javascript', src="#{getAssetUrl(cdnPayRoot, ecWWWLang + '/js/examples-nav.js')}")
script(type='text/javascript').
document.getElementById('nav-examples').className = 'active';
diff --git a/_jade/zh/examples.jade b/_jade/zh/examples.jade
index aec694d..44e6af8 100644
--- a/_jade/zh/examples.jade
+++ b/_jade/zh/examples.jade
@@ -30,9 +30,9 @@ block extra_js
var GALLERY_VIEW_PATH = GALLERY_PATH + 'view.html?c=';
var GALLERY_THUMB_PATH = GALLERY_PATH + 'data/thumb/';
- script(type='text/javascript', src='#{cdnPayRoot}/#{ecWWWLang}/js/config.js?_v_=#{homeVersion}')
- script(type='text/javascript', src='#{cdnPayRoot}/#{ecWWWLang}/js/chart-list.js?_v_=#{homeVersion}')
- script(type='text/javascript', src='#{cdnPayRoot}/#{ecWWWLang}/js/examples-nav.js?_v_=#{homeVersion}')
+ script(type='text/javascript', src="#{getAssetUrl(cdnPayRoot, ecWWWLang + '/js/config.js')}")
+ script(type='text/javascript', src="#{getAssetUrl(cdnPayRoot, ecWWWLang + '/js/chart-list.js')}")
+ script(type='text/javascript', src="#{getAssetUrl(cdnPayRoot, ecWWWLang + '/js/examples-nav.js')}")
script(type='text/javascript').
document.getElementById('nav-examples').className = 'active';
diff --git a/bin/build.js b/bin/build.js
index 32854e8..27b7191 100644
--- a/bin/build.js
+++ b/bin/build.js
@@ -13,6 +13,7 @@ const argv = require('yargs').argv;
const assert = require('assert');
const requirejs = require('requirejs');
const readline = require('readline');
+const md5 = require('md5');
const LANGUAGES = ['zh', 'en'];
const projectDir = path.resolve(__dirname, '..');
@@ -74,6 +75,18 @@ function initEnv() {
assert(path.isAbsolute(config.releaseDestDir));
+ config.getAssetUrl = function (cdnPayRoot, filePath) {
+ const fullFilePath = path.join(config.releaseDestDir, filePath);
+ let content;
+ try {
+ content = fs.readFileSync(fullFilePath, 'utf-8');
+ }
+ catch (e) {
+ throw new Error(`Unkown file ${fullFilePath}`);
+ }
+ const hash = md5(content);
+ return cdnPayRoot + '/' + filePath + '?_v_=' + hash.substr(-10);
+ };
// Update home version each build.
config.homeVersion = +new Date();
// Temp: give a fixed version until need to update.
@@ -145,6 +158,20 @@ async function buildSASS(config) {
console.log('buildSASS done.');
}
+async function getFolderHash(globPattern) {
+ const files = await globby(globPattern);
+ if (!files.length) {
+ throw new Error('No file exists for pattern ' + globPattern);
+ }
+ let concatedStr = '';
+ for (let file of files) {
+ const content = fs.readFileSync(file);
+ concatedStr += md5(content);
+ }
+ assert(concatedStr);
+ return md5(concatedStr).substr(-10);
+}
+
async function buildJade(config) {
const basePath = path.resolve(projectDir, '_jade');
const srcPaths = await globby([
@@ -153,11 +180,21 @@ async function buildJade(config) {
cwd: basePath
});
+ const hashes = {};
+ for (let lang of ['zh', 'en']) {
+ hashes[lang] = {
+ docHash: await getFolderHash(path.resolve(config.releaseDestDir, lang, 'documents/**/*.js')),
+ nextDocHash: await getFolderHash(path.resolve(config.releaseDestDir, 'next', lang, 'documents/**/*.js'))
+ };
+ }
+
for (let srcPath of srcPaths) {
let filePath = path.resolve(basePath, srcPath);
const lang = srcPath.indexOf('zh/') === 0 ? 'zh' : 'en';
- const cfg = Object.assign({}, config);
+ assert(hashes[lang]);
+
+ const cfg = Object.assign({}, config, hashes[lang]);
cfg.cdnPayRoot = config.cdnPayRootMap[lang];
cfg.cdnFreeRoot = config.cdnFreeRootMap[lang];
@@ -469,7 +506,6 @@ async function run() {
else {
if (config.filter === 'all') {
await buildSASS(config);
- await buildJade(config);
await buildJS(config);
await copyResource(config);
await updateSourceVersion(config);
@@ -477,6 +513,9 @@ async function run() {
await buildLegacyDoc(config);
await buildSpreadsheet(config);
+ // Build jade at last because it needs to read the resources.
+ await buildJade(config);
+
await makeCDNChecker(config);
}
else {
diff --git a/package.json b/package.json
index d151163..c28e492 100644
--- a/package.json
+++ b/package.json
@@ -23,6 +23,7 @@
"globby": "^10.0.1",
"jade": "^1.11.0",
"less": "^3.10.3",
+ "md5": "^2.3.0",
"node-sass": "^4.13.0",
"onchange": "^6.1.0",
"postcss": "^7.0.25",
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@echarts.apache.org
For additional commands, e-mail: commits-help@echarts.apache.org