Skip to content
This repository was archived by the owner on Sep 6, 2021. It is now read-only.

Commit 31106b7

Browse files
author
Marcel Gerber
committed
Update Web Platform Docs & Provide update script
1 parent ed56656 commit 31106b7

File tree

5 files changed

+131
-1
lines changed

5 files changed

+131
-1
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,3 +34,4 @@ Thumbs.db
3434

3535
# Files that can be automatically downloaded that we don't want to ship with our builds
3636
/src/extensibility/node/node_modules/request/tests/
37+
/src/extensions/default/WebPlatformDocs/update-docs/node_modules

src/extensions/default/WebPlatformDocs/css.json

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Updates css.json via the Web Platform Docs API
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
{
2+
"name": "update-docs",
3+
"version": "0.0.1",
4+
"description": "Updates from Web Platform Docs",
5+
"main": "update-docs.js",
6+
"author": "Marcel Gerber <mg.hain@gmx.de>",
7+
"keywords": [
8+
"mediawiki", "wiki", "parser"
9+
],
10+
"licenses": [
11+
{
12+
"type": "MIT",
13+
"url": "https://github.com/adobe/brackets/blob/master/LICENSE"
14+
}
15+
],
16+
"devDependencies": {
17+
"instaview": "0.6.3",
18+
"lodash.unescape": "2.4.1"
19+
},
20+
"repository": {
21+
"type": "git",
22+
"url": "https://github.com/adobe/brackets.git"
23+
}
24+
}
Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
/*
2+
* Copyright (c) 2014 Adobe Systems Incorporated. All rights reserved.
3+
*
4+
* Permission is hereby granted, free of charge, to any person obtaining a
5+
* copy of this software and associated documentation files (the "Software"),
6+
* to deal in the Software without restriction, including without limitation
7+
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
8+
* and/or sell copies of the Software, and to permit persons to whom the
9+
* Software is furnished to do so, subject to the following conditions:
10+
*
11+
* The above copyright notice and this permission notice shall be included in
12+
* all copies or substantial portions of the Software.
13+
*
14+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
19+
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
20+
* DEALINGS IN THE SOFTWARE.
21+
*
22+
*/
23+
/*global require*/
24+
25+
(function () {
26+
"use strict";
27+
28+
var fs = require("fs"),
29+
https = require("https"),
30+
instaview = require("instaview"),
31+
unescape = require("lodash.unescape");
32+
33+
instaview.conf.paths.articles = "https://docs.webplatform.org/wiki/";
34+
35+
var propertiesURL = "https://docs.webplatform.org/w/api.php?action=ask&format=json&query=%20%5B%5BPath%3A%3A~css%2Fproperties%2F*%5D%5D%7C%3FSummary%7Cprettyprint%3Dno%7Climit%3D100000", // #ask: [[Path::~css/properties/*]]|?Summary|prettyprint=no|limit=100000
36+
valuesURL = "https://docs.webplatform.org/w/api.php?action=ask&format=json&query=%5B%5BValue%20for%20property%3A%3A~css%2Fproperties%2F*%5D%5D%7C%3FProperty%20value%7C%3FProperty%20value%20description%7C%3FValue%20for%20property%7Cprettyprint%3Dno%7Climit%3D100000"; // #ask: [[Value for property::~css/properties/*]]|?Property value|?Property value description|?Value for property|prettyprint=no|limit=100000
37+
38+
var result = {},
39+
outputFile = "../css.json",
40+
propertiesResponse = "",
41+
valuesResponse = "";
42+
43+
console.log("Getting properties");
44+
https.get(propertiesURL, function (res) {
45+
res.on("data", function (chunk) {
46+
propertiesResponse += chunk;
47+
});
48+
49+
res.on("end", function () {
50+
console.log("Parsing properties");
51+
propertiesResponse = JSON.parse(propertiesResponse).query.results;
52+
Object.keys(propertiesResponse).forEach(function (propertyName) {
53+
var data = propertiesResponse[propertyName];
54+
var propertyData = {};
55+
if (data.printouts.Summary.length) {
56+
propertyData.SUMMARY = instaview.convert(data.printouts.Summary[0]);
57+
propertyData.URL = data.fullurl;
58+
propertyData.VALUES = [];
59+
60+
result[propertyName] = propertyData;
61+
}
62+
});
63+
console.log("Getting values");
64+
https.get(valuesURL, function (res) {
65+
res.on("data", function (chunk) {
66+
valuesResponse += chunk;
67+
});
68+
69+
res.on("end", function () {
70+
function parseHTMLEntities(str) {
71+
return str.replace(/&#([0-9]{1,4});/g, function (match, numStr) {
72+
var num = parseInt(numStr, 10);
73+
return String.fromCharCode(num);
74+
});
75+
}
76+
77+
console.log("Parsing values");
78+
valuesResponse = JSON.parse(valuesResponse).query.results;
79+
80+
Object.keys(valuesResponse).forEach(function (valueIdentifier) {
81+
var data = valuesResponse[valueIdentifier].printouts;
82+
var forProperty = data["Value for property"].length && data["Value for property"][0].fulltext;
83+
var valueData = {};
84+
if (data["Property value"].length && forProperty && result.hasOwnProperty(forProperty)) {
85+
valueData.DESCRIPTION = "";
86+
if (data["Property value description"].length) {
87+
valueData.DESCRIPTION = instaview.convert(data["Property value description"][0]);
88+
}
89+
valueData.TITLE = parseHTMLEntities(unescape(data["Property value"][0]));
90+
91+
result[forProperty].VALUES.push(valueData);
92+
}
93+
});
94+
fs.writeFile(outputFile, JSON.stringify({DATETIME: new Date().toUTCString(), PROPERTIES: result}));
95+
console.log("Done writing " + Object.keys(result).length + " properties.");
96+
}).on("error", function (e) {
97+
console.error(e);
98+
});
99+
});
100+
});
101+
}).on("error", function (e) {
102+
console.error(e);
103+
});
104+
}());

0 commit comments

Comments
 (0)