Skip to content
This repository was archived by the owner on Nov 21, 2018. It is now read-only.

Commit 759d646

Browse files
committed
Merge pull request #243 from iojs/improved-language-support
i18n/build improvements, part 1
2 parents 35f0466 + 0a86311 commit 759d646

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

87 files changed

+1417
-1297
lines changed

gulp/tasks/templates.js

Lines changed: 57 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,15 @@ var gulp = require('gulp'); // because this is a gulp task. duh.
66
var HTMLtemplate = require('html-template'); // substack's html template implementation
77
var md = require('markdown-it')({ html: true }); // to convert markdown to html
88
var source = require('vinyl-source-stream'); // used to convert substack's readStream to vinylStream
9-
var replaceStream = require('replacestream'); // used to add an element to the html: making sure each page has it's own class if needed in css
109
var moment = require('moment-timezone');
1110
var exec = require('child_process').exec
1211
var utils = require('../util/template-utils.js');
1312
var path = require('path');
13+
var crypto = require("crypto");
14+
var gulpif = require('gulp-if');
15+
var handlebars = require('gulp-compile-handlebars');
16+
var buffer = require('vinyl-buffer');
17+
var rename = require('gulp-rename');
1418

1519
gulp.task('templates', function() {
1620
var separator = '<SEPARATOR>';
@@ -40,30 +44,60 @@ gulp.task('templates', function() {
4044
var html = md.render(markdown); // convert md string to html string
4145
var thisFileJSON = _.cloneDeep(templateJSON); // clone in the template JSON object
4246
var pageTitle = thisFileJSON['browser-title'];
43-
thisFileJSON = _.omit(thisFileJSON, 'browser-title');
44-
var finalJSON = {};
45-
_.forEach(thisFileJSON, function(value, key) {
46-
finalJSON['[i18n-' + key + ']'] = value;
47-
})
48-
finalJSON['[i18n-content]'] = html; // Attach md2html string to the interpolation object
49-
var htmlObj = HTMLtemplate(); // finally using that holder for the template stream
50-
i18nObj = htmlObj.template('i18n', {
51-
include: false
52-
}); // same
5347
var filepath = __dirname.split('gulp/tasks')[0] + 'source/templates/main.html'; // get the main template file location. There can be multiple, this is just a proof of concept
5448
var destinationDirectory = path.dirname('public/' + file.filepathArray.join('/'));
55-
var fileStream = fs.createReadStream(filepath) // pulling this code from substack's example on html-template
56-
.pipe(replaceStream('<title i18n-title>io.js - JavaScript I/O</title>', '<title i18n-title>' + pageTitle + '</title>'))
57-
.pipe(replaceStream('markdown-page=""', 'markdown-page="' + file.filename + '"')) // add css-triggerable attribute to body
58-
.pipe(replaceStream('[page-stylesheet]', file.filename)) // require in specific stylesheet
59-
.pipe(replaceStream('Build Time:', 'Build Time: ' + buildTime))
60-
.pipe(replaceStream('Commit Sha:', 'Commit Sha: ' + commitSha))
61-
.pipe(replaceStream('Commit Msg:', 'Commit Msg: ' + commitMsg))
62-
.pipe(htmlObj)
63-
.pipe(source(file.filename + '.html')) // converting the readStream to a vinyl stream so gulp can write it back to the disk
64-
.pipe(gulp.dest(destinationDirectory)); // dump it in the appropriate language subfolder
65-
i18nObj.write(finalJSON); // write the interpolation JSON to the template
66-
i18nObj.end(); // saving? this is taken from substack too.
49+
var changedFileCache = [];
50+
51+
var isChangedFile = function(vinylFile) {
52+
if (vinylFile.isNull()) {
53+
return;
54+
}
55+
if (changedFileCache[vinylFile.path] != null) {
56+
return changedFileCache[vinylFile.path];
57+
}
58+
59+
var currentContent = fs.readFileSync(path.join(destinationDirectory, file.filename + '.html'), {encoding: 'utf8'});
60+
var currentHash = currentContent.match(/Hashsum:\s(\b([a-f0-9]{40})\b)/);
61+
if (currentHash && currentHash.length > 2) {
62+
currentHash = currentHash[1]
63+
} else {
64+
currentHash = null
65+
}
66+
67+
var contents = String(vinylFile.contents);
68+
var newHash = crypto
69+
.createHash("sha1")
70+
.update(vinylFile.contents, "binary")
71+
.digest("hex");
72+
73+
var isChanged = (currentHash !== newHash);
74+
75+
if (isChanged) {
76+
contents = contents.replace(/Hashsum:(?:\s+\b([a-f0-9]{40})\b)?/, `Hashsum: ${newHash}`)
77+
contents = contents.replace('Build Time:', `Build Time: ${buildTime}`)
78+
contents = contents.replace('Commit Sha:', `Commit Sha: ${commitSha}`)
79+
contents = contents.replace('Commit Msg:', `Commit Msg: ${commitMsg}`)
80+
vinylFile.contents = new Buffer(contents);
81+
}
82+
changedFileCache[vinylFile.path] = isChanged;
83+
return isChanged;
84+
};
85+
86+
var templateContent = {
87+
i18n: thisFileJSON,
88+
content: html,
89+
lang: lang,
90+
build: {
91+
markdownPage: file.filename,
92+
pageStylesheet: file.filename
93+
}
94+
};
95+
96+
var fileStream = gulp.src(filepath) // pulling this code from substack's example on html-template
97+
.pipe(rename(file.filename + '.html')) // converting the readStream to a vinyl stream so gulp can write it back to the disk
98+
.pipe(buffer())
99+
.pipe(handlebars(templateContent))
100+
.pipe(gulpif(isChangedFile, gulp.dest(destinationDirectory))); // dump it in the appropriate language subfolder
67101
});
68102
});
69103
});

