Optimize load time

This commit is contained in:
Flaviu Tamas 2015-05-31 18:07:37 -04:00
commit 8337b4b817
45 changed files with 84 additions and 76 deletions

49
Rules
View file

@ -13,40 +13,59 @@
# item, use the pattern “/about/*/”; “/about/*” will also select the parent,
# because “*” matches zero or more characters.
compile '*' do
if item.identifier == '/toc/'
compile '/assets/css/*' do
filter :erb
filter :rainpress if File.basename(item[:content_filename], ".*") == 'all'
end
compile '/assets/js/*' do
filter :erb
filter :uglify_js if File.basename(item[:content_filename], ".*") == 'all'
end
compile '/content/*' do
if item.identifier == '/content/toc/'
filter :kramdown
layout 'blank'
elsif item.identifier == '/footer/'
elsif item.identifier == '/content/footer/'
layout 'blank'
elsif item[:extension] == 'md'
filter :kramdown, {:input => 'GFM'}
filter :colorize_syntax, :default_colorizer => :pygmentize
filter :relativize_paths, :type => :html
layout 'default'
elsif item[:extension] == 'css'
elsif item[:extension] == 'js'
# don’t filter stylesheets, js
elsif item.binary?
# don’t filter binary items
else
filter :erb
layout 'default'
end
end
route '*' do
if item[:extension] == 'css'
# Write item with identifier /foo/ to /foo.css
route '/assets/css/*' do
# if not debug mode, only let all.css through
unless @config[:debug]
item.identifier.chop + '.css' if File.basename(item[:content_filename], ".*") == 'all'
else
item.identifier.chop + '.css'
elsif item[:extension] == 'js'
end
end
route '/assets/js/*' do
# if not debug mode, only let all.js through
unless @config[:debug]
item.identifier.chop + '.js' if File.basename(item[:content_filename], ".*") == 'all'
else
item.identifier.chop + '.js'
elsif item.binary?
end
end
route '/content/*' do
if item.binary?
# Write item with identifier /foo/ to /foo.ext
item.identifier.chop + '.' + item[:extension]
item.identifier.sub("/content", "").chop + '.' + item[:extension]
else
# Write item with identifier /foo/ to /foo/index.html
item.identifier + 'index.html'
item.identifier.sub("/content", "") + 'index.html'
end
end

View file

@ -0,0 +1 @@
<%= all_css @config[:stylesheets] %>

1
content/assets/css/normalize.css vendored Normal file
View file

