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

i18n/build improvements, part 1 #243

Merged
merged 4 commits into from
Feb 26, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
80 changes: 57 additions & 23 deletions gulp/tasks/templates.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,15 @@ var gulp = require('gulp'); // because this is a gulp task. duh.
var HTMLtemplate = require('html-template'); // substack's html template implementation
var md = require('markdown-it')({ html: true }); // to convert markdown to html
var source = require('vinyl-source-stream'); // used to convert substack's readStream to vinylStream
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
var moment = require('moment-timezone');
var exec = require('child_process').exec
var utils = require('../util/template-utils.js');
var path = require('path');
var crypto = require("crypto");
var gulpif = require('gulp-if');
var handlebars = require('gulp-compile-handlebars');
var buffer = require('vinyl-buffer');
var rename = require('gulp-rename');

gulp.task('templates', function() {
var separator = '<SEPARATOR>';
Expand Down Expand Up @@ -40,30 +44,60 @@ gulp.task('templates', function() {
var html = md.render(markdown); // convert md string to html string
var thisFileJSON = _.cloneDeep(templateJSON); // clone in the template JSON object
var pageTitle = thisFileJSON['browser-title'];
thisFileJSON = _.omit(thisFileJSON, 'browser-title');
var finalJSON = {};
_.forEach(thisFileJSON, function(value, key) {
finalJSON['[i18n-' + key + ']'] = value;
})
finalJSON['[i18n-content]'] = html; // Attach md2html string to the interpolation object
var htmlObj = HTMLtemplate(); // finally using that holder for the template stream
i18nObj = htmlObj.template('i18n', {
include: false
}); // same
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
var destinationDirectory = path.dirname('public/' + file.filepathArray.join('/'));
var fileStream = fs.createReadStream(filepath) // pulling this code from substack's example on html-template
.pipe(replaceStream('<title i18n-title>io.js - JavaScript I/O</title>', '<title i18n-title>' + pageTitle + '</title>'))
.pipe(replaceStream('markdown-page=""', 'markdown-page="' + file.filename + '"')) // add css-triggerable attribute to body
.pipe(replaceStream('[page-stylesheet]', file.filename)) // require in specific stylesheet
.pipe(replaceStream('Build Time:', 'Build Time: ' + buildTime))
.pipe(replaceStream('Commit Sha:', 'Commit Sha: ' + commitSha))
.pipe(replaceStream('Commit Msg:', 'Commit Msg: ' + commitMsg))
.pipe(htmlObj)
.pipe(source(file.filename + '.html')) // converting the readStream to a vinyl stream so gulp can write it back to the disk
.pipe(gulp.dest(destinationDirectory)); // dump it in the appropriate language subfolder
i18nObj.write(finalJSON); // write the interpolation JSON to the template
i18nObj.end(); // saving? this is taken from substack too.
var changedFileCache = [];

var isChangedFile = function(vinylFile) {
if (vinylFile.isNull()) {
return;
}
if (changedFileCache[vinylFile.path] != null) {
return changedFileCache[vinylFile.path];
}

var currentContent = fs.readFileSync(path.join(destinationDirectory, file.filename + '.html'), {encoding: 'utf8'});
var currentHash = currentContent.match(/Hashsum:\s(\b([a-f0-9]{40})\b)/);
if (currentHash && currentHash.length > 2) {
currentHash = currentHash[1]
} else {
currentHash = null
}

var contents = String(vinylFile.contents);
var newHash = crypto
.createHash("sha1")
.update(vinylFile.contents, "binary")
.digest("hex");

var isChanged = (currentHash !== newHash);

if (isChanged) {
contents = contents.replace(/Hashsum:(?:\s+\b([a-f0-9]{40})\b)?/, `Hashsum: ${newHash}`)
contents = contents.replace('Build Time:', `Build Time: ${buildTime}`)
contents = contents.replace('Commit Sha:', `Commit Sha: ${commitSha}`)
contents = contents.replace('Commit Msg:', `Commit Msg: ${commitMsg}`)
vinylFile.contents = new Buffer(contents);
}
changedFileCache[vinylFile.path] = isChanged;
return isChanged;
};

var templateContent = {
i18n: thisFileJSON,
content: html,
lang: lang,
build: {
markdownPage: file.filename,
pageStylesheet: file.filename
}
};

var fileStream = gulp.src(filepath) // pulling this code from substack's example on html-template
.pipe(rename(file.filename + '.html')) // converting the readStream to a vinyl stream so gulp can write it back to the disk
.pipe(buffer())
.pipe(handlebars(templateContent))
.pipe(gulpif(isChangedFile, gulp.dest(destinationDirectory))); // dump it in the appropriate language subfolder
});
});
});
Expand Down
5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,21 +47,24 @@
"glob": "^4.3.5",
"gulp": "^3.8.10",
"gulp-changed": "^1.1.0",
"gulp-compile-handlebars": "^0.4.4",
"gulp-connect": "^2.2.0",
"gulp-filesize": "0.0.6",
"gulp-htmlmin": "^1.0.0",
"gulp-if": "^1.2.5",
"gulp-imagemin": "^2.1.0",
"gulp-less": "^2.0.1",
"gulp-markdown": "^1.0.0",
"gulp-postcss": "^4.0.2",
"gulp-rename": "^1.2.0",
"gulp-stylus": "^2.0.0",
"html-template": "^1.2.1",
"lodash": "^2.4.1",
"markdown-it": "^3.0.4",
"moment-timezone": "^0.3.0",
"replacestream": "^2.0.0",
"require-dir": "^0.1.0",
"run-sequence": "^1.0.2",
"vinyl-buffer": "^1.0.0",
"vinyl-source-stream": "^1.0.0"
}
}
31 changes: 16 additions & 15 deletions public/cn/es6.html
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<!DOCTYPE html>
<html lang="en">
<html lang="cn">

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

