mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-11-24 06:35:49 +03:00
Fixed internal linking not correctly filtering to published-only (#20054)
no issue - updated search to add `status` to the search results - added filtering to the editor's `searchLinks()` method - prevented TaskCancellation errors being thrown from the search task being cast to a Promise
This commit is contained in:
parent
a10b13916a
commit
7132619115
@ -4,9 +4,9 @@ import React, {Suspense} from 'react';
|
||||
import fetch from 'fetch';
|
||||
import ghostPaths from 'ghost-admin/utils/ghost-paths';
|
||||
import {action} from '@ember/object';
|
||||
import {didCancel, task} from 'ember-concurrency';
|
||||
import {inject} from 'ghost-admin/decorators/inject';
|
||||
import {inject as service} from '@ember/service';
|
||||
import {task} from 'ember-concurrency';
|
||||
|
||||
export const fileTypes = {
|
||||
image: {
|
||||
@ -311,14 +311,23 @@ export default class KoenigLexicalEditor extends Component {
|
||||
return this.defaultLinks;
|
||||
}
|
||||
|
||||
const results = await this.search.searchTask.perform(term);
|
||||
let results = [];
|
||||
|
||||
try {
|
||||
results = await this.search.searchTask.perform(term);
|
||||
} catch (error) {
|
||||
// don't surface task cancellation errors
|
||||
if (!didCancel(error)) {
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: Add grouped results support to Koenig
|
||||
const flattenedResults = [];
|
||||
results.forEach(group => flattenedResults.push(...group.options));
|
||||
|
||||
// only published posts/pages have URLs
|
||||
const filteredResults = flattenedResults.filter(result => result.groupName === 'Posts');
|
||||
const filteredResults = flattenedResults.filter(result => (result.groupName === 'Posts' || result.groupName === 'Pages') && result.status === 'published');
|
||||
return filteredResults;
|
||||
};
|
||||
|
||||
|
@ -18,14 +18,14 @@ export default class SearchService extends Service {
|
||||
{
|
||||
name: 'Posts',
|
||||
model: 'post',
|
||||
fields: ['id', 'url', 'title'],
|
||||
fields: ['id', 'url', 'title', 'status'],
|
||||
idField: 'id',
|
||||
titleField: 'title'
|
||||
},
|
||||
{
|
||||
name: 'Pages',
|
||||
model: 'page',
|
||||
fields: ['id', 'url', 'title'],
|
||||
fields: ['id', 'url', 'title', 'status'],
|
||||
idField: 'id',
|
||||
titleField: 'title'
|
||||
},
|
||||
@ -127,7 +127,8 @@ export default class SearchService extends Service {
|
||||
id: `${searchable.model}.${item[searchable.idField]}`,
|
||||
url: item.url,
|
||||
title: item[searchable.titleField],
|
||||
groupName: searchable.name
|
||||
groupName: searchable.name,
|
||||
status: item.status
|
||||
})
|
||||
);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user