0
Fork 0
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:
Rishabh 2022-07-07 11:09:53 +02:00
parent 44c8969192
commit d24ea3ce55
5 changed files with 18 additions and 18 deletions

View file

@ -9,7 +9,7 @@ export default class App extends React.Component {
super(props);
const searchIndex = new SearchIndex({
siteURL: props.siteURL,
adminUrl: props.adminUrl,
apiKey: props.apiKey
});
@ -98,7 +98,7 @@ export default class App extends React.Component {
<AppContext.Provider value={{
page: 'search',
showPopup: this.state.showPopup,
siteUrl: this.props.siteUrl,
adminUrl: this.props.adminUrl,
appVersion: this.props.appVersion,
searchIndex: this.state.searchIndex,
indexComplete: this.state.indexComplete,

View file

@ -4,7 +4,7 @@ import React from 'react';
test('renders Sodo Search app component', () => {
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 = document.querySelector('.gh-root-frame');
expect(containerElement).toBeInTheDocument();

View file

@ -17,26 +17,26 @@ function getSiteData() {
*/
const scriptTag = document.querySelector('script[data-sodo-search]');
if (scriptTag) {
const siteUrl = scriptTag.dataset.sodoSearch;
const adminUrl = scriptTag.dataset.sodoSearch;
const apiKey = scriptTag.dataset.key;
const appVersion = scriptTag.dataset.version;
return {siteUrl, apiKey, appVersion};
return {adminUrl, apiKey, appVersion};
}
return {};
}
function setup({siteUrl}) {
function setup() {
addRootDiv();
}
function init() {
const {siteUrl: customSiteUrl, apiKey, apiUrl, appVersion} = getSiteData();
const siteUrl = customSiteUrl || window.location.origin;
setup({siteUrl});
const {adminUrl, apiKey, appVersion} = getSiteData();
const adminBaseUrl = (adminUrl || window.location.origin)?.replace(/\/+$/, '');
setup();
ReactDOM.render(
<React.StrictMode>
<App
siteUrl={siteUrl} apiKey={apiKey} apiUrl={apiUrl}
adminUrl={adminBaseUrl} apiKey={apiKey}
appVersion={appVersion}
/>
</React.StrictMode>,

View file

@ -2,9 +2,9 @@ import elasticlunr from 'elasticlunr';
import GhostContentAPI from '@tryghost/content-api';
export default class SearchIndex {
constructor({siteURL, apiKey}) {
constructor({adminUrl, apiKey}) {
this.api = new GhostContentAPI({
url: siteURL,
url: adminUrl,
key: apiKey,
version: 'v5.0'
});

View file

@ -3,9 +3,9 @@ import nock from 'nock';
describe('search index', function () {
test('initializes search index', async () => {
const siteURL = 'http://localhost';
const adminUrl = 'http://localhost';
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')
.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: []
});
await searchIndex.init({siteURL, apiKey});
await searchIndex.init();
expect(scope.isDone()).toBeTruthy();
@ -33,9 +33,9 @@ describe('search index', function () {
});
test('allows to search for indexed posts and authors', async () => {
const siteURL = 'http://localhost';
const adminUrl = 'http://localhost';
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')
.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');
expect(searchResults.posts.length).toEqual(1);