<header>
<div class="content">
<a href="index.html" class="logo" i18n-logo-text>io.js</a>
<a href="index.html" class="logo">io.js</a>
<div class="spacer"></div>
<a href="faq.html" i18n-faq-link>常见问题</a>
<a href="es6.html" i18n-es6-link>ES6</a>
<a href="https://iojs.org/api/" i18n-api-link>API 文档</a>
<a href="faq.html">常见问题</a>
<a href="es6.html">ES6</a>
<a href="https://iojs.org/api/">API 文档</a>
</div>
</header>

<div class="content clearfix" i18n-content><h1>io.js 运行 ES6</h1>
<div class="content clearfix"><h1>io.js 运行 ES6</h1>
<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>
<p>io.js 1.3.0 集成了 V8 4.1.0.14 版本,其中包含的 ES6 特性远超 joyent/[email protected] 集成的 3.26.33 版本所包含的。</p>
<h2>干掉 --harmony</h2>
Expand Down Expand Up @@ -121,11 +121,11 @@ <h2>如何查阅某一版本的 io.js 所集成的 V8 的版本?</h2>

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

Expand All @@ -136,10 +136,11 @@ <h2>如何查阅某一版本的 io.js 所集成的 V8 的版本?</h2>
<!--
=========== BUILD INFORMATION ===========

Build Time: 2015-02-20 14:45:25 UTC
Build Time: 2015-02-26 12:44:12 UTC

Commit Sha: 626785252f037c99c2fdbf1d93e71019684a2cb4
Commit Msg: update io.js version to 1.3.0 in all languages
Commit Sha: 68970fd56e9b43ccbb6bfd2d7720ef484936f92f
Commit Msg: Initial public template changes resulting from template modifications
Hashsum: da1ab8449a06c7c7ba9bf54d17b00d72a5f1247d

=========== END BUILD INFORMATION ===========
-->
31 changes: 16 additions & 15 deletions public/cn/faq.html
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<!DOCTYPE html>
<html lang="en">
<html lang="cn">

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

<header>
<div class="content">
<a href="index.html" class="logo" i18n-logo-text>io.js</a>
<a href="index.html" class="logo">io.js</a>
<div class="spacer"></div>
<a href="faq.html" i18n-faq-link>常见问题</a>
<a href="es6.html" i18n-es6-link>ES6</a>
<a href="https://iojs.org/api/" i18n-api-link>API 文档</a>
<a href="faq.html">常见问题</a>
<a href="es6.html">ES6</a>
<a href="https://iojs.org/api/">API 文档</a>
</div>
</header>

<div class="content clearfix" i18n-content><h1>常见问题</h1>
<div class="content clearfix"><h1>常见问题</h1>
<h2>io.js 是什么?</h2>
<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>
<p>想知道为什么?io.js 能提供更短、可预测的发布周期。目前,它融合了最新的语言特性,API 和 V8 引擎的性能改进,并且会持续更新 libuv 和其他底层库。</p>
Expand All @@ -52,11 +52,11 @@ <h2>什么是开放的管理模式?</h2>

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

