Skip to content
This repository has been archived by the owner on Sep 7, 2020. It is now read-only.

Commit

Permalink
@phenomic/core: Fix static rendering for collection items (when no by…
Browse files Browse the repository at this point in the history
… param is used)

Regression introduced in c68633a

packages: @phenomic/core
tag: fix

Closes #1114
  • Loading branch information
MoOx committed Aug 4, 2017
1 parent dfbed0a commit a66ac13
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions packages/core/src/prerender/resolve.js
Expand Up @@ -2,6 +2,9 @@ import createQuery from "@phenomic/api-client/lib/query";

const debug = require("debug")("phenomic:core:prerender:resolve");

const defaultQueryKey = "default";
const mainKey = "key";

const arrayUnique = array => [...new Set(array)];

const getRouteQueries = route => {
Expand Down Expand Up @@ -62,12 +65,18 @@ const resolveURLsForDynamicParams = async function(
// @todo memoize for perfs and avoid uncessary call
const query = getRouteQueries(route);
debug(route.path, query);
const key =
let key =
(query[collectionConfig.collection] &&
query[collectionConfig.collection].by) ||
"key";
mainKey;
if (key === defaultQueryKey) {
key = mainKey;
}
const collection = await phenomicFetch(createQuery(collectionConfig));
debug(route.path, `collection fetched. ${collection.list.length} items`);
debug(
route.path,
`collection fetched. ${collection.list.length} items (key: ${key})`
);
const path = route.path || "*";
const list = collection.list.reduce((acc, item) => {
if (!item[key]) {
Expand All @@ -85,7 +94,7 @@ const resolveURLsForDynamicParams = async function(
let resolvedPath = path.replace(":" + key, value);
let params = { [key]: value };
// try *
if (key === "key" && resolvedPath === path) {
if (key === mainKey && resolvedPath === path) {
resolvedPath = resolvedPath.replace("*", value);
params = { splat: value };
}
Expand Down

0 comments on commit a66ac13

Please sign in to comment.