package.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,21 +47,24 @@
4747
"glob": "^4.3.5",
4848
"gulp": "^3.8.10",
4949
"gulp-changed": "^1.1.0",
50+
"gulp-compile-handlebars": "^0.4.4",
5051
"gulp-connect": "^2.2.0",
5152
"gulp-filesize": "0.0.6",
5253
"gulp-htmlmin": "^1.0.0",
54+
"gulp-if": "^1.2.5",
5355
"gulp-imagemin": "^2.1.0",
5456
"gulp-less": "^2.0.1",
5557
"gulp-markdown": "^1.0.0",
5658
"gulp-postcss": "^4.0.2",
59+
"gulp-rename": "^1.2.0",
5760
"gulp-stylus": "^2.0.0",
5861
"html-template": "^1.2.1",
5962
"lodash": "^2.4.1",
6063
"markdown-it": "^3.0.4",
6164
"moment-timezone": "^0.3.0",
62-
"replacestream": "^2.0.0",
6365
"require-dir": "^0.1.0",
6466
"run-sequence": "^1.0.2",
67+
"vinyl-buffer": "^1.0.0",
6568
"vinyl-source-stream": "^1.0.0"
6669
}
6770
}

public/cn/es6.html

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
<!DOCTYPE html>
2-
<html lang="en">
2+
<html lang="cn">
33

44
<head>
55
<meta charset="utf-8">
6-
<title i18n-title>io.js - JavaScript I/O</title>
6+
<title>io.js - JavaScript I/O</title>
77
<meta http-equiv="X-UA-Compatible" content="IE=edge">
88
<meta name="viewport" content="width=device-width,initial-scale=1">
99
<meta name="description" content="io.js is an npm compatible platform originally based on node.js">
@@ -24,15 +24,15 @@
2424

