Skip to content

Commit

Permalink
Add 404.html
Browse files Browse the repository at this point in the history
  • Loading branch information
kokororin committed Dec 7, 2016
1 parent 9ac2419 commit aa62c7d
Show file tree
Hide file tree
Showing 4 changed files with 106 additions and 17 deletions.
36 changes: 20 additions & 16 deletions cfg/dist.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,17 +55,18 @@ let config = Object.assign({}, baseConfig, {
this.plugin('done', function(statsData) {
let stats = statsData.toJson();
if (!stats.errors.length) {
let htmlFileName = '/../dist/index.html';
let htmlFilePath = path.join(__dirname, htmlFileName);
let html = fs.readFileSync(htmlFilePath, 'utf8');
let htmlFileNames = ['/../dist/index.html', '/../dist/404.html'];
htmlFileNames.map(function(htmlFileName) {
let htmlFilePath = path.join(__dirname, htmlFileName);
let html = fs.readFileSync(htmlFilePath, 'utf8');

// let htmlOutput = html.replace(
// /<script\s+src=(["'])(.+?)bundle\.js\1/i,
// '<script src=$1$2' + stats.assetsByChunkName.main + '?' + stats.hash + '$1');
// let htmlOutput = html.replace(
// /<script\s+src=(["'])(.+?)bundle\.js\1/i,
// '<script src=$1$2' + stats.assetsByChunkName.main + '?' + stats.hash + '$1');

let htmlOutput = html.replace(
/<script\s+src=(["'])(.+?)bundle\.js(.*)<\/script>/i,
`<script type="text/javascript">
let htmlOutput = html.replace(
/<script\s+src=(["'])(.+?)bundle\.js(.*)<\/script>/i,
`<script type="text/javascript">
(function(hash, src, localStorage, document, window) {
var createScript = function(url) {
var script = document.createElement("script");
Expand Down Expand Up @@ -109,15 +110,18 @@ let config = Object.assign({}, baseConfig, {
})("${stats.hash}", "$2${stats.assetsByChunkName.main}?${stats.hash}", window.localStorage, document, window);
</script>`);

htmlOutput = minify(htmlOutput, {
collapseWhitespace: true,
removeComments: true,
minifyJS: true,
minifyCSS: true,
processConditionalComments: true
htmlOutput = minify(htmlOutput, {
collapseWhitespace: true,
removeComments: true,
minifyJS: true,
minifyCSS: true,
processConditionalComments: true
});

fs.writeFileSync(htmlFilePath, htmlOutput);
});

fs.writeFileSync(htmlFilePath, htmlOutput);

}
});
}
Expand Down
1 change: 1 addition & 0 deletions dist/404.html
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<!doctype html><html lang="ja"><head><meta charset="utf-8"><title>pixivの「ラブライブ」発見</title><meta name="viewport" content="width=device-width,initial-scale=1"><meta name="google-site-verification" content="aHrpJZ8M_WPQb07omJ2bwC2fg2DQMgFFEovu9wsSD0E"><link rel="dns-prefetch" href="//www.pixiv.net"><link rel="shortcut icon" type="image/x-icon" href="/favicon.ico?version=0.8.7"><style>.message{text-align:center;padding:20px 0;color:#999}.message p{font-size:15px}</style></head><body><!--[if lte IE 8]><div class="message"><p>古いInternet Explorerにサ終了!</p><script type="text/javascript">!function(){try{document.getElementById("app").innerHTML="";var t=window.location.hash.replace("#/","");!isNaN(parseFloat(t))&&isFinite(t)&&(document.write("<p>あなたはpixiv.netへリダイレクトしています</p>"),setTimeout(function(){window.location.href="http://www.pixiv.net/member_illust.php?mode=medium&illust_id="+t},1500))}catch(t){document.write("<p>申し訳ございません</p>")}}()</script></div><![endif]--><noscript><div class="message"><p>Javascriptが無効になっていると、サイト内の一部機能がご利用いただけません</p></div></noscript><div id="app"><div class="message"><p>あなただけが存在しませんああルート...悲しみを打ちます。</p></div></div><script type="text/javascript">!function(){var e=window.location.pathname.replace("/","").match(/\/([0-9]{0,}$)/);e&&e[1]&&(document.getElementById("app").innerHTML='<div class="message"><p>あなたはpixiv.netへリダイレクトしています</p></div>',setTimeout(function(){window.location.href="http://www.pixiv.net/member_illust.php?mode=medium&illust_id="+e[1]},1500))}()</script><script>!function(e,a,t,n,c,o,s){e.GoogleAnalyticsObject=c,e[c]=e[c]||function(){(e[c].q=e[c].q||[]).push(arguments)},e[c].l=1*new Date,o=a.createElement(t),s=a.getElementsByTagName(t)[0],o.async=1,o.src=n,s.parentNode.insertBefore(o,s)}(window,document,"script","//www.google-analytics.com/analytics.js","ga"),ga("create","UA-70944432-2","auto"),ga("send","pageview")</script></body></html>
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"main": "server.js",
"scripts": {
"clean": "rimraf dist/*",
"copy": "copyfiles -f ./src/index.html ./src/favicon.ico ./src/robots.txt ./src/CNAME ./dist",
"copy": "copyfiles -f ./src/*.html ./src/favicon.ico ./src/robots.txt ./src/CNAME ./dist",
"dist": "npm run clean && npm run copy && webpack --env=dist",
"lint": "eslint --max-warnings 0 ./src",
"posttest": "npm run lint",
Expand Down
84 changes: 84 additions & 0 deletions src/404.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
<!doctype html>
<html lang="ja">

<head>
<meta charset="utf-8">
<title>pixivの「ラブライブ」発見</title>
<meta name="viewport" content="width=device-width, initial-scale=1" />
<meta name="google-site-verification" content="aHrpJZ8M_WPQb07omJ2bwC2fg2DQMgFFEovu9wsSD0E" />
<link rel="dns-prefetch" href="//www.pixiv.net">
<link rel="shortcut icon" type="image/x-icon" href="/favicon.ico?version=0.8.7">
<style>
.message {
text-align: center;
padding: 20px 0;
color: #999;
}

.message p {
font-size: 15px;
}
</style>
</head>

<body>
<!--[if lte IE 8]>
<div class="message">
<p>古いInternet Explorerにサ終了!</p>
<script type="text/javascript">
(function() {
try {
document.getElementById('app').innerHTML = '';
var afterHash = window.location.hash.replace('#/', '');
if (!isNaN(parseFloat(afterHash)) && isFinite(afterHash)) {
document.write('<p>あなたはpixiv.netへリダイレクトしています</p>');
setTimeout(function() {
window.location.href = 'http://www.pixiv.net/member_illust.php?mode=medium&illust_id=' + afterHash;
}, 1500);
}
} catch ( e ) {
document.write('<p>申し訳ございません</p>');
}
})();
</script>
</div>
<![endif]-->
<noscript>
<div class="message">
<p>Javascriptが無効になっていると、サイト内の一部機能がご利用いただけません</p>
</div>
</noscript>
<div id="app">
<div class="message">
<p>あなただけが存在しませんああルート...悲しみを打ちます。</p>
</div>
</div>
<script type="text/javascript">
(function() {
var matches = window.location.pathname.replace('/', '').match(/\/([0-9]{0,}$)/);
if (matches && matches[1]) {
document.getElementById('app').innerHTML = '<div class="message"><p>あなたはpixiv.netへリダイレクトしています</p></div>';
setTimeout(function() {
window.location.href = 'http://www.pixiv.net/member_illust.php?mode=medium&illust_id=' + matches[1];
}, 1500);
}
})();
</script>
<script>
(function(i, s, o, g, r, a, m) {
i['GoogleAnalyticsObject'] = r;
i[r] = i[r] || function() {
(i[r].q = i[r].q || []).push(arguments)
}, i[r].l = 1 * new Date();
a = s.createElement(o),
m = s.getElementsByTagName(o)[0];
a.async = 1;
a.src = g;
m.parentNode.insertBefore(a, m)
})(window, document, 'script', '//www.google-analytics.com/analytics.js', 'ga');
ga('create', 'UA-70944432-2', 'auto');
ga('send', 'pageview');
</script>
</body>

</html>

0 comments on commit aa62c7d

Please sign in to comment.