Gist files support
-
I am a contributor to this blog.
My posts usually include code samples, which I write in Github as Gists.
Such gists usually contain multiple files (one gist per post and one file inside the gist for each snippet).I am aware og the gist support, but such support does not include include just a single file of the Gist. There are 3rd party plugins, which of course I cannot use in our hosted solution.
Could multi-file gists be supported?
Thanks
The blog I need help with is: (visible only to logged in users)
-
Can you share a link to one of your gists with multiple files, and explain how you’d like to use it in your posts? That will help me understand what you’re looking for so I can see if we can add support for that here at WordPress.com.
-
Sure, thing.
This is the gist that contains multiple files: https://gist.github.com/dgg/9ae1b698c42043bac0f6
If the blog supported script tags, I would include a single file of the gist doing:
<script src="https://gist.github.com/dgg/9ae1b698c42043bac0f6.js?file=mirror.js"></script>,for another file in the gist I’d do<script src="https://gist.github.com/dgg/9ae1b698c42043bac0f6.js?file=config.js"></script>.I’d like to achieve kind of what this plugin says it does: https://wordpress.org/plugins/embed-github-gist/
[gist id=546764 file=file.txt]does that make sense?
-
Thanks for that example — I see what you mean now. I passed along those details to our team so they can consider adding support for multiple files like that at WordPress.com. :)
-
-
I’ve come here to make the same request, I’m glad I’m not alone. I agree with Daniel, but I think it would be good to keep the shortcodes compatible with the current style by emulating the URLs that gist.github.com produces.
Currently, we can paste the URL of a single file gist, such as:
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
/** * Calculate the driving distance (in meters) along a route. * * @param {"london","manchester","liverpool"} route * Comma separated ordered list of two or more map * waypoints to include in route. First point * is 'origin', last is 'destination'. * * @customfunction */ function drivingDistance(route) { // From gist.github.com/mogsdad/e07d537ff06f444866c5 // Adapted from developers.google.com/apps-script/quickstart/macros // If a range of cells is passed in, 'route' will be a two-dimensional array. // Test for an array, and if we have one, collapse it to a single array. if (route.constructor === Array) { var args = []; for (var row=0; row<route.length; row++) { for (var col=0; col<route[row].length; col++) { // Skip blanks if (route[row][col]) args.push(route[row][col]); } } } else { // No array? Grab the arbitrary arguments passed to the function. args = arguments; } args = args.clean(""); // remove blanks // Just one rule to a route - we need a beginning and an end if (args.length < 2) throw new Error( "Must have at least 2 waypoints." ) // Pass our waypoints to getDirections_(). Tricky bit, this. var directions = getDirections_.apply(this, args); // We have our directions, grab the first route's legs var legs = directions.routes[0].legs; // Loop through all legs, and sum up distances var dist = 0; for (var i=0; i<legs.length; i++) { dist += legs[i].distance.value; } // Done - return the value in meters return dist; } /** * Use Maps service to get directions for a route consisting of an arbitrary * set of waypoints. */ function getDirections_(route) { // From gist.github.com/mogsdad/e07d537ff06f444866c5 // Just one rule to a route - we need a beginning and an end if (arguments.length < 2) throw new Error( "Must have at least 2 waypoints." ) // Assume first point is origin, last is destination. var origin = arguments[0]; var destination = arguments[arguments.length-1]; // Build our route; origin + all midpoints + destination var directionFinder = Maps.newDirectionFinder(); directionFinder.setOrigin(origin); for ( var i=1; i<arguments.length-1; i++ ) { directionFinder.addWaypoint(arguments[i]); } directionFinder.setDestination(destination); // Get our directions from Map service; // throw an error if no route can be calculated. var directions = directionFinder.getDirections(); if (directions.routes.length == 0) { throw 'Unable to calculate directions between these addresses.'; } return directions; } // From stackoverflow.com/a/281335/1677912 Array.prototype.clean = function(deleteValue) { for (var i = 0; i < this.length; i++) { if (this[i] == deleteValue) { this.splice(i, 1); i--; } } return this; }; … which gets automatically shortcoded to:
[gist:e07d537ff06f444866c5]
No change there, for single-file gists. (What to do if a multi-file gist is reference this way? Currently, nothing is displayed. The gist convention is to show the first file, in alphabetical order. You can try the gists in this comment, they’re real.)
It would be convenient if we could similarly paste the URL of one of the files in a multi-file gist, which looks like:
https://gist.github.com/mogsdad/7977853f69fd7cdc8fa0#file-csvutils-gs
… or in shortcode:
[gist:7977853f69fd7cdc8fa0#file-csvutils-gs]
This single feature has me investigating a hosted wp, or self-hosting just to get to use a third-party plugin. I would rather spend my time creating content, so the fact that you’re looking into this is awesome!
-
Oops, got the shortcodes wrong in previous post. Should have been:
[gist]e07d537ff06f444866c5[/gist]
and
[gist]7977853f69fd7cdc8fa0#file-csvutils-gs[/gist]
respectively.
- The topic ‘Gist files support’ is closed to new replies.