Skip to content

Commit ce15cae

Browse files
committed
Merge pull request #3 from SignpostMarv/recent-update-display-all
Pre-render index page
2 parents dffb4e3 + f890d1a commit ce15cae

File tree

9 files changed

+114
-110
lines changed

9 files changed

+114
-110
lines changed

Gruntfile.js

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,18 @@ module.exports = function Gruntfile(grunt) {
1313
'assets/app.js',
1414
],
1515
},
16+
htmlSnapshot: {
17+
index: {
18+
options: {
19+
bodyAttr: 'data-prerendered',
20+
fileNamePrefix: '',
21+
msWaitForPages: 5000,
22+
urls: [
23+
'assets/index.vulcanized.html',
24+
],
25+
},
26+
},
27+
},
1628
postcss: {
1729
options: {
1830
processors: [
@@ -27,6 +39,13 @@ module.exports = function Gruntfile(grunt) {
2739
},
2840
},
2941
},
42+
rename: {
43+
index: {
44+
files: {
45+
'index.html': 'assets_index.vulcanized.html.html',
46+
},
47+
},
48+
},
3049
uglify: {
3150
assets: {
3251
files: {
@@ -42,7 +61,7 @@ module.exports = function Gruntfile(grunt) {
4261
},
4362
index: {
4463
files: {
45-
'index.html': 'assets/index.html',
64+
'assets/index.vulcanized.html': 'assets/index.html',
4665
},
4766
},
4867
},
@@ -80,6 +99,8 @@ module.exports = function Gruntfile(grunt) {
8099
],
81100
tasks: [
82101
'vulcanize:index',
102+
'htmlSnapshot:index',
103+
'rename:index',
83104
],
84105
},
85106
},
@@ -90,5 +111,7 @@ module.exports = function Gruntfile(grunt) {
90111
'uglify:assets',
91112
'postcss:assets',
92113
'vulcanize:index',
114+
'htmlSnapshot:index',
115+
'rename:index',
93116
]);
94117
};

assets/app.js

Lines changed: 39 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@
6060
[3600, 'minutes', 60],
6161
[7200, '1 hour ago'],
6262
[86400, 'hours', 3600],
63-
[172800, 'Yesterday'],
63+
[172800, 'yesterday'],
6464
[604800, 'days', 86400],
6565
[1209600, '1 week ago'],
6666
[2678400, 'weeks', 604800],
@@ -72,43 +72,46 @@
7272
return f[2] ? Math.floor(seconds / f[2]) + ' ' + f[1] + ' ago' : f[1];
7373
}
7474
}
75-
return 'A while ago';
76-
}
77-
78-
// Display a repo's overview (for recent updates section)
79-
function showRepoOverview(repo) {
80-
var item = (
81-
'<li>' +
82-
'<span class="name"><a href="' + repo.html_url + '">' +
83-
repo.name +
84-
'</a></span>' +
85-
' &middot; ' +
86-
'<span class="time"><a href="' + repo.html_url + '/commits">' +
87-
prettyDate(repo.pushed_at) +
88-
'</a></span>' +
89-
'</li>'
90-
);
91-
92-
$(item).appendTo('#updated-repos');
75+
return 'a while ago';
9376
}
9477

9578
// Create an entry for the repo in the grid of org repos
9679
function showRepo(repo) {
97-
var $item = $('<div class="unit-1-3 repo" />');
98-
var $link = $('<a class="box" href="' + getRepoUrl(repo) + '" />');
99-
100-
$link.append('<h2 class="repo__name">' + repo.name + '</h2>');
101-
$link.append(
102-
'<p class="repo__info">' +
103-
repo.watchers +
104-
' stargazers &middot; ' +
105-
repo.language +
106-
'</p>'
107-
);
108-
$link.append('<p class="repo__desc">' + getRepoDesc(repo) + '</p>');
109-
110-
$link.appendTo($item);
111-
$item.appendTo('#repos');
80+
var $item = $('.unit-1-3.repo[data-repo-name="' + repo.name + '"]');
81+
var alreadyThere = $item.length >= 1;
82+
if (!alreadyThere) {
83+
$item = $(
84+
'<div class="unit-1-3 repo">' +
85+
'<a class="box" href="">' +
86+
'<h2 class="repo__name"></h2>' +
87+
'<p class="repo__info">' +
88+
'<span class="repo__watchers"></span>' +
89+
' stargazers &middot; ' +
90+
'<span class="repo__language"></span>' +
91+
'<span class="repo__updated">&nbsp;</span>' +
92+
'</p>' +
93+
'<p class="repo__desc"></p>' +
94+
'</a>' +
95+
'</div>'
96+
);
97+
$item.attr('data-repo-name', repo.name);
98+
}
99+
100+
$item.children('a').attr('href', getRepoUrl(repo));
101+
$item.find('.repo__name').text(repo.name);
102+
$item.find('.repo__watchers').text(repo.watchers);
103+
$item.find('.repo__language').text(repo.language);
104+
$item.find('.repo__desc').text(getRepoDesc(repo));
105+
if ($('body').attr('data-prerendered') === 'data-prerendered') {
106+
$item.find('.repo__updated').text(
107+
'Updated ' +
108+
prettyDate(repo.pushed_at)
109+
);
110+
}
111+
112+
if (!alreadyThere) {
113+
$item.appendTo('#repos');
114+
}
112115
}
113116

