Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Add utils/meetups.js to parse and write the list of meetups.
  • Loading branch information
francois2metz committed Feb 18, 2012
1 parent dfd7207 commit 1dac6cf
Show file tree
Hide file tree
Showing 5 changed files with 229 additions and 9 deletions.
14 changes: 14 additions & 0 deletions README.md
Expand Up @@ -2,6 +2,20 @@

This is the source of the parisjs.org website.

## Utils

Before everything else:

npm install

### Parsing all meetups and talks

node utils/meetups.js parse

### Writing all meetups

node utils/meetups.js update

## License

DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
Expand Down
18 changes: 9 additions & 9 deletions index.html
Expand Up @@ -66,12 +66,12 @@ <h2>We'll be there!</h2>
<div id="meetups">
<h2>Seen and heard in the meetups</h2>
<!-- Template for meetup content for lazy people :P
<li class="meetup-content">
<li>
<ul>
<li class="avatar"><img alt="twitter avatar" src="" /></li>
<li class="avatar"><img alt="" src=""></li>
<li class="titleTalk">Testing javascript</li>
<li class="authorTalk">By: <a href="http://twitter.com/">@</a></li>
<li class="descTalk">Here are the <a href="">Slides</a></li>
<li class="descTalk">Here are the <a href="">Slides</a>.</li>
</ul>
</li>
-->
Expand Down Expand Up @@ -173,7 +173,7 @@ <h2>Seen and heard in the meetups</h2>
<li class="avatar"></li>
<li class="titleTalk"> RxJS </li>
<li class="authorTalk">By: <a href="https://twitter.com/#!/jbrwk">@jbrwk</a></li>
<li class="descTalk">Here are the <s><a href="http://parisjs.org/#">Slides</a></s>!</li>
<li class="descTalk">Here are the <s><a href="#">Slides</a></s>!</li>
</ul>
<ul>
<li class="avatar"><img alt="twitter avatar" src="http://a2.twimg.com/profile_images/1499737633/avatar.jpg"/></li>
Expand Down Expand Up @@ -396,14 +396,14 @@ <h2>Seen and heard in the meetups</h2>
<li class="avatar"><img alt="twitter avatar" src="http://a1.twimg.com/profile_images/1432571433/photo_reasonably_small.png" /></li>
<li class="titleTalk">Cross-Browser JS Synthesizer</li>
<li class="authorTalk">By: <a href="http://twitter.com/#!/hexapode">@hexapode</a></li>
<li class="descTalk">Here are the <s><a href="http://parisjs.org/#">Slides</a></s>!</li>
<li class="descTalk">Here are the <s><a href="#">Slides</a></s>!</li>
</ul>

<ul>
<li class="avatar"><img alt="twitter avatar" src="http://a2.twimg.com/profile_images/1252804654/24750_1238080394441_1302186545_30538088_1432027_n_reasonably_small.jpg" /></li>
<li class="titleTalk">Observer pattern done right</li>
<li class="authorTalk">By: <a href="http://twitter.com/#!/shinuza">@shinuza</a></li>
<li class="descTalk">Here are the <s><a href="http://parisjs.org/#">Slides</a></s>!</li>
<li class="descTalk">Here are the <s><a href="#">Slides</a></s>!</li>
</ul>

<ul>
Expand All @@ -417,7 +417,7 @@ <h2>Seen and heard in the meetups</h2>
<li class="avatar"><img alt="twitter avatar" src="https://si0.twimg.com/profile_images/1500074506/5825926997_3a11d50cd9_b.jpeg" /></li>
<li class="titleTalk">Overview of awesome Mozilla Labs projects</li>
<li class="authorTalk">By: <a href="http://twitter.com/tbassetto">@tbassetto</a></li>
<li class="descTalk">Here are the <s><a href="http://parisjs.org/#">Slides</a></s>!</li>
<li class="descTalk">Here are the <s><a href="#">Slides</a></s>!</li>
</ul>

