mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-01-08 20:22:53 +03:00
🛠 🙈 Rename ghost-url.js to ghost-sdk.js (#8767)
closes #8605 - This file has already been moved, might as well get the rename out of the way - Especially as we don't migrate clients - everyone will now need to make just one change
This commit is contained in:
parent
f6a9e8694e
commit
301696632f
2
.gitignore
vendored
2
.gitignore
vendored
@ -68,7 +68,7 @@ config.*.json
|
||||
# Built asset files
|
||||
/core/built
|
||||
/core/server/admin/views/*
|
||||
/core/server/public/ghost-url.min.js
|
||||
/core/server/public/ghost-sdk.min.js
|
||||
/core/server/public/ghost.min.css
|
||||
|
||||
# Coverage reports
|
||||
|
@ -321,7 +321,7 @@ var overrides = require('./core/server/overrides'),
|
||||
sourceMap: false
|
||||
},
|
||||
files: {
|
||||
'core/server/public/ghost-url.min.js': 'core/server/public/ghost-url.js'
|
||||
'core/server/public/ghost-sdk.min.js': 'core/server/public/ghost-sdk.js'
|
||||
}
|
||||
}
|
||||
},
|
||||
|
@ -43,9 +43,9 @@ module.exports = function setupBlogApp() {
|
||||
// @TODO make sure all of these have a local 404 error handler
|
||||
// Favicon
|
||||
blogApp.use(serveFavicon());
|
||||
// Ghost-Url
|
||||
blogApp.use(servePublicFile('public/ghost-url.js', 'application/javascript', utils.ONE_HOUR_S));
|
||||
blogApp.use(servePublicFile('public/ghost-url.min.js', 'application/javascript', utils.ONE_HOUR_S));
|
||||
// /public/ghost-sdk.js
|
||||
blogApp.use(servePublicFile('public/ghost-sdk.js', 'application/javascript', utils.ONE_HOUR_S));
|
||||
blogApp.use(servePublicFile('public/ghost-sdk.min.js', 'application/javascript', utils.ONE_HOUR_S));
|
||||
// Serve sitemap.xsl file
|
||||
blogApp.use(servePublicFile('sitemap.xsl', 'text/xsl', utils.ONE_DAY_S));
|
||||
|
||||
|
@ -68,7 +68,7 @@ function finaliseStructuredData(metaData) {
|
||||
|
||||
function getAjaxHelper(clientId, clientSecret) {
|
||||
return '<script type="text/javascript" src="' +
|
||||
getAssetUrl('public/ghost-url.js', true) +
|
||||
getAssetUrl('public/ghost-sdk.js', true) +
|
||||
'"></script>\n' +
|
||||
'<script type="text/javascript">\n' +
|
||||
'ghost.init({\n' +
|
||||
|
1
core/server/public/ghost-sdk.min.js
vendored
Normal file
1
core/server/public/ghost-sdk.min.js
vendored
Normal file
@ -0,0 +1 @@
|
||||
!function(){"use strict";function a(a){var b,c=[];if(!a)return"";for(b in a)a.hasOwnProperty(b)&&(a[b]||a[b]===!1)&&c.push(b+"="+encodeURIComponent(a[b]));return c.length?"?"+c.join("&"):""}var b,c,d,e,f="{{api-url}}";d={api:function(){var d,e=Array.prototype.slice.call(arguments),g=f;return d=e.pop(),d&&"object"!=typeof d&&(e.push(d),d={}),d=d||{},d.client_id=b,d.client_secret=c,e.length&&e.forEach(function(a){g+=a.replace(/^\/|\/$/g,"")+"/"}),g+a(d)}},e=function(a){b=a.clientId?a.clientId:"",c=a.clientSecret?a.clientSecret:"",f=a.url?a.url:f.match(/{\{api-url}}/)?"":f},"undefined"!=typeof window&&(window.ghost=window.ghost||{},window.ghost.url=d,window.ghost.init=e),"undefined"!=typeof module&&(module.exports={url:d,init:e})}();
|
@ -1,9 +1,8 @@
|
||||
var should = require('should'), // jshint ignore:line
|
||||
ghostUrl = require('../../server/public/ghost-url'),
|
||||
ghostSdk = require('../../server/public/ghost-sdk'),
|
||||
configUtils = require('../utils/configUtils'),
|
||||
utils = require('../../server/utils');
|
||||
|
||||
// @TODO: ghostUrl.init was obviously written for this test, get rid of it! (write a route test instead)
|
||||
describe('Ghost Ajax Helper', function () {
|
||||
beforeEach(function () {
|
||||
configUtils.set({
|
||||
@ -16,52 +15,52 @@ describe('Ghost Ajax Helper', function () {
|
||||
});
|
||||
|
||||
it('sets url empty if it is not set on init', function () {
|
||||
ghostUrl.init({
|
||||
ghostSdk.init({
|
||||
clientId: '',
|
||||
clientSecret: ''
|
||||
});
|
||||
|
||||
ghostUrl.url.api().should.equal('');
|
||||
ghostSdk.url.api().should.equal('');
|
||||
});
|
||||
|
||||
it('renders basic url correctly when no arguments are presented', function () {
|
||||
ghostUrl.init({
|
||||
ghostSdk.init({
|
||||
clientId: '',
|
||||
clientSecret: '',
|
||||
url: utils.url.urlFor('api', {cors: true}, true)
|
||||
});
|
||||
|
||||
ghostUrl.url.api().should.equal('//testblog.com/ghost/api/v0.1/');
|
||||
ghostSdk.url.api().should.equal('//testblog.com/ghost/api/v0.1/');
|
||||
});
|
||||
|
||||
it('strips arguments of forward and trailing slashes correctly', function () {
|
||||
ghostUrl.init({
|
||||
ghostSdk.init({
|
||||
clientId: '',
|
||||
clientSecret: '',
|
||||
url: utils.url.urlFor('api', {cors: true}, true)
|
||||
});
|
||||
|
||||
ghostUrl.url.api('a/', '/b', '/c/').should.equal('//testblog.com/ghost/api/v0.1/a/b/c/');
|
||||
ghostSdk.url.api('a/', '/b', '/c/').should.equal('//testblog.com/ghost/api/v0.1/a/b/c/');
|
||||
});
|
||||
|
||||
it('appends client_id & client_secret to query string automatically', function () {
|
||||
ghostUrl.init({
|
||||
ghostSdk.init({
|
||||
clientId: 'ghost-frontend',
|
||||
clientSecret: 'notasecret',
|
||||
url: utils.url.urlFor('api', {cors: true}, true)
|
||||
});
|
||||
|
||||
ghostUrl.url.api().should.equal('//testblog.com/ghost/api/v0.1/?client_id=ghost-frontend&client_secret=notasecret');
|
||||
ghostSdk.url.api().should.equal('//testblog.com/ghost/api/v0.1/?client_id=ghost-frontend&client_secret=notasecret');
|
||||
});
|
||||
|
||||
it('generates query parameters correctly', function () {
|
||||
ghostUrl.init({
|
||||
ghostSdk.init({
|
||||
clientId: 'ghost-frontend',
|
||||
clientSecret: 'notasecret',
|
||||
url: utils.url.urlFor('api', {cors: true}, true)
|
||||
});
|
||||
|
||||
var rendered = ghostUrl.url.api({a: 'string', b: 5, c: 'en coded'});
|
||||
var rendered = ghostSdk.url.api({a: 'string', b: 5, c: 'en coded'});
|
||||
|
||||
rendered.should.match(/\/\/testblog\.com\/ghost\/api\/v0\.1\/\?/);
|
||||
rendered.should.match(/client_id=ghost-frontend/);
|
||||
@ -72,7 +71,7 @@ describe('Ghost Ajax Helper', function () {
|
||||
});
|
||||
|
||||
it('handles null/undefined queryOptions correctly', function () {
|
||||
ghostUrl.init({
|
||||
ghostSdk.init({
|
||||
clientId: 'ghost-frontend',
|
||||
clientSecret: 'notasecret',
|
||||
url: 'test'
|
||||
@ -81,8 +80,8 @@ describe('Ghost Ajax Helper', function () {
|
||||
var test = {
|
||||
a: null
|
||||
},
|
||||
rendered = ghostUrl.url.api(test.a), // null value
|
||||
rendered2 = ghostUrl.url.api(test.b); // undefined value
|
||||
rendered = ghostSdk.url.api(test.a), // null value
|
||||
rendered2 = ghostSdk.url.api(test.b); // undefined value
|
||||
|
||||
rendered.should.match(/test/);
|
||||
rendered.should.match(/client_id=ghost-frontend/);
|
||||
@ -93,13 +92,13 @@ describe('Ghost Ajax Helper', function () {
|
||||
});
|
||||
|
||||
it('generates complex query correctly', function () {
|
||||
ghostUrl.init({
|
||||
ghostSdk.init({
|
||||
clientId: 'ghost-frontend',
|
||||
clientSecret: 'notasecret',
|
||||
url: utils.url.urlFor('api', {cors: true}, true)
|
||||
});
|
||||
|
||||
var rendered = ghostUrl.url.api('posts/', '/tags/', '/count', {include: 'tags,tests', page: 2});
|
||||
var rendered = ghostSdk.url.api('posts/', '/tags/', '/count', {include: 'tags,tests', page: 2});
|
||||
|
||||
rendered.should.match(/\/\/testblog\.com\/ghost\/api\/v0\.1\/posts\/tags\/count\/\?/);
|
||||
rendered.should.match(/client_id=ghost-frontend/);
|
||||
@ -113,13 +112,13 @@ describe('Ghost Ajax Helper', function () {
|
||||
url: 'https://testblog.com/'
|
||||
});
|
||||
|
||||
ghostUrl.init({
|
||||
ghostSdk.init({
|
||||
clientId: 'ghost-frontend',
|
||||
clientSecret: 'notasecret',
|
||||
url: utils.url.urlFor('api', true)
|
||||
});
|
||||
|
||||
var rendered = ghostUrl.url.api('posts/', '/tags/', '/count', {include: 'tags,tests', page: 2});
|
||||
var rendered = ghostSdk.url.api('posts/', '/tags/', '/count', {include: 'tags,tests', page: 2});
|
||||
|
||||
rendered.should.match(/https:\/\/testblog\.com\/ghost\/api\/v0\.1\/posts\/tags\/count\/\?/);
|
||||
rendered.should.match(/client_id=ghost-frontend/);
|
||||
@ -132,13 +131,13 @@ describe('Ghost Ajax Helper', function () {
|
||||
configUtils.set({
|
||||
url: 'https://testblog.com/blog/'
|
||||
});
|
||||
ghostUrl.init({
|
||||
ghostSdk.init({
|
||||
clientId: 'ghost-frontend',
|
||||
clientSecret: 'notasecret',
|
||||
url: utils.url.urlFor('api', true)
|
||||
});
|
||||
|
||||
var rendered = ghostUrl.url.api('posts/', '/tags/', '/count', {include: 'tags,tests', page: 2});
|
||||
var rendered = ghostSdk.url.api('posts/', '/tags/', '/count', {include: 'tags,tests', page: 2});
|
||||
|
||||
rendered.should.match(/https:\/\/testblog\.com\/blog\/ghost\/api\/v0\.1\/posts\/tags\/count\/\?/);
|
||||
rendered.should.match(/client_id=ghost-frontend/);
|
||||
@ -152,14 +151,14 @@ describe('Ghost Ajax Helper', function () {
|
||||
url: 'https://testblog.com/blog/'
|
||||
});
|
||||
|
||||
ghostUrl.init({
|
||||
ghostSdk.init({
|
||||
clientId: 'ghost-frontend',
|
||||
clientSecret: 'notasecret',
|
||||
url: utils.url.urlFor('api', {cors: true}, true)
|
||||
});
|
||||
|
||||
var rendered = ghostUrl.url.api('posts', {limit: 3}),
|
||||
rendered2 = ghostUrl.url.api('posts', {limit: 3});
|
||||
var rendered = ghostSdk.url.api('posts', {limit: 3}),
|
||||
rendered2 = ghostSdk.url.api('posts', {limit: 3});
|
||||
|
||||
rendered.should.equal(rendered2);
|
||||
});
|
@ -1096,7 +1096,7 @@ describe('{{ghost_head}} helper', function () {
|
||||
{data: {root: {context: []}}}
|
||||
).then(function (rendered) {
|
||||
should.exist(rendered);
|
||||
rendered.string.should.match(/<script type="text\/javascript" src="\/public\/ghost-url\.js\?v=/);
|
||||
rendered.string.should.match(/<script type="text\/javascript" src="\/public\/ghost-sdk\.js\?v=/);
|
||||
|
||||
done();
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user