Expand All @@ -67,10 +67,11 @@ <h2>什么是开放的管理模式?</h2>
<!--
=========== BUILD INFORMATION ===========

Build Time: 2015-02-20 14:45:25 UTC
Build Time: 2015-02-26 12:44:12 UTC

Commit Sha: 626785252f037c99c2fdbf1d93e71019684a2cb4
Commit Msg: update io.js version to 1.3.0 in all languages
Commit Sha: 68970fd56e9b43ccbb6bfd2d7720ef484936f92f
Commit Msg: Initial public template changes resulting from template modifications
Hashsum: 376cc54fd6a3da0d92459c8a8b767b317add2ec4

=========== END BUILD INFORMATION ===========
-->
31 changes: 16 additions & 15 deletions public/cn/index.html
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<!DOCTYPE html>
<html lang="en">
<html lang="cn">

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

<header>
<div class="content">
<a href="index.html" class="logo" i18n-logo-text>io.js</a>
<a href="index.html" class="logo">io.js</a>
<div class="spacer"></div>
<a href="faq.html" i18n-faq-link>常见问题</a>
<a href="es6.html" i18n-es6-link>ES6</a>
<a href="https://iojs.org/api/" i18n-api-link>API 文档</a>
<a href="faq.html">常见问题</a>
<a href="es6.html">ES6</a>
<a href="https://iojs.org/api/">API 文档</a>
</div>
</header>

<div class="content clearfix" i18n-content><h1>JavaScript I/O</h1>
<div class="content clearfix"><h1>JavaScript I/O</h1>
<p>将 <a href="es6.html">ES6</a> 带入 Node 社区!</p>
<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>
<p><a href="https://iojs.org/dist/v1.3.0/"><img src="../images/1.0.0.png" alt="io.js"></a></p>
Expand All @@ -48,11 +48,11 @@

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

Expand All @@ -63,10 +63,11 @@
<!--
=========== BUILD INFORMATION ===========

Build Time: 2015-02-20 14:45:25 UTC
Build Time: 2015-02-26 12:44:12 UTC

Commit Sha: 626785252f037c99c2fdbf1d93e71019684a2cb4
Commit Msg: update io.js version to 1.3.0 in all languages
Commit Sha: 68970fd56e9b43ccbb6bfd2d7720ef484936f92f
Commit Msg: Initial public template changes resulting from template modifications
Hashsum: 80471c1fe73fef2ea2cd69c220dbe4bc4e859b10

=========== END BUILD INFORMATION ===========
-->
31 changes: 16 additions & 15 deletions public/cs/es6.html
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<!DOCTYPE html>
<html lang="en">
<html lang="cs">

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

<header>
<div class="content">
<a href="index.html" class="logo" i18n-logo-text>io.js</a>
<a href="index.html" class="logo">io.js</a>
<div class="spacer"></div>
<a href="faq.html" i18n-faq-link>FAQ</a>
<a href="es6.html" i18n-es6-link>ES6</a>
<a href="https://iojs.org/api/" i18n-api-link>API Docs</a>
<a href="faq.html">FAQ</a>
<a href="es6.html">ES6</a>
<a href="https://iojs.org/api/">API Docs</a>
</div>
</header>

<div class="content clearfix" i18n-content><h1>ES6 on io.js</h1>
<div class="content clearfix"><h1>ES6 on io.js</h1>
<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>
<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>
<h2>No more --harmony flag</h2>
Expand Down Expand Up @@ -121,11 +121,11 @@ <h2>How do I find which version of V8 ships with a particular version of io.js?<

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

Expand All @@ -136,10 +136,11 @@ <h2>How do I find which version of V8 ships with a particular version of io.js?<
<!--
=========== BUILD INFORMATION ===========

Build Time: 2015-02-20 14:45:25 UTC
Build Time: 2015-02-26 12:44:12 UTC

Commit Sha: 626785252f037c99c2fdbf1d93e71019684a2cb4
Commit Msg: update io.js version to 1.3.0 in all languages
Commit Sha: 68970fd56e9b43ccbb6bfd2d7720ef484936f92f
Commit Msg: Initial public template changes resulting from template modifications
Hashsum: 753832db36670dfda3882d74d6d0573fd44d7859

=========== END BUILD INFORMATION ===========
-->
Loading