Permalink
Browse files

Works

  • Loading branch information...
1 parent ccd08fa commit e26da3238fdf505c180ee1b676287b5cede1ace5 @tmcw committed Oct 5, 2012
Showing with 79 additions and 1 deletion.
  1. +59 −0 index.html
  2. +2 −0 jquery.js
  3. +2 −1 package.json
  4. +16 −0 titles.js
View
@@ -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>
View
Oops, something went wrong.
View
@@ -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"
}
}
View
@@ -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.