-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgenerate.js
108 lines (89 loc) · 3.29 KB
/
generate.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
var fs = require('fs'),
_ = require('lodash'),
Citation = require('citation'),
sm = require('sitemap'),
glob = require('glob');
var section_tmpl = _.template(fs.readFileSync('templates/section._', 'utf8'));
var index_tmpl = _.template(fs.readFileSync('templates/index._', 'utf8'));
var title_tmpl = _.template(fs.readFileSync('templates/title._', 'utf8'));
function cited2(x) { return x; }
function cited(text) {
var c = Citation.find(text, {
context: {
dc_code: {
source: 'dc_code'
}
},
excerpt: 40,
types: ['dc_code', 'dc_register', 'law', 'stat'],
replace: {
dc_code: codeCited,
law: lawCited,
dc_register: dcrCited,
stat: statCited
}
}).text;
return c;
function linked(url, text) {
return "<a href='" + url + "'>" + text + "</a>";
}
function statCited(cite) {
if (parseInt(cite.stat.volume, 10) < 65)
return;
return linked('http://api.fdsys.gov/link?collection=statute&volume=' + cite.stat.volume + '&page=' + cite.stat.page,
cite.match);
}
// is this a current DC Code cite (something we should cross-link),
// or is it to a prior version of the DC Code?
function codeCited(cite) {
var index = cite.excerpt.search(/ior\s+codifications\s+1981\s+Ed\.?\,?/i);
if (index > 0 && index < 40) // found, and to the left of the cite
return;
return linked("./" + cite.dc_code.title + "-" + cite.dc_code.section + '.html',
cite.match);
}
function lawCited(cite) {
var lawName = cite.law.type + " law " + cite.law.congress + "-" + cite.law.number;
var url = 'http://www.govtrack.us/search?q=' + encodeURIComponent(lawName);
return linked(url, cite.match);
}
// just link to that year's copy on the DC Register website
function dcrCited(cite) {
if (parseInt(cite.dc_register.volume, 10) < 57)
return;
var year = parseInt(cite.dc_register.volume, 10) + 1953;
return linked('http://www.dcregs.dc.gov/Gateway/IssueList.aspx?IssueYear=' + year,
cite.match);
}
}
var urls = [];
glob.sync('sections/*.json').forEach(function(s) {
var section = JSON.parse(fs.readFileSync(s));
fs.writeFileSync('sections/' + section.heading.identifier + '.html',
section_tmpl({ section: section, cited: cited }));
urls.push({
url: '/simple/sections/' + section.heading.identifier + '.html'
});
console.log('done with ', section.heading.identifier);
});
var index = JSON.parse(fs.readFileSync('index.json'));
fs.writeFileSync('index.html', index_tmpl({ index: index }));
index.titles.forEach(function(i) {
var all_sections = index.sections.filter(function(s) {
return s[0].split('-')[0] == i[0];
});
fs.writeFileSync(i[0] + '.html', title_tmpl({ all_sections: all_sections, title: i }));
console.log('done with ', i[0]);
urls.push({
url: '/simple/' + i[0] + '.html'
});
});
console.log('generating sitemap');
sitemap = sm.createSitemap({
hostname: 'http://dccode.org',
cacheTime: 600000, // 600 sec - cache purge period
urls: urls
});
sitemap.toXML(function(xml) {
fs.writeFileSync('sitemap.xml', xml);
});