Created
April 8, 2016 05:37
-
-
Save rockarts/659def6a05305f79befb02e3d534813e to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| var Firebase = require('firebase'); | |
| var json2html = require('node-json2html'); | |
| const api = new Firebase('https://hacker-news.firebaseio.com/v0') | |
| var topStoryIds = [] | |
| function loadTopStories(callback) { | |
| api.child('topstories').on('value', snapshot => { | |
| topStoryIds = snapshot.val(); | |
| callback(print_stories); | |
| }) | |
| } | |
| function print(callback) { | |
| for(var i = 0; i < topStoryIds.length; i++){ | |
| api.child('item/' + topStoryIds[i]).once('value', snapshot => { | |
| callback(snapshot.val()); | |
| }) | |
| } | |
| } | |
| function print_stories(data) { | |
| var transform = {"tag":"div","children":[{"tag":"a","href":"${url}","html":"${title}"}]}; | |
| console.log(json2html.transform(data,transform) ); | |
| //console.log(story.title.toString()); | |
| } | |
| function transformJson(data, html) { | |
| //LivingSocial Is Laying Off More Than 50 Percent of Its Staff (recode.net) | |
| //31 points by danso 37 minutes ago | 12 comments | |
| var transform = {"tag":"div","children":[{"tag":"a","href":"${url}","html":"${title}"}]}; | |
| // const docProvider = { | |
| // provideTextDocumentContent: () => json2html.transform(data,transform) | |
| // }; | |
| // console.log(json2html.transform(data,transform) ); | |
| vscode.workspace.registerTextDocumentContentProvider('hackernews', docProvider); | |
| vscode.commands.executeCommand("vscode.previewHtml", | |
| vscode.Uri.parse("hackernews://base"), vscode.ViewColumn.One) | |
| .then(() => 1, error => console.log(error)); | |
| html = json2html.transform(data, transform); | |
| console.log("--------------------------------------------------"); | |
| console.log(html); | |
| return html; | |
| } | |
| loadTopStories(print); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment