Skip to content
Permalink
Browse files

Lazy load icon list

  • Loading branch information...
jxnblk committed Oct 28, 2016
1 parent 30b676c commit 81dfaa28c10b2a1a2a9de0eea4e6f4d758a7f442
Showing with 71 additions and 10 deletions.
  1. +5 −0 .babelrc
  2. +13 −4 index.js
  3. +6 −3 landing/Root.js
  4. +10 −0 landing/entry.js
  5. +5 −2 package.json
  6. +1 −1 simple-icons.js
  7. +31 −0 webpack.config.js
@@ -0,0 +1,5 @@
{
"presets": [
"es2015"
]
}
@@ -1,6 +1,8 @@

const fs = require('fs')
const path = require('path')
const url = require('url')
const { createElement } = require('react')
const { createElement: h } = require('react')
const { renderToStaticMarkup } = require('react-dom/server')
const Icon = require('./Icon')
const relineKeys = require('./reline-keys')
@@ -106,6 +108,12 @@ const parseUrl = url => {
}

module.exports = (req, res) => {
if (/bundle\.js/.test(req.url)) {
res.setHeader('Content-Type', 'text/html')
fs.createReadStream(path.join(__dirname, 'bundle.js'))
.pipe(res)
return
}
if (/robots\.txt/.test(req.url)) {
return `User-agent: Twitterbot\n Disallow:`
}
@@ -124,13 +132,14 @@ module.exports = (req, res) => {
)

if (!name) {
return renderToStaticMarkup(
createElement(Root)
const html = renderToStaticMarkup(
h(Root)
)
return html
}

const svg = renderToStaticMarkup(
createElement(Icon, Object.assign({
h(Icon, Object.assign({
name,
}, params))
)
@@ -3,7 +3,6 @@ const { createElement: h } = require('react')
const Head = require('./Head')
const Header = require('./Header')
const Usage = require('./Usage')
const IconList = require('./IconList')
const Footer = require('./Footer')

module.exports = ({
@@ -12,8 +11,12 @@ module.exports = ({
h(Head),
h(Header),
h(Usage),
h(IconList),
h(Footer)
h('div', { id: 'icons' }),
h(Footer),
h('script', {
async: true,
src: 'bundle.js'
})
)
)

@@ -0,0 +1,10 @@

const { createElement: h }= require('react')
const ReactDOM = require('react-dom')
const IconList = require('./IconList')

ReactDOM.render(
h(IconList),
icons
)

@@ -4,7 +4,7 @@
"description": "",
"main": "index.js",
"scripts": {
"build": "node build.js",
"build": "node build.js && webpack -p",
"postinstall": "napa danleech/simple-icons#gh-pages",
"start": "./node_modules/micro/bin/micro -p 3000",
"dev": "nodemon --exec 'npm start'"
@@ -23,7 +23,10 @@
"reline": "^1.0.0-beta.3"
},
"devDependencies": {
"babel-loader": "^6.2.7",
"babel-preset-es2015": "^6.18.0",
"cheerio": "^0.22.0",
"nodemon": "^1.11.0"
"nodemon": "^1.11.0",
"webpack": "^1.13.3"
}
}

Large diffs are not rendered by default.

@@ -0,0 +1,31 @@

const webpack = require('webpack')
const path = require('path')

module.exports = {
entry: './landing/entry.js',

output: {
path: __dirname,
filename: 'bundle.js'
},

module: {
loaders: [
{
test: /\.js$/,
exclude: /node_modules/,
loader: 'babel'
}
]
},

plugins: [
new webpack.DefinePlugin({
'process.env':{
'NODE_ENV': JSON.stringify('production')
}
})
]
}

0 comments on commit 81dfaa2

Please sign in to comment.
You can’t perform that action at this time.