mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-02-03 23:00:14 -05:00
Updated script url to use admin url
refs https://github.com/TryGhost/Team/issues/1665 - replaces usage of site url to admin url as script only needs admin url for setup - updates tests
This commit is contained in:
parent
44c8969192
commit
d24ea3ce55
5 changed files with 18 additions and 18 deletions
|
@ -9,7 +9,7 @@ export default class App extends React.Component {
|
||||||
super(props);
|
super(props);
|
||||||
|
|
||||||
const searchIndex = new SearchIndex({
|
const searchIndex = new SearchIndex({
|
||||||
siteURL: props.siteURL,
|
adminUrl: props.adminUrl,
|
||||||
apiKey: props.apiKey
|
apiKey: props.apiKey
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -98,7 +98,7 @@ export default class App extends React.Component {
|
||||||
<AppContext.Provider value={{
|
<AppContext.Provider value={{
|
||||||
page: 'search',
|
page: 'search',
|
||||||
showPopup: this.state.showPopup,
|
showPopup: this.state.showPopup,
|
||||||
siteUrl: this.props.siteUrl,
|
adminUrl: this.props.adminUrl,
|
||||||
appVersion: this.props.appVersion,
|
appVersion: this.props.appVersion,
|
||||||
searchIndex: this.state.searchIndex,
|
searchIndex: this.state.searchIndex,
|
||||||
indexComplete: this.state.indexComplete,
|
indexComplete: this.state.indexComplete,
|
||||||
|
|
|
@ -4,7 +4,7 @@ import React from 'react';
|
||||||
|
|
||||||
test('renders Sodo Search app component', () => {
|
test('renders Sodo Search app component', () => {
|
||||||
window.location.hash = '#/search';
|
window.location.hash = '#/search';
|
||||||
render(<App siteURL="http://localhost" apiKey="69010382388f9de5869ad6e558" />);
|
render(<App adminUrl="http://localhost" apiKey="69010382388f9de5869ad6e558" />);
|
||||||
// const containerElement = screen.getElementsByClassName('gh-portal-popup-container');
|
// const containerElement = screen.getElementsByClassName('gh-portal-popup-container');
|
||||||
const containerElement = document.querySelector('.gh-root-frame');
|
const containerElement = document.querySelector('.gh-root-frame');
|
||||||
expect(containerElement).toBeInTheDocument();
|
expect(containerElement).toBeInTheDocument();
|
||||||
|
|
|
@ -17,26 +17,26 @@ function getSiteData() {
|
||||||
*/
|
*/
|
||||||
const scriptTag = document.querySelector('script[data-sodo-search]');
|
const scriptTag = document.querySelector('script[data-sodo-search]');
|
||||||
if (scriptTag) {
|
if (scriptTag) {
|
||||||
const siteUrl = scriptTag.dataset.sodoSearch;
|
const adminUrl = scriptTag.dataset.sodoSearch;
|
||||||
const apiKey = scriptTag.dataset.key;
|
const apiKey = scriptTag.dataset.key;
|
||||||
const appVersion = scriptTag.dataset.version;
|
const appVersion = scriptTag.dataset.version;
|
||||||
return {siteUrl, apiKey, appVersion};
|
return {adminUrl, apiKey, appVersion};
|
||||||
}
|
}
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
function setup({siteUrl}) {
|
function setup() {
|
||||||
addRootDiv();
|
addRootDiv();
|
||||||
}
|
}
|
||||||
|
|
||||||
function init() {
|
function init() {
|
||||||
const {siteUrl: customSiteUrl, apiKey, apiUrl, appVersion} = getSiteData();
|
const {adminUrl, apiKey, appVersion} = getSiteData();
|
||||||
const siteUrl = customSiteUrl || window.location.origin;
|
const adminBaseUrl = (adminUrl || window.location.origin)?.replace(/\/+$/, '');
|
||||||
setup({siteUrl});
|
setup();
|
||||||
ReactDOM.render(
|
ReactDOM.render(
|
||||||
<React.StrictMode>
|
<React.StrictMode>
|
||||||
<App
|
<App
|
||||||
siteUrl={siteUrl} apiKey={apiKey} apiUrl={apiUrl}
|
adminUrl={adminBaseUrl} apiKey={apiKey}
|
||||||
appVersion={appVersion}
|
appVersion={appVersion}
|
||||||
/>
|
/>
|
||||||
</React.StrictMode>,
|
</React.StrictMode>,
|
||||||
|
|
|
@ -2,9 +2,9 @@ import elasticlunr from 'elasticlunr';
|
||||||
import GhostContentAPI from '@tryghost/content-api';
|
import GhostContentAPI from '@tryghost/content-api';
|
||||||
|
|
||||||
export default class SearchIndex {
|
export default class SearchIndex {
|
||||||
constructor({siteURL, apiKey}) {
|
constructor({adminUrl, apiKey}) {
|
||||||
this.api = new GhostContentAPI({
|
this.api = new GhostContentAPI({
|
||||||
url: siteURL,
|
url: adminUrl,
|
||||||
key: apiKey,
|
key: apiKey,
|
||||||
version: 'v5.0'
|
version: 'v5.0'
|
||||||
});
|
});
|
||||||
|
|
|
@ -3,9 +3,9 @@ import nock from 'nock';
|
||||||
|
|
||||||
describe('search index', function () {
|
describe('search index', function () {
|
||||||
test('initializes search index', async () => {
|
test('initializes search index', async () => {
|
||||||
const siteURL = 'http://localhost';
|
const adminUrl = 'http://localhost';
|
||||||
const apiKey = '69010382388f9de5869ad6e558';
|
const apiKey = '69010382388f9de5869ad6e558';
|
||||||
const searchIndex = new SearchIndex({siteURL, apiKey, storage: localStorage});
|
const searchIndex = new SearchIndex({adminUrl, apiKey, storage: localStorage});
|
||||||
|
|
||||||
const scope = nock('http://localhost/ghost/api/content')
|
const scope = nock('http://localhost/ghost/api/content')
|
||||||
.get('/posts/?key=69010382388f9de5869ad6e558&limit=all&fields=id%2Cslug%2Ctitle%2Cexcerpt%2Curl%2Cupdated_at%2Cvisibility&order=updated_at%20DESC&formats=plaintext')
|
.get('/posts/?key=69010382388f9de5869ad6e558&limit=all&fields=id%2Cslug%2Ctitle%2Cexcerpt%2Curl%2Cupdated_at%2Cvisibility&order=updated_at%20DESC&formats=plaintext')
|
||||||
|
@ -21,7 +21,7 @@ describe('search index', function () {
|
||||||
tags: []
|
tags: []
|
||||||
});
|
});
|
||||||
|
|
||||||
await searchIndex.init({siteURL, apiKey});
|
await searchIndex.init();
|
||||||
|
|
||||||
expect(scope.isDone()).toBeTruthy();
|
expect(scope.isDone()).toBeTruthy();
|
||||||
|
|
||||||
|
@ -33,9 +33,9 @@ describe('search index', function () {
|
||||||
});
|
});
|
||||||
|
|
||||||
test('allows to search for indexed posts and authors', async () => {
|
test('allows to search for indexed posts and authors', async () => {
|
||||||
const siteURL = 'http://localhost';
|
const adminUrl = 'http://localhost';
|
||||||
const apiKey = '69010382388f9de5869ad6e558';
|
const apiKey = '69010382388f9de5869ad6e558';
|
||||||
const searchIndex = new SearchIndex({siteURL, apiKey, storage: localStorage});
|
const searchIndex = new SearchIndex({adminUrl, apiKey, storage: localStorage});
|
||||||
|
|
||||||
nock('http://localhost/ghost/api/content')
|
nock('http://localhost/ghost/api/content')
|
||||||
.get('/posts/?key=69010382388f9de5869ad6e558&limit=all&fields=id%2Cslug%2Ctitle%2Cexcerpt%2Curl%2Cupdated_at%2Cvisibility&order=updated_at%20DESC&formats=plaintext')
|
.get('/posts/?key=69010382388f9de5869ad6e558&limit=all&fields=id%2Cslug%2Ctitle%2Cexcerpt%2Curl%2Cupdated_at%2Cvisibility&order=updated_at%20DESC&formats=plaintext')
|
||||||
|
@ -73,7 +73,7 @@ describe('search index', function () {
|
||||||
}]
|
}]
|
||||||
});
|
});
|
||||||
|
|
||||||
await searchIndex.init({siteURL, apiKey});
|
await searchIndex.init();
|
||||||
|
|
||||||
let searchResults = searchIndex.search('Barcelona');
|
let searchResults = searchIndex.search('Barcelona');
|
||||||
expect(searchResults.posts.length).toEqual(1);
|
expect(searchResults.posts.length).toEqual(1);
|
||||||
|
|
Loading…
Add table
Reference in a new issue