Skip to content

Commit

Permalink
Works
Browse files Browse the repository at this point in the history
  • Loading branch information
tmcw committed Oct 5, 2012
1 parent ccd08fa commit e26da32
Show file tree
Hide file tree
Showing 4 changed files with 79 additions and 1 deletion.
59 changes: 59 additions & 0 deletions index.html
@@ -0,0 +1,59 @@
<!DOCTYPE html>
<html>
<head>
<title>DC Municipal Regulations</title>
<style>
body {
font:normal 15px/20px 'Helvetica';
}
input {
font-size:50px;
}
#output {
width:100%;
height:400px;
}
#output a {
display:block;
}
</style>
</head>
<body>
<form action='POST'>
<input type='text' id='search' />
</form>
<pre id='output'></pre>
<script src='jquery.js'></script>
<script>
var indexes = {}, titles;
$.getJSON('titles.json', function(o) {
titles = o;
});
var $output = $('#output');
$('#search').keyup(function() {
var v = this.value;
var norm = v.replace(/[^A-Za-z]/g, '').toLowerCase();
if (norm.length > 2) {
var a = norm[0];
if (!indexes[a]) {
indexes[a] = {};
$('#output').text('');
$.getJSON('indexes/' + a + '.json', function(o) {
indexes[a] = o;
});
} else {
$output.empty();
(indexes[a][norm] || []).map(function(i) {
var link = document.createElement('a');
link.href = 'text/' + i + '.txt';
link.innerHTML = titles[i];
$output.append(link);
});
}
} else {
$output.text('');
}
});
</script>
</body>
</html>
2 changes: 2 additions & 0 deletions jquery.js

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion package.json
Expand Up @@ -10,6 +10,7 @@
"dependencies": {
"cheerio": "~0.10.1",
"underscore": "~1.4.1",
"request": "~2.11.4"
"request": "~2.11.4",
"underscore.string": "~2.3.0"
}
}
16 changes: 16 additions & 0 deletions titles.js
@@ -0,0 +1,16 @@
var _s = require('underscore.string'),
path = require('path'),
fs = require('fs');

fs.readdir('docs', function(err, files) {
var titles = {};
files.filter(function(f) {
return f.indexOf('.title') !== -1;
}).map(function(t) {
var id = +t.match(/(\d+)/)[0];
titles[id] = fs.readFileSync('docs/' + t, 'utf8').trim();
});
console.log('done');
fs.writeFileSync('titles.json', JSON.stringify(titles));
console.log('writing thing');
});

0 comments on commit e26da32

Please sign in to comment.