-
Notifications
You must be signed in to change notification settings - Fork 210
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use mdn-links package for cross-linking MDN
- Loading branch information
Andy Earnshaw
committed
Jul 6, 2015
1 parent
b9004dd
commit 634c65f
Showing
3 changed files
with
60 additions
and
60 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
#!/usr/bin/env node | ||
'use strict'; | ||
|
||
var get = require('https').get, | ||
fs = require('fs'), | ||
path = require('path'), | ||
|
||
// MDN base URLS | ||
baseURLs = [ | ||
'https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects', | ||
'https://developer.mozilla.org/en-US/docs/Web/API' | ||
], | ||
|
||
done = 0, | ||
output = 'module.exports = ', | ||
|
||
// Final data object | ||
data = {}; | ||
|
||
baseURLs.forEach(function (u) { | ||
get(u + '$children', function (res) { | ||
var text = ''; | ||
|
||
res.on('data', function(d) { | ||
text += d; | ||
}); | ||
|
||
res.on('end', function () { | ||
var vars = JSON.parse(text); | ||
|
||
data[u] = vars.subpages.reduce(function (d, c) { | ||
// Only get classes for now, though methods/functions might be useful for | ||
// crosslinking | ||
if (!~c.title.indexOf('()') && !~c.title.indexOf(' ')) { | ||
d[c.title] = c.slug.slice(c.slug.lastIndexOf('/')); | ||
} | ||
return d; | ||
}, {}); | ||
|
||
if (++done === baseURLs.length) { | ||
write(); | ||
} | ||
}); | ||
}); | ||
}); | ||
|
||
function write () { | ||
fs.writeFileSync( | ||
path.join(__dirname, '../lib/mdn.js'), | ||
output + JSON.stringify(data, null, 4) + ';' | ||
); | ||
} |