stackgl / packages

:package: A list of packages that fall under the stack.gl umbrella
http://stack.gl/packages/
115 stars 11 forks source link

inline links should point to the original repo #7

Closed yoshuawuyts closed 9 years ago

yoshuawuyts commented 9 years ago

When a link inside the markdown points to /demo.js it will no longer work on the packages page. Instead the link should be overwritten compile-time to point to the original repo (github.com/my/repo/demo.js)

Example: http://stack.gl/packages/#stackgl/gl-particles

rreusser commented 9 years ago

I added this code to build.js in scijs/packages. Not sure what the best procedure is for getting this back upstream. Can create separate pull request with same code. :frowning:

    // Remove badges
    $('img[src*="://img.shields.io"]').remove()
    $('img[src*="://badges.github.io"]').remove()
    $('img[src*="://nodei.co"]').remove()
    $('img[src*="://david-dm.org"]').remove()
    $('img[src*="://badge.fury.io"]').remove()
    $('img[src*="://travis-ci.org"]').remove()
    $('img[src*="://secure.travis-ci.org"]').remove()
    $('h1 img').remove()

    $('a:not([href^=http]):not([href^=#])').each(function(i,el) {
      var $a = $(el)
      $a.attr( 'href', 'http://github.com/'+target.user+'/'+target.name+'/blob/master/'+$a.attr('href') )
    })  

    $('img:not([src^=http])').each(function(i,el) {
      var $img = $(el)
      $img.attr( 'src', 'https://raw.githubusercontent.com/' + target.user + '/' + target.name + '/master/' + $img.attr('src') )
    })  
yoshuawuyts commented 9 years ago

Ooh, I like the functionality. Thanks! If you could use document.querySelector() / document.querySelectorAll() instead of relying on jQuery we can probably merge this in. If you're uncomfortable using native dom functions I might take a stab at modifying your code and merging it in myself ^^.

rreusser commented 9 years ago

Ah, sorry, to clarify: This is in the build script so it's not jquery. The preceding line is:

var $ = cheerio.load(content)

Also for reference and to convince myself that it's really not more complicated than this, here's what npm uses:

https://github.com/npm/marky-markdown/blob/51cad7e2255f28e369cc5c4849b598bb8531ec7e/lib/github.js#L26

yoshuawuyts commented 9 years ago

Whoops, my bad. Yeah, it'd be wonderful if you'd submit a PR for this! 🌴

rreusser commented 9 years ago

stackgl is a bit more established than scijs so would like to test to make sure all links are valid, but looks like pygments is failing on one of the readmes (uses 'shell' code format which apparently isn't recognized; need to debug to figure out which repo) so a bit more work required before testing.

Also, would love to check links against the repo list and rewrite links to other github repos as anchor links within the docs, but first things first.

rreusser commented 9 years ago

And finally, would love to use ecosystem-docs to cache requests so I don't have to thrash github every time I test build.js…

FWIW: I have the bandwidth until new job starts on Monday to work on straightening some stuff out and cleaning some things up here, and it's the same code as scijs docs which I'm rather interested in, but not sure exactly where the community is going here. I get the sense things are progressing piece by piece but that everyone is strapped for time to work on some of this gruntwork, so if there's something useful I could do here, would love to pitch in.

hughsk commented 9 years ago

Fixed :)