Uniform slug generation
This commit is contained in:
parent
c20896d073
commit
f6a1718085
@ -3,8 +3,7 @@ import { createEntry } from '../../../valueObjects/Entry';
|
|||||||
import { selectEntrySlug } from '../../../reducers/collections';
|
import { selectEntrySlug } from '../../../reducers/collections';
|
||||||
|
|
||||||
function getSlug(path) {
|
function getSlug(path) {
|
||||||
const m = path.match(/([^\/]+?)(\.[^\/\.]+)?$/);
|
return path.split('/').pop().replace(/\.[^\.]+$/, '');
|
||||||
return m && m[1];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export default class Algolia {
|
export default class Algolia {
|
||||||
@ -85,7 +84,7 @@ export default class Algolia {
|
|||||||
body: JSON.stringify({ requests: searchCollections }),
|
body: JSON.stringify({ requests: searchCollections }),
|
||||||
}).then((response) => {
|
}).then((response) => {
|
||||||
const entries = response.results.map((result, index) => result.hits.map((hit) => {
|
const entries = response.results.map((result, index) => result.hits.map((hit) => {
|
||||||
const slug = hit.slug || getSlug(hit.path);
|
const slug = getSlug(hit.path);
|
||||||
return createEntry(collections[index], slug, hit.path, { data: hit.data, partial: true });
|
return createEntry(collections[index], slug, hit.path, { data: hit.data, partial: true });
|
||||||
}));
|
}));
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user