</li>
Expand Down Expand Up @@ -449,7 +449,7 @@ <h2>Seen and heard in the meetups</h2>

<ul>
<li class="avatar"><img alt="twitter avatar" src="https://si0.twimg.com/profile_images/1500074506/5825926997_3a11d50cd9_b.jpeg" /></li>
<li class="titleTalk">Video cpature using HTML5</li>
<li class="titleTalk">Video capture using HTML5</li>
<li class="authorTalk">By: <a href="http://twitter.comt/bassetto">@tbassetto</a></li>
<li class="descTalk">Here are the <a href="http://www.slideshare.net/tbassetto/fr-capture-vido-avec-html5">Slides</a>!</li>
</ul>
Expand All @@ -458,7 +458,7 @@ <h2>Seen and heard in the meetups</h2>
<li class="avatar"><img alt="twitter avatar" src="http://a1.twimg.com/profile_images/762702904/12870_229006808135_636953135_4441217_1387053_n_reasonably_small.jpg" /></li>
<li class="titleTalk">CouchDB user feedback</li>
<li class="authorTalk">By: <a href="http://twitter.com/#!/challet">@challet</a></li>
<li class="descTalk">Here are the <s><a href="http://parisjs.org/#">Slides</a></s>!</li>
<li class="descTalk">Here are the <s><a href="#">Slides</a></s>!</li>
</ul>

</li>
Expand Down
15 changes: 15 additions & 0 deletions package.json
@@ -0,0 +1,15 @@
{
"name": "parisjs-website",
"description": "The website of parisjs.org",
"version": "0.0.1",
"homepage": "http://parisjs.org/",
"repository": {
"type": "git",
"url": "git://github.com/parisjs/parisjs-website.git"
},
"dependencies": {
"jsdom": "",
"underscore": ""
},
"devDependencies": {}
}
177 changes: 177 additions & 0 deletions utils/meetups.js
@@ -0,0 +1,177 @@
#!/usr/bin/env node
/**
* You don't want to manage the list of events/talks/people by hands? This script can help you.
*
* It's a two way parser:
* - read index.html and extract the list of events/talks/people and output JSON on stdout
* - read a JSON from stdin and update index.html
*
* Why JSON?
* Because there is no good yaml parser in javascript, and it was out of the scope for now
*
* How to use it?
* node utils/meetups.js parse > meetup.json
* node utils/meetups.js update < meetup.json
*/

var jsdom = require('jsdom')
, fs = require('fs')
, _ = require('underscore')
;

if (process.argv.length == 3) {
if (process.argv[2] == 'parse') {
return parseMeetups();
} else if (process.argv[2] == 'update') {
return updateMeetups();
}
}
console.log('usage');
console.log('node utils/meetups.js parse');
console.log('node utils/meetups.js update');
return;

function readStdin(callback) {
var data = "";
process.stdin.resume();
process.stdin.setEncoding('utf8');

process.stdin.on('data', function (chunk) {
data += chunk;
});
process.stdin.on('end', function () {
callback(data);
});
}

function updateMeetups() {
readStdin(function(data) {
var meetups = JSON.parse(data);
var html = generateHTMLFor(meetups);
var website = fs.readFileSync(__dirname + '/../index.html', 'utf8');

var jquery = 'http://code.jquery.com/jquery-1.5.min.js';
jsdom.env(website, [jquery],
function(errors, window) {
if (errors) {
return console.error('jsdom error', errors)
}
var $ = window.$;
var $meetups = $('#meetups > ul').empty().append("\n ").append($(html)).append("\n ");
var document = window.document;
// remove the jquery inserted by jsdom
$('script:last', document).remove();
var output = document.doctype + document.innerHTML;
console.log(output.trim());
});
});
}

function generateHTMLFor(meetups) {
var template = _.template(fs.readFileSync(__dirname +'/template_meetup.html', 'utf8'));
var html = meetups.map(function(meetup) {
return template(meetup);
});
return "\n"+ html.join('')+"\n\n";
}

