Fix slugs for search result entries

This commit is contained in:
Mathias Biilmann Christensen 2016-10-27 19:56:50 +02:00
parent a33aa13d0f
commit 442a02f009

View File

@ -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 };