114117
$.ajax({
@@ -125,27 +128,7 @@
125128
// Convert pushed_at to Date.
126129
$.each(repos, function feRepo(i, REPO) {
127130
var repo = REPO;
128-
var weekHalfLife = 1.146 * Math.pow(10, -9);
129-
var pushDelta;
130-
var createdDelta = (new Date()) - Date.parse(repo.created_at);
131-
var weightForPush = 1;
132-
var weightForWatchers = 1.314 * Math.pow(10, 7);
133-
134131
repo.pushed_at = new Date(repo.pushed_at);
135-
pushDelta = (new Date()) - Date.parse(repo.pushed_at);
136-
repo.hotness = weightForPush * Math.pow(Math.E, -1 * weekHalfLife * pushDelta);
137-
repo.hotness += weightForWatchers * repo.watchers / createdDelta;
138-
});
139-
140-
// Sort by hotness.
141-
repos.sort(function sortRepos(a, b) {
142-
if (a.hotness < b.hotness) return 1;
143-
if (b.hotness < a.hotness) return -1;
144-
return 0;
145-
});
146-
147-
$.each(repos, function feSortedRepo(i, repo) {
148-
showRepo(repo);
149132
});
150133

151134
// Sort by most-recently pushed to.
@@ -155,8 +138,8 @@
155138
return 0;
156139
});
157140

158-
$.each(repos.slice(0, 3), function feSlicedRepos(i, repo) {
159-
showRepoOverview(repo);
141+
$.each(repos, function feSortedRepo(i, repo) {
142+
showRepo(repo);
160143
});
161144
});
162145
},

assets/app.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

assets/index.html

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,11 @@ <h3>Regular Expressions made easy</h3>
1919
<a href="https://github.com/VerbalExpressions/repositories">
2020
<b id="num-repos">View</b> public repos
2121
</a>
22-
<br>
22+
,
2323
<a href="https://github.com/VerbalExpressions?tab=members">
2424
<b id="num-members">View</b> members
2525
</a>
2626
</p>
27-
<h3>Recently updated</h3>
28-
<ol id="updated-repos"></ol>
2927
<a class="twitter-share-button"
3028
href="http://twitter.com/share"
3129
data-text="All the VerbalExpressions projects in one place"