//

function parseMeetups() {
var website = fs.readFileSync(__dirname + '/../index.html', 'utf8');

var jquery = 'http://code.jquery.com/jquery-1.5.min.js';
jsdom.env(website, [jquery],
function(errors, window) {
if (errors) {
return console.error('jsdom error', errors)
}
var $ = window.$;
var meetups = extractMeetups($);
console.log(JSON.stringify(meetups));
//var normalization = normalizeMeetups(meetups);
//console.log(JSON.stringify(normalization));
});
}

/**
* The hard part
* find same authors to have a ref to each ones
*/
function normalizeMeetups(meetups) {
var authors = {};
// don't worry, this is only the first level of indentation
meetups.forEach(function(meetup) {
// don't worry, this is only the second level of indentation
meetup.talks.forEach(function(talk) {
// don't worry, this is only the last level of indentation
talk.authors = talk.authors.map(function(author) {
if (authors[author.name]) {
var previous = authors[author.name];
['url', 'avatar'].forEach(function(property) {
if (author[property] != previous[property])
console.error('grrrr! '+ property +' mismatch for '+ author.name);
});
}
authors[author.name] = author;
return author.name;
});
})
});
return {
meetups: meetups,
authors: authors
}
}

/**
* Return a raw object of all events and talks
*/
function extractMeetups($) {
var $meetups = $('#meetups li.meetup');
var meetups = [];
$meetups.each(function() {
var $meetup = $(this);
var meetup = {
title: $(this).text(),
talks: []
};
var $talks = $meetup.next('.meetup-content').find('> ul');
meetup.talks = extractTalks($, $talks);
meetups.push(meetup);
});
return meetups;
}

function extractTalks($, $talks) {
return $talks.toArray().map(function(talk) {
var $talk = $(talk);

function getLinks(regexp) {
return $talk.find('.descTalk a').filter(function() {
return $(this).text().match(regexp);
}).map(function() {
return $(this).attr('href');
}).toArray();
}

var slides = getLinks(/slide/i);
var videos = getLinks(/(video|part)/i);
var projects = getLinks(/project/i);

return {
title: $talk.find('.titleTalk').text().trim(),
slides: slides,
videos: videos,
projects: projects,
authors: $talk.find('.authorTalk a').map(function() {
return {
name: $(this).text(),
url: $(this).attr('href'),
// sorry boy, in case of multiple authors, we have only one avatar
avatar: $talk.find('.avatar img').attr('src')
}
}).toArray()
}
});
}
14 changes: 14 additions & 0 deletions utils/template_meetup.html
@@ -0,0 +1,14 @@
<li class="meetup"><a href="#"><%= title %></a></li>

<li class="meetup-content"><% talks.forEach(function(talk) { %>

<ul>
<li class="avatar"><% if (talk.authors[0].avatar) { %><img alt="twitter avatar" src="<%= talk.authors[0].avatar %>"><% } %></li>
<li class="titleTalk"><%= talk.title %></li>
<li class="authorTalk">By: <% for (var i=0; i<talk.authors.length; i++) { var author = talk.authors[i]; var end = (i == talk.authors.length - 1); %><a href="<%= author.url %>"><%= author.name %></a><% if (!end) print(" and "); } %></li>
<li class="descTalk">Here are the <% if (talk.projects.length == 1) { %><a href="<%= talk.projects[0] %>">project</a><% } %><% if (talk.slides.length == 1) { if (talk.slides[0] == "#") print('<s>'); %><a href="<%= talk.slides[0] %>">Slides</a><%if (talk.slides[0] == "#") print('</s>'); } %><% if (talk.videos.length > 0) { %>
and the <% for (var j=0; j<talk.videos.length; j++) { %><a href="<%= talk.videos[j] %>">video<% if (talk.videos.length > 1) print(' part.'+ (j+1)); %></a><% } }%>!</li>
</ul><% }) %>

</li>

0 comments on commit 1dac6cf

Please sign in to comment.