Skip to content

Commit 053b4c7

Browse files
author
mrmrs
committed
Merge branch 'master' of github.com:tachyons-css/tachyons-css.github.io
2 parents 37048b8 + a83bf8f commit 053b4c7

File tree

144 files changed

+1352
-673
lines changed

Some content is hidden

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

144 files changed

+1352
-673
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@ node_modules
22
npm-debug.log
33
.DS_STORE
44
*.swp
5+
tmp

build.js

Lines changed: 46 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,46 @@
1-
require('./src/header-build')()
2-
require('./src/gallery-build')()
3-
require('./src/resources-build')()
4-
console.log('header build complete')
5-
require('./src/table-of-styles-build')()
6-
console.log('table of styles build complete')
7-
require('./src/table-of-properties-build')()
8-
console.log('table of properties build complete')
9-
require('./src/home-build')()
10-
console.log('home build complete')
11-
//require('./src/components-build')()
12-
//console.log('components build complete')
1+
const chalk = require('chalk');
2+
const co = require('co');
3+
const prettyHrtime = require('pretty-hrtime');
4+
5+
const startTime = process.hrtime();
6+
7+
// require('./src/header-build')()
8+
// require('./src/gallery-build')()
9+
// require('./src/resources-build')()
10+
// console.log('header build complete')
11+
// require('./src/table-of-styles-build')()
12+
// console.log('table of styles build complete')
13+
// require('./src/table-of-properties-build')()
14+
// console.log('table of properties build complete')
15+
// require('./src/home-build')()
16+
// console.log('home build complete')
17+
18+
const componentsBuildIndex = require('./src/components-build-index');
19+
const componentsBuildPages = require('./src/components-build-pages');
20+
const componentsBuildScreenshots = require('./src/components-build-screenshots');
21+
22+
// See src/components-build-defaults for list of options that can be overriden
23+
const options = {
24+
// componentsGlobPattern: 'src/components/buttons/*.html',
25+
};
26+
27+
// Note that componentsBuildIndex() generates the index *and* the JSON
28+
// file listing all the components pages and screenshots should be built for.
29+
// Scenario: if you are working on one component, uncomment and set componentsGlobPattern
30+
// in the options above to only (re-)generate the index, pages, and screenshots for the
31+
// corresponding category. When you are done, comment componentsGlobPattern back, comment
32+
// the line below that generate the screenshots, then run the script -- this will
33+
// re-create the full index page for all components, re-generate all the pages (since they need
34+
// to cross-reference the new component), and use the previously generated screenshots as well
35+
// as the new one (i.e. no need to re-generate *all* the screenshots unless you made
36+
// modifications to the screenshots script itself).
37+
co(function* generator() {
38+
yield componentsBuildIndex(options); // <- builds component index page and JSON index
39+
yield componentsBuildPages(options); // <- comment to skip building pages
40+
yield componentsBuildScreenshots(options); // <- comment to skip building screenshots
41+
}).then(() => {
42+
const elapsed = process.hrtime(startTime);
43+
console.log(chalk.green('All done'), chalk.dim(prettyHrtime(elapsed)));
44+
}).catch((err) => {
45+
console.log(err);
46+
});

js/lazysizes.min.js

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

