Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

CSS file links now parsed directly from Github

  • Loading branch information...
commit e4feaedbae55601c4f885640b8605b9c9dc87e44 1 parent 8a82325
@youurayy authored
Showing with 42 additions and 19 deletions.
  1. +1 −1  README.md
  2. +26 −7 gfms.js
  3. +11 −10 package.json
  4. +4 −1 views/layout.jade
View
2  README.md
@@ -23,7 +23,7 @@ And none would show the result looking (almost) exactly like at Github.
Well, the current implementation of GFMS doesn't color the source code blocks, but it at least renders them correctly. I had to modify the `showdown.js` from `github-flavored-markdown`. I made a copy of that file, and fork & pull-request to the original project is on my `TODO` list. GFMS has `github-flavored-markdown` as a dependency despite it's not needed, so that the heritage is obvious in NPM.
-Another possible shortcoming is that the [Github CSS](http://a248.e.akamai.net/assets.github.com/stylesheets/bundles/github-34a19ad407ee058e180249a0f19030a3731ed4d8.css) file is loaded from Akamai, and when its name changes, this tool will need to be updated.
+Another possible shortcoming is that the URLs of the Github CSS files are scraped from www.github.com directly, introducing some fragility inherent to the nature of scraping.
## Usage
View
33 gfms.js
@@ -17,12 +17,14 @@ var markdown = //require('github-flavored-markdown').parse;
require('./showdown.js').parse;
var _ = require('underscore');
var fs = require('fs');
+var request = require('request');
var laeh = require('laeh2').leanStacks(true);
var _e = laeh._e;
var _x = laeh._x;
var watched = {};
+var styles = [];
app.configure(function() {
@@ -97,6 +99,7 @@ app.get('*', function(req, res, next) {
res.render('directory', {
files: files,
dir: dir,
+ styles: styles,
title: basename(dir)
});
}
@@ -115,6 +118,7 @@ app.get('*', function(req, res, next) {
res.render('file', {
file: markdown(fs.readFileSync(dir, 'utf8')),
title: basename(dir),
+ styles: styles,
fullname: dir
});
}
@@ -122,13 +126,28 @@ app.get('*', function(req, res, next) {
return next();
});
-app.listen(argv.p, argv.h);
-io = sio.listen(app);
-io.set('log level', 1);
-
-console.log('GFMS serving ' + process.cwd() + ' at http://' + argv.h + ':' + argv.p + '/ - press CTRL+C to exit.');
-
process.on('SIGINT', function() {
console.log('\nGFMS exit.');
return process.exit();
-});
+});
+
+console.log('Getting .css links from Github...');
+
+request('http://www.github.com', function(err, res, body) {
+
+ if(err || res.statusCode != 200)
+ throw 'Cannot load .css links from Github';
+
+ var m, re = /<link href="(.+?)" media="screen" rel="stylesheet" type="text\/css" \/>/g;
+ while(m = re.exec(body))
+ styles.push(m[1]);
+
+ if(!styles.length)
+ throw 'Cannot parse .css links from Github';
+
+ app.listen(argv.p, argv.h);
+ io = sio.listen(app);
+ io.set('log level', 1);
+
+ console.log('GFMS serving ' + process.cwd() + ' at http://' + argv.h + ':' + argv.p + '/ - press CTRL+C to exit.');
+});
View
21 package.json
@@ -20,16 +20,17 @@
"node": ">= 0.6.0"
},
"dependencies": {
- "laeh2": "0.2.0",
- "express": "2.5.6",
- "optimist": "0.2.x",
- "github-flavored-markdown": "1.0.0",
- "utilz": "0.1.3",
- "jade": "0.20.0",
- "stylus": "0.22.6",
- "nib": "0.3.2",
- "underscore": "1.3.1",
- "socket.io": "0.8.7"
+ "express": "*",
+ "github-flavored-markdown": "*",
+ "jade": "*",
+ "laeh2": "*",
+ "nib": "*",
+ "optimist": "*",
+ "request": "*",
+ "socket.io": "*",
+ "stylus": "*",
+ "underscore": "*",
+ "utilz": "*"
},
"devDependencies": {
}
View
5 views/layout.jade
@@ -3,7 +3,10 @@ html
head
title #{title} - Github Flavored Markdown Server
//link(rel='stylesheet', href='/github.css')
- link(rel='stylesheet', href='http://a248.e.akamai.net/assets.github.com/stylesheets/bundles/github-34a19ad407ee058e180249a0f19030a3731ed4d8.css')
+ each style in styles
+ link(rel='stylesheet', href=style)
+ //link(rel='stylesheet', href='https://a248.e.akamai.net/assets.github.com/stylesheets/bundles/github-e99d6cd1ba845aee419becbfcd08b713f4bf0a55.css')
+ //link(rel='stylesheet', href='https://a248.e.akamai.net/assets.github.com/stylesheets/bundles/github2-295a02b2f2bdc835d7af368e96a0579808719484.css')
link(rel='stylesheet', href='/style.css')
script(src='http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js')
script(src='/socket.io/socket.io.js')
Please sign in to comment.
Something went wrong with that request. Please try again.