-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathbootstrap.js
71 lines (56 loc) · 1.9 KB
/
bootstrap.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
var jsdom = require('jsdom');
var fs = require('fs-extra');
var path = require('path');
var jquery = fs.readFileSync("./lib/jquery.js", "utf-8");
var generateJSON = function(window){
var $ = window.$;
var output = {};
$('.bs-docs-section').each(function(){
var $t = $(this);
var $header = $t.find('.page-header');
var id = $header.attr('id');
var title = $header.text();
var contents = [];
var exampleID = 1;
$t.find('.bs-example').each(function(){
var html = [];
html.push($(this).children()[0].outerHTML);
var header = $(this).prevAll('h4').html();
if (!header) header = $(this).prevAll('h3').html();
if (!header) header = $(this).prevAll('h2').html();
if (!header) header = $(this).prevAll('h1').html();
contents.push({
header: header,
id: exampleID,
html: html
});
exampleID++;
});
output[id] = {
id: id,
url: 'http://getbootstrap.com/components#' + id,
title: title,
contents: contents
};
});
return output;
};
jsdom.env({
file: 'raw/bootstrap.html',
// url: "http://getbootstrap.com/components",
src: [jquery],
done: function (errors, window) {
var dataPath = '../user-bootstrap/data/bootstrap';
var fileName = 'bootstrap.json';
var fullPath = path.join(dataPath, fileName);
var data = generateJSON(window);
// Preparing path for data write
fs.mkdirp(dataPath, function (err) {
if (err) return console.error(err);
fs.writeFile(fullPath, JSON.stringify(data, null, 4), function(err) {
if (err) return console.error(err);
console.log('JSON saved to: ' + fullPath);
});
});
}
});