mirror of
https://github.com/jsbin/jsbin.git
synced 2026-02-01 16:46:05 +00:00
Add description to gist export
This commit is contained in:
parent
17002e4556
commit
9b413b8aad
@ -82,6 +82,20 @@ var Gist = (function () { // jshint ignore:line
|
||||
content: index
|
||||
};
|
||||
|
||||
var desc = [];
|
||||
|
||||
if (jsbin.state.title) {
|
||||
desc.push(jsbin.state.title);
|
||||
}
|
||||
|
||||
if (jsbin.state.description) {
|
||||
desc.push(jsbin.state.description);
|
||||
}
|
||||
|
||||
desc.push('// source ' + jsbin.getURL());
|
||||
|
||||
gist.description = desc.join('\n\n');
|
||||
|
||||
var token = '';
|
||||
if (jsbin.user && jsbin.user.github_token) { // jshint ignore:line
|
||||
token = '?access_token=' + jsbin.user.github_token; // jshint ignore:line
|
||||
|
||||
@ -84,6 +84,7 @@ var getPreparedCode = (function () {
|
||||
code: /%code%/,
|
||||
csscode: /%css%/,
|
||||
title: /<title>(.*)<\/title>/i,
|
||||
description: /<meta.*name=["']description['"].*?>/i,
|
||||
winLoad: /window\.onload\s*=/,
|
||||
scriptopen: /<script/gi
|
||||
};
|
||||
@ -131,7 +132,7 @@ var getPreparedCode = (function () {
|
||||
// 'console.' and then checks the position of the code. If it's inside
|
||||
// an openning script tag, it'll change it to window.top._console,
|
||||
// otherwise it'll leave it.
|
||||
js = js.replace(re.console, function (all, str, arg, pos) {
|
||||
js = js.replace(re.console, function (all, str, arg) {
|
||||
return replaceWith + arg;
|
||||
});
|
||||
}
|
||||
@ -213,10 +214,18 @@ var getPreparedCode = (function () {
|
||||
});
|
||||
}
|
||||
|
||||
var description = (html.match(re.description) || [''])[0];
|
||||
if (description) {
|
||||
var i = description.indexOf('content=') + 'content='.length;
|
||||
var quote = description.slice(i, i+1);
|
||||
jsbin.state.description = description.substr(i + 1).replace(new RegExp(quote + '.*$'), '');
|
||||
}
|
||||
|
||||
|
||||
// read the element out of the html code and plug it in to our document.title
|
||||
var newDocTitle = html.match(re.title);
|
||||
if (newDocTitle !== null && newDocTitle[1] !== documentTitle) {
|
||||
documentTitle = newDocTitle[1].trim();
|
||||
var newDocTitle = (html.match(re.title) || [,''])[1].trim();
|
||||
if (newDocTitle && newDocTitle !== documentTitle) {
|
||||
jsbin.state.title = documentTitle = newDocTitle;
|
||||
if (documentTitle) {
|
||||
document.title = documentTitle + ' - ' + 'JS Bin';
|
||||
} else {
|
||||
|
||||
2
public/js/vendor/bin-to-file.min.js
vendored
Normal file
2
public/js/vendor/bin-to-file.min.js
vendored
Normal file
@ -0,0 +1,2 @@
|
||||
/*! bin-to-file | v0.0.5 | (c) 2014 Remy Sharp | http://jsbin.mit-license.org */
|
||||
!function(a,b){"use strict";"function"==typeof define&&define.amd?define(b()):"object"==typeof exports?module.exports=b():a.binToFile=b()}(this,function(){"use strict";function a(a){var b=0,c=0,d=0;if(0===a.length)return b;for(;c<a.length;c++)d=a.charCodeAt(c),b=(b<<5)-b+d,b&=b;return b.toString(16)}function b(a,b,c){if(-1===a.toLowerCase().indexOf(b.toLowerCase()))return null;var d=a.substring(0,a.toLowerCase().lastIndexOf(b.toLowerCase())),e=a.substring(a.toLowerCase().lastIndexOf(b.toLowerCase())),f="";return d&&e&&(f=d+c+e),f}function c(a){return a.replace(/<\/script>/gi,"<\\/script>").replace(/<!--/g,"<\\!--")}var d=new RegExp(/^<!doctype[^>]*>\n?/im);return function(e,f){if(!e)return console.error("binToFile requires bin object",(new Error).stack),"<!DOCTYPE html>";f||(f={});var g=void 0!==f.proto?f.proto:"http:";g&&":"!==g.slice(-1)&&(g+=":");var h="",i=(e.html||"").replace(/(\r\n)/g,"\n"),j=e.source,k=c(e.css||""),l=c(e.javascript||""),m=e.processors||{},n=e.meta||(e.url?"<!-- source: http://jsbin.com/"+e.url+"/"+(e.revision||"")+" -->\n":"");if(i=i.replace(/(src|href)=('|")\/\//g,"$1=$2"+g+"//"),n&&"\n"!==n.slice(-1)&&(n+="\n"),h=i,k)if(-1!==h.indexOf("%css%"))h=h.split("%css%").join(e.css);else{k='<style id="jsbin-css">\n'+k+"\n</style>\n";var o=b(h,"</head>",k);if(o)h=o;else{var p=b(h,"</title>",k);h=p?p:k+h}}var q=(i.trim().split("\n").shift().trim().match(d)||[])[0]||"";if(h=q?h.replace(d,q+"\n"+n):n+h,l)if(-1!==h.indexOf("%code%"))h=h.split("%code%").join(l);else{l='<script id="jsbin-javascript">\n'+l+"\n</script>";var r=b(h,"</body>",l+"\n");h=r?r:h+"\n"+l}if(j){j.css===k&&delete j.css,j.javascript===l&&delete j.javascript,j.html===i&&delete j.html;var s=["html","css","javascript"].map(function(a){if(void 0===j[a])return"";var b=c(j[a]);return b?'\n<script id="jsbin-source-'+a+'" type="text/'+(m[a]||a)+'">'+b+"</script>":void 0}).join("\n"),t=b(h,"</body>",s);t?h=t:h+=s}var u=a(h);return h=h.split("^^hash^^").join(u)}});
|
||||
Loading…
x
Reference in New Issue
Block a user