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

Commit

Permalink
Update Web Platform Docs & Provide update script
Browse files Browse the repository at this point in the history
  • Loading branch information
Marcel Gerber committed Oct 26, 2014
1 parent ed56656 commit 31106b7
Show file tree
Hide file tree
Showing 5 changed files with 131 additions and 1 deletion.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,4 @@ Thumbs.db

# Files that can be automatically downloaded that we don't want to ship with our builds
/src/extensibility/node/node_modules/request/tests/
/src/extensions/default/WebPlatformDocs/update-docs/node_modules
2 changes: 1 addition & 1 deletion src/extensions/default/WebPlatformDocs/css.json

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Updates css.json via the Web Platform Docs API
24 changes: 24 additions & 0 deletions src/extensions/default/WebPlatformDocs/update-docs/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"name": "update-docs",
"version": "0.0.1",
"description": "Updates from Web Platform Docs",
"main": "update-docs.js",
"author": "Marcel Gerber <mg.hain@gmx.de>",
"keywords": [
"mediawiki", "wiki", "parser"
],
"licenses": [
{
"type": "MIT",
"url": "https://github.com/adobe/brackets/blob/master/LICENSE"
}
],
"devDependencies": {
"instaview": "0.6.3",
"lodash.unescape": "2.4.1"
},
"repository": {
"type": "git",
"url": "https://github.com/adobe/brackets.git"
}
}
104 changes: 104 additions & 0 deletions src/extensions/default/WebPlatformDocs/update-docs/update-docs.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
/*
* Copyright (c) 2014 Adobe Systems Incorporated. All rights reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*
*/
/*global require*/

(function () {
"use strict";

var fs = require("fs"),
https = require("https"),
instaview = require("instaview"),
unescape = require("lodash.unescape");

instaview.conf.paths.articles = "https://docs.webplatform.org/wiki/";

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
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

var result = {},
outputFile = "../css.json",
propertiesResponse = "",
valuesResponse = "";

console.log("Getting properties");
https.get(propertiesURL, function (res) {
res.on("data", function (chunk) {
propertiesResponse += chunk;
});

res.on("end", function () {
console.log("Parsing properties");
propertiesResponse = JSON.parse(propertiesResponse).query.results;
Object.keys(propertiesResponse).forEach(function (propertyName) {
var data = propertiesResponse[propertyName];
var propertyData = {};
if (data.printouts.Summary.length) {
propertyData.SUMMARY = instaview.convert(data.printouts.Summary[0]);
propertyData.URL = data.fullurl;
propertyData.VALUES = [];

result[propertyName] = propertyData;
}
});
console.log("Getting values");
https.get(valuesURL, function (res) {
res.on("data", function (chunk) {
valuesResponse += chunk;
});

res.on("end", function () {
function parseHTMLEntities(str) {
return str.replace(/&#([0-9]{1,4});/g, function (match, numStr) {
var num = parseInt(numStr, 10);
return String.fromCharCode(num);
});
}

console.log("Parsing values");
valuesResponse = JSON.parse(valuesResponse).query.results;

Object.keys(valuesResponse).forEach(function (valueIdentifier) {
var data = valuesResponse[valueIdentifier].printouts;
var forProperty = data["Value for property"].length && data["Value for property"][0].fulltext;
var valueData = {};
if (data["Property value"].length && forProperty && result.hasOwnProperty(forProperty)) {
valueData.DESCRIPTION = "";
if (data["Property value description"].length) {
valueData.DESCRIPTION = instaview.convert(data["Property value description"][0]);
}
valueData.TITLE = parseHTMLEntities(unescape(data["Property value"][0]));

result[forProperty].VALUES.push(valueData);
}
});
fs.writeFile(outputFile, JSON.stringify({DATETIME: new Date().toUTCString(), PROPERTIES: result}));
console.log("Done writing " + Object.keys(result).length + " properties.");
}).on("error", function (e) {
console.error(e);
});
});
});
}).on("error", function (e) {
console.error(e);
});
}());

0 comments on commit 31106b7

Please sign in to comment.