assets/index.vulcanized.html

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
<!DOCTYPE html><html lang="en"><head>
2+
<meta charset="utf-8">
3+
<title>VerbalExpressions ♥ Open Source</title>
4+
<meta name="description" content="Find all the VerbalExpressions projects in one place.">
5+
<meta name="viewport" content="width=device-width, initial-scale=1">
6+
<style>
7+
html{font:14px/1.4 Helvetica Neue,Helvetica,Arial,sans-serif;color:#333;-webkit-text-size-adjust:100%;-ms-text-size-adjust:100%}body{max-width:940px;padding:20px 10px;margin:0 auto;background:#f5f5f5}img{border:0;-ms-interpolation-mode:bicubic}a{color:#0084b4;text-decoration:none}a:active,a:focus,a:hover{color:#005e80;text-decoration:underline}a:focus{outline:thin dotted}a:active,a:hover{outline:0}h1,h2,h3{margin:0 0 1em}.h1,h1{margin:0 0 .25em;font-size:3em}.h2,h2{font-size:1.25em}.h3,h3{font-size:1.125em;color:#777}p{margin:0 0 1em}ol,ul{list-style:none;padding:0;margin:0}.grid{display:block;padding:0;margin:0 -10px;letter-spacing:-.31em;*letter-spacing:normal;word-spacing:-.43em;text-rendering:optimizespeed}.unit-1-3{width:300px;display:inline-block;margin:0 10px 20px;vertical-align:top;letter-spacing:normal;word-spacing:normal;text-rendering:auto;*display:inline;*zoom:1}.box{display:block;overflow:hidden;min-height:200px;padding:15px;border:1px solid #ddd;border-radius:4px;text-decoration:none;background:#fff}a.box:active,a.box:focus,a.box:hover{padding:12px;border-width:4px;border-color:#005e80;text-decoration:none}.site-header{float:left;text-align:center}.site-header a{min-height:48px;min-width:48px;line-height:48px}.stats{font-size:1.125em}.twitter-share-button{margin-top:30px}.repo__name{margin:0 0 .1em;font-size:1.5em}.repo__info{display:block;margin:0 0 1.25em;font-size:12px;font-weight:700;color:#999}.repo__info .repo__updated{display:block}.repo__desc{color:#666}.repo__team{overflow:hidden;margin:20px -1px 0}.repo__team img{float:left;width:23px;height:23px;border:1px solid #999;margin:0 1px;background:#eee}.site-footer{padding:15px;border:1px solid #ddd;border-radius:4px;background:#fff;clear:both}.site-footer p{margin:0}@media (max-width:960px){body{max-width:620px}}@media (max-width:640px){body{max-width:300px}}
8+
</style>
9+
</head>
10+
<body>
11+
<div class="grid">
12+
<div class="unit-1-3 site-header">
13+
<div class="box">
14+
<div class="site-logo">
15+
<h2>VerbalExpressions</h2>
16+
</div>
17+
<h3>Regular Expressions made easy</h3>
18+
<p class="stats">
19+
<a href="https://github.com/VerbalExpressions/repositories">
20+
<b id="num-repos">View</b> public repos
21+
</a>
22+
,
23+
<a href="https://github.com/VerbalExpressions?tab=members">
24+
<b id="num-members">View</b> members
25+
</a>
26+
</p>
27+
<a class="twitter-share-button" href="http://twitter.com/share" data-text="All the VerbalExpressions projects in one place" data-url="http://VerbalExpressions.github.com/" data-count="none" target="_blank">Tweet</a>
28+
29+
</div>
30+
</div>
31+
32+
<div class="site-content" id="repos"></div>
33+
</div>
34+
35+
<footer class="site-footer">
36+
<p>VerbalExpressions <span id="year"></span></p>
37+
</footer>
38+
39+
<script async="">!function(a,b){var c,d=a.getElementsByTagName(b)[0],e=function(e,f,g){var h=f;a.getElementById(h)||(c=a.createElement(b),c.src=e,h&&(c.id=h),g&&(c.onload=g),d.parentNode.insertBefore(c,d))};e("http://platform.twitter.com/widgets.js","twitter-wjs"),e("https://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js",!1,function(){"use strict";function a(a){return g[a.name]||a.html_url}function b(a){return h[a.name]||a.description}function c(a){var b,c,d,e,f=0;for(b=new Date(a),c=(new Date-b)/1e3,d=[[60,"seconds",1],[120,"1 minute ago"],[3600,"minutes",60],[7200,"1 hour ago"],[86400,"hours",3600],[172800,"yesterday"],[604800,"days",86400],[1209600,"1 week ago"],[2678400,"weeks",604800]],f=0;f<d.length;f++)if(e=d[f],c<e[0])return e[2]?Math.floor(c/e[2])+" "+e[1]+" ago":e[1];return"a while ago"}function d(d){var f=e('.unit-1-3.repo[data-repo-name="'+d.name+'"]'),g=f.length>=1;g||(f=e('<div class="unit-1-3 repo"><a class="box" href=""><h2 class="repo__name"></h2><p class="repo__info"><span class="repo__watchers"></span> stargazers &middot; <span class="repo__language"></span><span class="repo__updated">&nbsp;</span></p><p class="repo__desc"></p></a></div>'),f.attr("data-repo-name",d.name)),f.children("a").attr("href",a(d)),f.find(".repo__name").text(d.name),f.find(".repo__watchers").text(d.watchers),f.find(".repo__language").text(d.language),f.find(".repo__desc").text(b(d)),"data-prerendered"===e("body").attr("data-prerendered")&&f.find(".repo__updated").text("Updated "+c(d.pushed_at)),g||f.appendTo("#repos")}var e=window.jQuery,f="VerbalExpressions",g={"verbalexpressions.github.io":"http://verbalexpressions.github.io/"},h={};e.ajax({dataType:"json",url:"https://api.github.com/orgs/"+f+"/repos?per_page=100",headers:{},success:function(a){var b=a;e(function(){e("#num-repos").text(b.length),e.each(b,function(a,b){var c=b;c.pushed_at=new Date(c.pushed_at)}),b.sort(function(a,b){return a.pushed_at<b.pushed_at?1:b.pushed_at<a.pushed_at?-1:0}),e.each(b,function(a,b){d(b)})})}}),e.ajax({dataType:"json",url:"https://api.github.com/orgs/"+f+"/members",headers:{},success:function(a){var b=a;e(function(){e("#num-members").text(b.length)})}}),e("#year").html((new Date).getFullYear())})}(document,"script");</script>
40+
41+
42+
</body></html>

assets/style.css

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -144,17 +144,13 @@ a.box:active {
144144
text-align: center;
145145
}
146146

147-
.site-header .box {
148-
min-height: 452px;
149-
}
150147
.site-header a {
151148
min-height: 48px ;
152149
min-width: 48px ;
153150
line-height: 48px ;
154151
}
155152

156153
.stats {
157-
margin: 0 0 2em;
158154
font-size: 1.125em;
159155
}
160156

@@ -177,6 +173,9 @@ a.box:active {
177173
font-weight: bold;
178174
color: #999;
179175
}
176+
.repo__info .repo__updated {
177+
display: block ;
178+
}
180179

181180
.repo__desc {
182181
color: #666;

0 commit comments

Comments
 (0)