js/ls.unveilhooks.min.js

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,10 @@
2424
"doc:images": "watch 'node src/modules/images.js' src/templates/docs/images",
2525
"doc:bgsize": "watch 'node src/modules/background-size.js' src/templates/docs/background-size",
2626
"build:all": "node build.js && bash script.sh",
27-
"cson": "node src/components-cson-build.js"
27+
"cson": "node src/components-cson-build.js",
28+
"copy:lazysizes": "cp node_modules/lazysizes/lazysizes.min.js js/",
29+
"copy:lazysizes:plugins": "cp node_modules/lazysizes/plugins/unveilhooks/ls.unveilhooks.min.js js/",
30+
"postinstall": "npm run copy:lazysizes && npm run copy:lazysizes:plugins"
2831
},
2932
"repository": "tachyons-css/tachyons-css.github.io",
3033
"author": "mrmrs",
@@ -33,6 +36,16 @@
3336
"url": "https://github.com/tachyons-css/tachyons-css.github.io/issues"
3437
},
3538
"dependencies": {
39+
"chalk": "^1.1.3",
40+
"co": "^4.6.0",
41+
"express": "^4.14.0",
42+
"filesize": "^3.3.0",
43+
"imagemin": "^5.2.2",
44+
"imagemin-mozjpeg": "^6.0.0",
45+
"jimp": "^0.2.27",
46+
"lazysizes": "^3.0.0-rc2",
47+
"nightmare": "^2.8.1",
48+
"pretty-hrtime": "^1.0.3",
3649
"tachyons-background-size": "^5.0.3",
3750
"tachyons-base": "^1.2.5",
3851
"tachyons-border-colors": "^4.2.2",
@@ -81,7 +94,8 @@
8194
"tachyons-white-space": "^4.0.1",
8295
"tachyons-widths": "^5.0.1",
8396
"tachyons-word-break": "3.0.1",
84-
"tachyons-z-index": "^1.0.4"
97+
"tachyons-z-index": "^1.0.4",
98+
"tmp": "0.0.31"
8599
},
86100
"devDependencies": {
87101
"autoprefixer": "^6.5.1",

src/components-build-defaults.js

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
module.exports = {
2+
// Components
3+
componentsForNavPath: 'tmp/componentsForNav.json', // temporary file built by the index
4+
componentsGlobPattern: 'src/components/**/*.html', // source components to process
5+
componentsIndexPath: 'components/index.html', // target location of components index
6+
componentsBuildPages: true, // false to skip building pages
7+
componentsBuildScreenshots: true, // false to skip building screenshots
8+
// Screenshots
9+
screenshotName: 'screenshot.jpg', // name JPEG screenshot in each component dir
10+
screenshotAspectRatio: '4x3', // Tachyon aspect ratio of screenshot in index
11+
screenshotViewportWidth: 1024, // viewport width used for capture
12+
screenshotViewportHeight: 768, // viewport height used for capture
13+
screenshotTargetMinWidth: 400, // min width of target, resized screenshot
14+
screenshotTargetMinHeight: 160, // min height of target, resized screenshot
15+
mozjpegQuality: 90, // mozjpeg optimizer quality (default 75)
16+
screenshotSelector: '[data-name="component-container"]', // DOM element to capture
17+
// Misc
18+
tachyonsCssPath: 'src/css/tachyons.css',
19+
serverPort: 3333,
20+
// Templates
21+
analyticsTemplatePath: 'src/templates/ga.html',
22+
componentsIndexTemplatePath: 'src/templates/components-index.html',
23+
componentsTemplatePath: 'src/templates/components.html',
24+
footerTemplatePath: 'src/templates/footer.html',
25+
headerTemplatePath: 'src/templates/header.html',
26+
headTemplatePath: 'src/templates/head.html',
27+
highlightTemplatePath: 'src/templates/highlight.html',
28+
lazysizesTemplate: 'src/templates/lazysizes.html',
29+
};

src/components-build-index.js

Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
const _ = require('lodash');
2+
const chalk = require('chalk');
3+
const crypto = require('crypto');
4+
const fm = require('json-front-matter');
5+
const fs = require('fs');
6+
const glob = require('glob');
7+
const mkdirp = require('mkdirp');
8+
const path = require('path');
9+
const prettyHrtime = require('pretty-hrtime');
10+
const rmHtmlExt = require('remove-html-extension');
11+
const titleize = require('titleize');
12+
13+
const defaults = require('./components-build-defaults');
14+
15+
const getTitle = (component) => {
16+
const title = rmHtmlExt(component).replace('src/components/', '').replace(/(\/|_|-)/g, ' ');
17+
return titleize(title);
18+
};
19+
20+
const getName = component => titleize(getTitle(component.split('/')[3]));
21+
22+
module.exports = _options => new Promise((resolve, reject) => {
23+
const options = _.assign({}, defaults, _options);
24+
const startTime = process.hrtime();
25+
glob(options.componentsGlobPattern, {}, (err, components) => {
26+
console.log(chalk.magenta('Working on components index...'));
27+
if (err) {
28+
reject(err);
29+
return;
30+
}
31+
32+
const npmPackage = JSON.parse(fs.readFileSync('package.json', 'utf8'));
33+
34+
const componentsForNav = {};
35+
components.forEach((component) => {
36+
const componentTokens = component.replace('src/components/', '').split('/');
37+
const category = componentTokens[0];
38+
39+
const componentHtml = fs.readFileSync(component, 'utf8');
40+
const fmParsed = fm.parse(componentHtml);
41+
const frontMatter = fmParsed.attributes || {};
42+
const dir = component.replace('src/', '').replace('.html', '');
43+
44+
// Compute component signature based on the Tachyons version and the contents of the
45+
// component itself. This can be used to bust the browser cache of screenshots.
46+
const md5sum = crypto.createHash('md5');
47+
md5sum.update(npmPackage.version);
48+
md5sum.update(componentHtml);
49+
const signature = md5sum.digest('hex');
50+
51+
componentsForNav[category] = componentsForNav[category] || [];
52+
componentsForNav[category].push({
53+
name: frontMatter.name || getName(component),
54+
title: frontMatter.title || getTitle(component),
55+
src: component,
56+
path: `${dir}/index.html`,
57+
href: `/${dir}/index.html`,
58+
screenshot: {
59+
path: `${dir}/${options.screenshotName}`,
60+
href: `/${dir}/${options.screenshotName}?version=${signature}`,
61+
},
62+
signature,
63+
frontMatter,
64+
});
65+
});
66+
67+
const categories = Object.keys(componentsForNav);
68+
console.log(
69+
'- Found', components.length, components.length > 1 ? 'components' : 'component',
70+
'in', categories.length, categories.length > 1 ? 'categories' : 'category'
71+
);
72+
73+
mkdirp.sync(path.dirname(options.componentsForNavPath));
74+
fs.writeFileSync(options.componentsForNavPath, JSON.stringify(componentsForNav, undefined, 2));
75+
console.log('- Created navigation JSON:', options.componentsForNavPath);
76+
77+
const analytics = fs.readFileSync(options.analyticsTemplatePath, 'utf8');
78+
const footer = fs.readFileSync(options.footerTemplatePath, 'utf8');
79+
const head = fs.readFileSync(options.headTemplatePath, 'utf8');
80+
const header = fs.readFileSync(options.headerTemplatePath, 'utf8');
81+
const componentsIndexTemplate = fs.readFileSync(options.componentsIndexTemplatePath, 'utf8');
82+
const lazysizesTemplate = fs.readFileSync(options.lazysizesTemplate, 'utf8');
83+
84+
const compiledPage = _.template(componentsIndexTemplate)({
85+
componentsForNav,
86+
title: 'Components',
87+
analytics,
88+
footer,
89+
head,
90+
header,
91+
lazysizesTemplate,
92+
options,
93+
});
94+
mkdirp.sync(path.dirname(options.componentsIndexPath));
95+
fs.writeFileSync(options.componentsIndexPath, compiledPage);
96+
console.log('- Created index:', options.componentsIndexPath);
97+
98+
const elapsed = process.hrtime(startTime);
99+
console.log(chalk.magenta('Done with components index!'), chalk.dim(prettyHrtime(elapsed)));
100+
resolve();
101+
}); // glob
102+
}); // return promise

0 commit comments

Comments
 (0)