2525
<header>
2626
<div class="content">
27-
<a href="index.html" class="logo" i18n-logo-text>io.js</a>
27+
<a href="index.html" class="logo">io.js</a>
2828
<div class="spacer"></div>
29-
<a href="faq.html" i18n-faq-link>常见问题</a>
30-
<a href="es6.html" i18n-es6-link>ES6</a>
31-
<a href="https://iojs.org/api/" i18n-api-link>API 文档</a>
29+
<a href="faq.html">常见问题</a>
30+
<a href="es6.html">ES6</a>
31+
<a href="https://iojs.org/api/">API 文档</a>
3232
</div>
3333
</header>
3434

35-
<div class="content clearfix" i18n-content><h1>io.js 运行 ES6</h1>
35+
<div class="content clearfix"><h1>io.js 运行 ES6</h1>
3636
<p>io.js 是基于 <a href="https://code.google.com/p/v8/">V8</a> 引擎的较新版本构建的。通过持续跟进最新版的 V8 引擎,我们可以保证及时地为开发者带来最新的 <a href="http://www.ecma-international.org/publications/standards/Ecma-262.htm">JavaScript ECMA-262 规范</a> 中的语言特性,同时也能得到性能和稳定性的提升。</p>
3737
<p>io.js 1.3.0 集成了 V8 4.1.0.14 版本,其中包含的 ES6 特性远超 joyent/[email protected] 集成的 3.26.33 版本所包含的。</p>
3838
<h2>干掉 --harmony</h2>
@@ -121,11 +121,11 @@ <h2>如何查阅某一版本的 io.js 所集成的 V8 的版本?</h2>
121121

122122
<footer class="content">
123123
<nav>
124-
<a href="https://github.com/iojs/io.js/issues" i18n-issues-link>GitHub Issues</a><!--
125-
--><a href="https://github.com/iojs" i18n-org-link>GitHub Org</a><!--
126-
--><a href="https://webchat.freenode.net/?channels=io.js" i18n-irc-link>IRC Chat</a><!--
127-
--><a href="http://logs.libuv.org/io.js/latest" i18n-irc-logs-link>Logs</a><!--
128-
--><a href="https://github.com/iojs/io.js/blob/v1.x/GOVERNANCE.md#readme" i18n-gov-link>项目管理</a>
124+
<a href="https://github.com/iojs/io.js/issues">GitHub Issues</a><!--
125+
--><a href="https://github.com/iojs">GitHub Org</a><!--
126+
--><a href="https://webchat.freenode.net/?channels=io.js">IRC Chat</a><!--
127+
--><a href="http://logs.libuv.org/io.js/latest">Logs</a><!--
128+
--><a href="https://github.com/iojs/io.js/blob/v1.x/GOVERNANCE.md#readme">项目管理</a>
129129
</nav>
130130
</footer>
131131

@@ -136,10 +136,11 @@ <h2>如何查阅某一版本的 io.js 所集成的 V8 的版本?</h2>
136136
<!--
137137
=========== BUILD INFORMATION ===========
138138
139-
Build Time: 2015-02-20 14:45:25 UTC
139+
Build Time: 2015-02-26 12:44:12 UTC
140140
141-
Commit Sha: 626785252f037c99c2fdbf1d93e71019684a2cb4
142-
Commit Msg: update io.js version to 1.3.0 in all languages
141+
Commit Sha: 68970fd56e9b43ccbb6bfd2d7720ef484936f92f
142+
Commit Msg: Initial public template changes resulting from template modifications
143+
Hashsum: da1ab8449a06c7c7ba9bf54d17b00d72a5f1247d
143144
144145
=========== END BUILD INFORMATION ===========
145146
-->

public/cn/faq.html

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
<!DOCTYPE html>
2-
<html lang="en">
2+
<html lang="cn">
33

44
<head>
55
<meta charset="utf-8">
6-
<title i18n-title>io.js - JavaScript I/O</title>
6+
<title>io.js - JavaScript I/O</title>
77
<meta http-equiv="X-UA-Compatible" content="IE=edge">
88
<meta name="viewport" content="width=device-width,initial-scale=1">
99
<meta name="description" content="io.js is an npm compatible platform originally based on node.js">
@@ -24,15 +24,15 @@
2424