@ -0,0 +1 @@
/*! normalize.css v3.0.3 | MIT License | github.com/necolas/normalize.css */html{font-family:sans-serif;-ms-text-size-adjust:100%;-webkit-text-size-adjust:100%}body{margin:0}article,aside,details,figcaption,figure,footer,header,hgroup,main,menu,nav,section,summary{display:block}audio,canvas,progress,video{display:inline-block;vertical-align:baseline}audio:not([controls]){display:none;height:0}[hidden],template{display:none}a{background-color:transparent}a:active,a:hover{outline:0}abbr[title]{border-bottom:1px dotted}b,strong{font-weight:bold}dfn{font-style:italic}h1{font-size:2em;margin:.67em 0}mark{background:#ff0;color:#000}small{font-size:80%}sub,sup{font-size:75%;line-height:0;position:relative;vertical-align:baseline}sup{top:-0.5em}sub{bottom:-0.25em}img{border:0}svg:not(:root){overflow:hidden}figure{margin:1em 40px}hr{box-sizing:content-box;height:0}pre{overflow:auto}code,kbd,pre,samp{font-family:monospace,monospace;font-size:1em}button,input,optgroup,select,textarea{color:inherit;font:inherit;margin:0}button{overflow:visible}button,select{text-transform:none}button,html input[type="button"],input[type="reset"],input[type="submit"]{-webkit-appearance:button;cursor:pointer}button[disabled],html input[disabled]{cursor:default}button::-moz-focus-inner,input::-moz-focus-inner{border:0;padding:0}input{line-height:normal}input[type="checkbox"],input[type="radio"]{box-sizing:border-box;padding:0}input[type="number"]::-webkit-inner-spin-button,input[type="number"]::-webkit-outer-spin-button{height:auto}input[type="search"]{-webkit-appearance:textfield;box-sizing:content-box}input[type="search"]::-webkit-search-cancel-button,input[type="search"]::-webkit-search-decoration{-webkit-appearance:none}fieldset{border:1px solid silver;margin:0 2px;padding:.35em .625em .75em}legend{border:0;padding:0}textarea{overflow:auto}optgroup{font-weight:bold}table{border-collapse:collapse;border-spacing:0}td,th{padding:0}

1
content/assets/js/all.js Normal file
View file

@ -0,0 +1 @@
<%= all_js @config[:scripts] %>

View file

@ -19,7 +19,7 @@ for i, v in a:
for i in 4..100:
b.add(i * i)
b.delete(0) # takes «O(n)» time
b.delete(0) # takes O(n) time
b = a[0] & b # Same as original b
```

Binary file not shown.

View file

@ -1,14 +0,0 @@
<?xml version="1.0" standalone="no"?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
<svg xmlns="http://www.w3.org/2000/svg">
<metadata>Copyright (C) 2014 by original authors @ fontello.com</metadata>
<defs>
<font id="fontello" horiz-adv-x="1000" >
<font-face font-family="fontello" font-weight="400" font-stretch="normal" units-per-em="1000" ascent="850" descent="-150" />
<missing-glyph horiz-adv-x="1000" />
<glyph glyph-name="check" unicode="&#xe800;" d="m932 534q0-22-15-38l-404-404-76-76q-16-15-38-15t-38 15l-76 76-202 202q-15 16-15 38t15 38l76 76q16 16 38 16t38-16l164-165 366 367q16 16 38 16t38-16l76-76q15-16 15-38z" horiz-adv-x="1000" />
<glyph glyph-name="star" unicode="&#xe801;" d="m634 290l171 165-235 35-106 213-105-213-236-35 171-165-41-235 211 111 211-111z m295 199q0-12-15-27l-203-197 48-279q1-4 1-12 0-28-23-28-10 0-22 7l-251 132-250-132q-13-7-23-7-11 0-17 9t-6 19q0 4 1 12l48 279-203 197q-14 15-14 27 0 21 31 26l280 40 126 254q11 23 27 23t28-23l125-254 280-40q32-5 32-26z" horiz-adv-x="928.6" />
<glyph glyph-name="fork" unicode="&#xe802;" d="m161 29q0 22-16 38t-38 15-38-15-15-38 15-38 38-16 38 16 16 38z m0 642q0 23-16 38t-38 16-38-16-15-38 15-38 38-15 38 15 16 38z m357-71q0 22-16 38t-38 16-38-16-15-38 15-38 38-16 38 16 16 38z m53 0q0-29-14-54t-39-39q-1-160-126-231-38-21-114-45-71-22-94-39t-23-56v-15q24-14 39-39t14-53q0-45-31-76t-76-32-76 32-31 76q0 29 15 53t39 39v458q-25 14-39 39t-15 53q0 45 31 76t76 32 76-32 31-76q0-29-14-53t-39-39v-278q30 15 86 32 30 10 49 17t39 17 33 22 22 29 16 38 5 51q-25 14-39 39t-15 54q0 45 31 76t76 31 76-31 31-76z" horiz-adv-x="571.4" />
</font>
</defs>
</svg>

Before

Width:  |  Height:  |  Size: 1.6 KiB

Binary file not shown.

Binary file not shown.

View file

@ -1,30 +0,0 @@
@font-face {
font-family: 'fontello';
src: url('/fonts/fontelloe.eot?23005170');
src: url('/fonts/fontelloe.eot?23005170#iefix') format('embedded-opentype'),
url('/fonts/fontellow.woff?23005170') format('woff'),
url('/fonts/fontellot.ttf?23005170') format('truetype'),
url('/fonts/fontellos.svg?23005170#fontello') format('svg');
font-weight: normal;
font-style: normal;
}
[class^="icon-"]:before, [class*=" icon-"]:before {
font-family: "fontello";
font-style: normal;
font-weight: normal;
speak: none;
display: inline-block;
text-decoration: inherit;
width: 1em;
margin-right: .2em;
text-align: center;
font-variant: normal;
text-transform: none;
}
.icon-check:before { content: '\e800'; } /* '' */
.icon-star:before { content: '\e801'; } /* '' */
.icon-fork:before { content: '\e802'; } /* '' */

View file

@ -2,28 +2,28 @@
<html lang="en-US">
<head>
<meta charset="utf-8">
<title>Nim by Example - <%= @item[:title] %></title>
<link rel="stylesheet" type="text/css" href="https://cdnjs.cloudflare.com/ajax/libs/normalize/3.0.3/normalize.min.css">
<link rel="stylesheet" href="<%= @items['/stylesheets/main/'].path %>">
<link rel="stylesheet" href="<%= @items['/stylesheets/colorful/'].path %>" title="colorful">
<link rel="stylesheet" href="<%= @items['/stylesheets/fontello/'].path %>">
<script type="text/x-mathjax-config">
MathJax.Hub.Config({tex2jax: {inlineMath: [['«', '»']]}});
MathJax.Hub.config.tex2jax.skipTags = ["script", "noscript", "style", "textarea", "annotation", "annotation-xml"];
</script>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.5.3/config/TeX-AMS_HTML.js" async></script>
<script src="/js/main.js" type="text/javascript"></script>
<% if @config[:debug] %>
<% for file in @config[:stylesheets] %>
<link rel="stylesheet" type="text/css" href="/assets/css/<%= File.basename(file, ".*") %>.css">
<% end %>
<% for file in @config[:scripts] %>
<script async src="/assets/js/<%= file %>"></script>
<% end %>
<% else %>
<link rel="stylesheet" type="text/css" href="/assets/css/all.css">
<script async src="/assets/js/all.js"></script>
<% end %>
<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-58002512-1', 'auto');
ga('require', 'displayfeatures');
ga('send', 'pageview');
</script>
<title>Nim by Example - <%= @item[:title] %></title>
<meta name="generator" content="nanoc <%= Nanoc::VERSION %>">
<meta http-equiv="Default-Style" content="colorful">
<meta name=viewport content="width=device-width, initial-scale=1">
@ -33,7 +33,7 @@
<div id="sidebar">
<div class="abs-hamburger"><div class="nav-toggle" onclick="javascript:sidebarClick();"><span></span></div></div>
<nav>
<%= @items["/toc/"].compiled_content(snapshot: :last) %>
<%= @items["/content/toc/"].compiled_content(snapshot: :last) %>
</nav>
</div>
@ -47,7 +47,7 @@
</div>
<footer>
<%= @items["/footer/"].compiled_content(snapshot: :last) %>
<%= @items["/content/footer/"].compiled_content(snapshot: :last) %>
</footer>
</body>
</html>

19
lib/helpers.rb Normal file
View file

@ -0,0 +1,19 @@
def all_js(files)
js_arr = []
for file in files
item = @items.find{|i| i.identifier == "/assets/js/#{file}/"}
puts "File #{file} doesn't exist!" unless item
js_arr << item.compiled_content
end
js_arr.join("\n")
end
def all_css(files)
css_arr = []
for file in files
item = @items.find{|i| i.identifier == "/assets/css/#{file}/"}
puts "File #{file} doesn't exist!" unless item
css_arr << item.compiled_content
end
css_arr.join("\n")
end

View file

@ -60,3 +60,14 @@ data_sources:
# The default encoding for all files in `content/` and `layouts/`.
encoding: utf-8
debug: false
scripts:
- main
stylesheets:
- normalize
- colorful
- main

View file

@ -1,4 +1,4 @@
box: flaviut/nim-by-example-build-vm@0.0.6
box: flaviut/nim-by-example-build-vm@0.0.7
build:
steps:
- script: