From 5663df296cb3fde438124cb93d0e161ed916859d Mon Sep 17 00:00:00 2001 From: MoyuScript Date: Mon, 11 Dec 2017 21:20:14 +0800 Subject: [PATCH] Add gzipped package size to website (Fix #992) --- www/gatsby-config.js | 9 +- www/package-lock.json | 17 ++- www/package.json | 1 + www/src/pages/index.js | 251 +++++++++++++++++++++-------------------- 4 files changed, 151 insertions(+), 127 deletions(-) diff --git a/www/gatsby-config.js b/www/gatsby-config.js index c0522f5..463f623 100644 --- a/www/gatsby-config.js +++ b/www/gatsby-config.js @@ -1,6 +1,13 @@ +const gzipSize = require('gzip-size'); +const path = require('path'); +const fs = require('fs'); + module.exports = { siteMetadata: { - title: `Gatsby Default Starter` + title: `html2canvas`, + packageSize: gzipSize.sync( + fs.readFileSync(path.resolve(__dirname, '../dist/html2canvas.min.js')) + ) }, plugins: [ { diff --git a/www/package-lock.json b/www/package-lock.json index 5112c95..1003504 100644 --- a/www/package-lock.json +++ b/www/package-lock.json @@ -4608,11 +4608,12 @@ "integrity": "sha1-tyonTRsTeRBKAFC2OyB9xT/lb5k=" }, "gzip-size": { - "version": "3.0.0", - "resolved": "https://registry.npmjs.org/gzip-size/-/gzip-size-3.0.0.tgz", - "integrity": "sha1-VGGI6b3DN/Zzdy+BZgRks4nc5SA=", + "version": "4.1.0", + "resolved": "https://registry.npmjs.org/gzip-size/-/gzip-size-4.1.0.tgz", + "integrity": "sha1-iuCWJX6r59acRb4rZ8RIEk/7UXw=", "requires": { - "duplexer": "0.1.1" + "duplexer": "0.1.1", + "pify": "3.0.0" } }, "handlebars": { @@ -8713,6 +8714,14 @@ "which": "1.3.0" } }, + "gzip-size": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/gzip-size/-/gzip-size-3.0.0.tgz", + "integrity": "sha1-VGGI6b3DN/Zzdy+BZgRks4nc5SA=", + "requires": { + "duplexer": "0.1.1" + } + }, "is-windows": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/is-windows/-/is-windows-1.0.1.tgz", diff --git a/www/package.json b/www/package.json index a38f6e0..f60ddc9 100644 --- a/www/package.json +++ b/www/package.json @@ -17,6 +17,7 @@ "gatsby-remark-prismjs": "^1.2.10", "gatsby-source-filesystem": "^1.5.9", "gatsby-transformer-remark": "^1.7.23", + "gzip-size": "^4.1.0", "mkdirp": "^0.5.1", "typography": "^0.16.6", "typography-theme-github": "^0.15.10" diff --git a/www/src/pages/index.js b/www/src/pages/index.js index 07c1711..c661b56 100644 --- a/www/src/pages/index.js +++ b/www/src/pages/index.js @@ -21,154 +21,161 @@ const linkStyle = { color: '#fff' }; -const IndexPage = () => -
+export default ({data}) => { + return (
-
- -

html2canvas

-
-

- Screenshots with JavaScript -

+
+
+ +

html2canvas

+
+

+ Screenshots with JavaScript +

-
-
-

HTML

-
+
+
+

HTML

+
<div id="capture" style="padding: 10px; background: #f5da55">
     <h4 style="color: #000; ">Hello world!</h4>
 </div>
 
` - }} - /> -
-
-

JavaScript

-
+ }} + /> +
+
+

JavaScript

+
html2canvas(document.querySelector("#capture")).then(canvas => {
     document.body.appendChild(canvas)
 });
 
` - }} - /> -
-
- -
- - Try it out - - - Documentation - -
-
-
- -
-
-
Install NPM
- npm install --save html2canvas -
Install Yarn
- yarn add html2canvas - -
-
-
Connect
-
-