2525
<header>
2626
<div class="content">
27-
<a href="index.html" class="logo" i18n-logo-text>io.js</a>
27+
<a href="index.html" class="logo">io.js</a>
2828
<div class="spacer"></div>
29-
<a href="faq.html" i18n-faq-link>常见问题</a>
30-
<a href="es6.html" i18n-es6-link>ES6</a>
31-
<a href="https://iojs.org/api/" i18n-api-link>API 文档</a>
29+
<a href="faq.html">常见问题</a>
30+
<a href="es6.html">ES6</a>
31+
<a href="https://iojs.org/api/">API 文档</a>
3232
</div>
3333
</header>
3434

35-
<div class="content clearfix" i18n-content><h1>常见问题</h1>
35+
<div class="content clearfix"><h1>常见问题</h1>
3636
<h2>io.js 是什么?</h2>
3737
<p><a href="https://github.com/iojs/io.js">io.js</a> 是基于 <a href="http://code.google.com/p/v8/">Chrome's V8 运行环境</a> 的 JavaScript 平台。本项目基于 <a href="https://nodejs.org/">Joyent的 Node.js™</a> 项目并继续开发,兼容 <a href="https://www.npmjs.org/">npm</a> 生态系统。</p>
3838
<p>想知道为什么?io.js 能提供更短、可预测的发布周期。目前,它融合了最新的语言特性,API 和 V8 引擎的性能改进,并且会持续更新 libuv 和其他底层库。</p>
@@ -52,11 +52,11 @@ <h2>什么是开放的管理模式?</h2>
5252

5353
<footer class="content">
5454
<nav>
55-
<a href="https://github.com/iojs/io.js/issues" i18n-issues-link>GitHub Issues</a><!--
56-
--><a href="https://github.com/iojs" i18n-org-link>GitHub Org</a><!--
57-
--><a href="https://webchat.freenode.net/?channels=io.js" i18n-irc-link>IRC Chat</a><!--
58-
--><a href="http://logs.libuv.org/io.js/latest" i18n-irc-logs-link>Logs</a><!--
59-
--><a href="https://github.com/iojs/io.js/blob/v1.x/GOVERNANCE.md#readme" i18n-gov-link>项目管理</a>
55+
<a href="https://github.com/iojs/io.js/issues">GitHub Issues</a><!--
56+
--><a href="https://github.com/iojs">GitHub Org</a><!--
57+
--><a href="https://webchat.freenode.net/?channels=io.js">IRC Chat</a><!--
58+
--><a href="http://logs.libuv.org/io.js/latest">Logs</a><!--
59+
--><a href="https://github.com/iojs/io.js/blob/v1.x/GOVERNANCE.md#readme">项目管理</a>
6060
</nav>
6161
</footer>
6262

@@ -67,10 +67,11 @@ <h2>什么是开放的管理模式?</h2>
6767
<!--
6868
=========== BUILD INFORMATION ===========
6969
70-
Build Time: 2015-02-20 14:45:25 UTC
70+
Build Time: 2015-02-26 12:44:12 UTC
7171
72-
Commit Sha: 626785252f037c99c2fdbf1d93e71019684a2cb4
73-
Commit Msg: update io.js version to 1.3.0 in all languages
72+
Commit Sha: 68970fd56e9b43ccbb6bfd2d7720ef484936f92f
73+
Commit Msg: Initial public template changes resulting from template modifications
74+
Hashsum: 376cc54fd6a3da0d92459c8a8b767b317add2ec4
7475
7576
=========== END BUILD INFORMATION ===========
7677
-->

public/cn/index.html

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
<!DOCTYPE html>
2-
<html lang="en">
2+
<html lang="cn">
33

