Fix slugs for search result entries
This commit is contained in:
parent
a33aa13d0f
commit
442a02f009
@ -1,5 +1,6 @@
|
||||
import { createEntry } from '../../../valueObjects/Entry';
|
||||
import _ from 'lodash';
|
||||
import Collection from '../../../valueObjects/Collection';
|
||||
|
||||
function getSlug(path) {
|
||||
const m = path.match(/([^\/]+?)(\.[^\/\.]+)?$/);
|
||||
@ -101,11 +102,12 @@ export default class Algolia {
|
||||
if (this.entriesCache.collection === collection && this.entriesCache.page === page) {
|
||||
return Promise.resolve({ page: this.entriesCache.page, entries: this.entriesCache.entries });
|
||||
} else {
|
||||
const collectionModel = new Collection(collection);
|
||||
return this.request(`${ this.searchURL }/indexes/${ collection.get('name') }`, {
|
||||
params: { page },
|
||||
}).then((response) => {
|
||||
const entries = response.hits.map((hit) => {
|
||||
const slug = hit.slug || getSlug(hit.path);
|
||||
const slug = collectionModel.entrySlug(hit.path);
|
||||
return createEntry(collection.get('name'), slug, hit.path, { data: hit.data, partial: true });
|
||||
});
|
||||
this.entriesCache = { collection, pagination: response.page, entries };
|
||||
|
Loading…
x
Reference in New Issue
Block a user