44
<head>
55
<meta charset="utf-8">
6-
<title i18n-title>io.js - JavaScript I/O</title>
6+
<title>io.js - JavaScript I/O</title>
77
<meta http-equiv="X-UA-Compatible" content="IE=edge">
88
<meta name="viewport" content="width=device-width,initial-scale=1">
99
<meta name="description" content="io.js is an npm compatible platform originally based on node.js">
@@ -24,15 +24,15 @@
2424

2525
<header>
2626
<div class="content">
27-
<a href="index.html" class="logo" i18n-logo-text>io.js</a>
27+
<a href="index.html" class="logo">io.js</a>
2828
<div class="spacer"></div>
29-
<a href="faq.html" i18n-faq-link>常见问题</a>
30-
<a href="es6.html" i18n-es6-link>ES6</a>
31-
<a href="https://iojs.org/api/" i18n-api-link>API 文档</a>
29+
<a href="faq.html">常见问题</a>
30+
<a href="es6.html">ES6</a>
31+
<a href="https://iojs.org/api/">API 文档</a>
3232
</div>
3333
</header>
3434

35-
<div class="content clearfix" i18n-content><h1>JavaScript I/O</h1>
35+
<div class="content clearfix"><h1>JavaScript I/O</h1>
3636
<p><a href="es6.html">ES6</a> 带入 Node 社区!</p>
3737
<p><a href="https://github.com/iojs/io.js">io.js</a> 是一个衍生自 <a href="https://nodejs.org/">node.js</a>™ ,并兼容 <a href="https://www.npmjs.org/">npm</a> 的开发平台。</p>
3838
<p><a href="https://iojs.org/dist/v1.3.0/"><img src="../images/1.0.0.png" alt="io.js"></a></p>
@@ -48,11 +48,11 @@
4848

4949
<footer class="content">
5050
<nav>
51-
<a href="https://github.com/iojs/io.js/issues" i18n-issues-link>GitHub Issues</a><!--
52-
--><a href="https://github.com/iojs" i18n-org-link>GitHub Org</a><!--
53-
--><a href="https://webchat.freenode.net/?channels=io.js" i18n-irc-link>IRC Chat</a><!--
54-
--><a href="http://logs.libuv.org/io.js/latest" i18n-irc-logs-link>Logs</a><!--
55-
--><a href="https://github.com/iojs/io.js/blob/v1.x/GOVERNANCE.md#readme" i18n-gov-link>项目管理</a>
51+
<a href="https://github.com/iojs/io.js/issues">GitHub Issues</a><!--
52+
--><a href="https://github.com/iojs">GitHub Org</a><!--
53+
--><a href="https://webchat.freenode.net/?channels=io.js">IRC Chat</a><!--
54+
--><a href="http://logs.libuv.org/io.js/latest">Logs</a><!--
55+
--><a href="https://github.com/iojs/io.js/blob/v1.x/GOVERNANCE.md#readme">项目管理</a>
5656
</nav>
5757
</footer>
5858

@@ -63,10 +63,11 @@
6363
<!--
6464
=========== BUILD INFORMATION ===========
6565
66-
Build Time: 2015-02-20 14:45:25 UTC
66+
Build Time: 2015-02-26 12:44:12 UTC
6767
68-
Commit Sha: 626785252f037c99c2fdbf1d93e71019684a2cb4
69-
Commit Msg: update io.js version to 1.3.0 in all languages
68+
Commit Sha: 68970fd56e9b43ccbb6bfd2d7720ef484936f92f
69+
Commit Msg: Initial public template changes resulting from template modifications
70+
Hashsum: 80471c1fe73fef2ea2cd69c220dbe4bc4e859b10
7071
7172
=========== END BUILD INFORMATION ===========
7273
-->

public/cs/es6.html

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
<!DOCTYPE html>
2-
<html lang="en">
2+
<html lang="cs">
33

44
<head>
55
<meta charset="utf-8">
6-
<title i18n-title>io.js - JavaScript I/O</title>
6+
<title>io.js - JavaScript I/O</title>
77
<meta http-equiv="X-UA-Compatible" content="IE=edge">
88
<meta name="viewport" content="width=device-width,initial-scale=1">
99
<meta name="description" content="io.js is an npm compatible platform originally based on node.js">
@@ -24,15 +24,15 @@
2424

2525
<header>
2626
<div class="content">
27-
<a href="index.html" class="logo" i18n-logo-text>io.js</a>
27+
<a href="index.html" class="logo">io.js</a>
2828
<div class="spacer"></div>
29-
<a href="faq.html" i18n-faq-link>FAQ</a>
30-
<a href="es6.html" i18n-es6-link>ES6</a>
31-
<a href="https://iojs.org/api/" i18n-api-link>API Docs</a>
29+
<a href="faq.html">FAQ</a>
30+
<a href="es6.html">ES6</a>
31+
<a href="https://iojs.org/api/">API Docs</a>
3232
</div>
3333
</header>
3434

35-
<div class="content clearfix" i18n-content><h1>ES6 on io.js</h1>
35+
<div class="content clearfix"><h1>ES6 on io.js</h1>
3636
<p>io.js is built against modern versions of <a href="https://code.google.com/p/v8/">V8</a>. By keeping up-to-date with the latest releases of this engine we ensure new features from the <a href="http://www.ecma-international.org/publications/standards/Ecma-262.htm">JavaScript ECMA-262 specification</a> are brought to io.js developers in a timely manner, as well as continued performance and stability improvements.</p>
3737
<p>Version 1.3.0 of io.js ships with V8 4.1.0.14, which includes ES6 features well beyond version 3.26.33 that will be shipped with joyent/[email protected].</p>
3838
<h2>No more --harmony flag</h2>
@@ -121,11 +121,11 @@ <h2>How do I find which version of V8 ships with a particular version of io.js?<
121121

122122
<footer class="content">
123123
<nav>
124-
<a href="https://github.com/iojs/io.js/issues" i18n-issues-link>GitHub Issues</a><!--
125-
--><a href="https://github.com/iojs" i18n-org-link>GitHub Org</a><!--
126-
--><a href="https://webchat.freenode.net/?channels=io.js" i18n-irc-link>IRC Chat</a><!--
127-
--><a href="http://logs.libuv.org/io.js/latest" i18n-irc-logs-link>Logs</a><!--
128-
--><a href="https://github.com/iojs/io.js/blob/v1.x/GOVERNANCE.md#readme" i18n-gov-link>Governance</a>
124+
<a href="https://github.com/iojs/io.js/issues">GitHub Issues</a><!--
125+
--><a href="https://github.com/iojs">GitHub Org</a><!--
126+
--><a href="https://webchat.freenode.net/?channels=io.js">IRC Chat</a><!--
127+
--><a href="http://logs.libuv.org/io.js/latest">Logs</a><!--
128+
--><a href="https://github.com/iojs/io.js/blob/v1.x/GOVERNANCE.md#readme">Governance</a>
129129
</nav>
130130
</footer>
131131

@@ -136,10 +136,11 @@ <h2>How do I find which version of V8 ships with a particular version of io.js?<
136136
<!--
137137
=========== BUILD INFORMATION ===========
138138
139-
Build Time: 2015-02-20 14:45:25 UTC
139+
Build Time: 2015-02-26 12:44:12 UTC
140140
141-
Commit Sha: 626785252f037c99c2fdbf1d93e71019684a2cb4
142-
Commit Msg: update io.js version to 1.3.0 in all languages
141+
Commit Sha: 68970fd56e9b43ccbb6bfd2d7720ef484936f92f
142+
Commit Msg: Initial public template changes resulting from template modifications
143+
Hashsum: 753832db36670dfda3882d74d6d0573fd44d7859
143144
144145
=========== END BUILD INFORMATION ===========
145146
-->

0 commit comments

Comments
 (0)