@takeshape/ssg 11.124.6 → 11.125.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/generate/generate.js +28 -12
- package/dist/types.d.ts +4 -0
- package/package.json +5 -5
|
@@ -4,7 +4,7 @@ import BbPromise from 'bluebird';
|
|
|
4
4
|
import compose from 'lodash/fp/compose.js';
|
|
5
5
|
import flatten from 'lodash/fp/flatten.js';
|
|
6
6
|
import partition from 'lodash/partition.js';
|
|
7
|
-
import
|
|
7
|
+
import uniqBy from 'lodash/uniqBy.js';
|
|
8
8
|
import { obj as Pumpify } from 'pumpify';
|
|
9
9
|
import compressHtml from "../compress-html.js";
|
|
10
10
|
import { localizeConfig } from "../config.js";
|
|
@@ -122,22 +122,31 @@ function renderTemplates(generateContext) {
|
|
|
122
122
|
const routeContext = await resolveRouteContext(generateContext, route);
|
|
123
123
|
const context = combineContext(config.env, globalContext, route, routeContext);
|
|
124
124
|
const path = joinPath(pathPrefix, route.path);
|
|
125
|
-
|
|
125
|
+
const page = await renderTemplate(path, route.template, context);
|
|
126
|
+
return {
|
|
127
|
+
pages: [page],
|
|
128
|
+
order: route._routeOrder
|
|
129
|
+
};
|
|
126
130
|
});
|
|
127
131
|
}
|
|
128
132
|
function renderPaginatedTemplates(generateContext) {
|
|
129
133
|
const render = renderPaginatedTemplate(generateContext, getPaginatedData);
|
|
130
134
|
return async (routes) => {
|
|
131
135
|
const { config, globalContext } = generateContext;
|
|
132
|
-
|
|
136
|
+
return BbPromise.map(routes, async (route) => {
|
|
133
137
|
const routeContext = await resolveRouteContext(generateContext, route);
|
|
134
|
-
|
|
138
|
+
const renderedPages = await render(route, combineContext(config.env, globalContext, route, routeContext));
|
|
139
|
+
return {
|
|
140
|
+
pages: renderedPages,
|
|
141
|
+
order: route._routeOrder
|
|
142
|
+
};
|
|
135
143
|
});
|
|
136
|
-
return flatten(pages);
|
|
137
144
|
};
|
|
138
145
|
}
|
|
139
146
|
async function generatePages(config, generateContext) {
|
|
140
|
-
const
|
|
147
|
+
const routeEntries = Object.entries(config.routes);
|
|
148
|
+
const routesWithOrder = routeEntries.map(([, route], index) => ({ ...route, _routeOrder: index }));
|
|
149
|
+
const [paginatedRouteConfigs, singleRouteConfigs] = partition(routesWithOrder, 'paginate');
|
|
141
150
|
const renderContext = {
|
|
142
151
|
...generateContext,
|
|
143
152
|
globalContext: {
|
|
@@ -153,9 +162,13 @@ async function generatePages(config, generateContext) {
|
|
|
153
162
|
locale: config.locale
|
|
154
163
|
}
|
|
155
164
|
};
|
|
156
|
-
const
|
|
157
|
-
const
|
|
158
|
-
|
|
165
|
+
const singleRoutes = await renderTemplates(renderContext)(singleRouteConfigs);
|
|
166
|
+
const paginatedRoutes = await renderPaginatedTemplates(renderContext)(paginatedRouteConfigs);
|
|
167
|
+
const allRoutes = singleRoutes.concat(paginatedRoutes);
|
|
168
|
+
const sortedRoutes = allRoutes.sort((a, b) => a.order - b.order);
|
|
169
|
+
const allPages = sortedRoutes.flatMap((route) => route.pages);
|
|
170
|
+
// First route wins
|
|
171
|
+
return uniqBy(allPages, 'path');
|
|
159
172
|
}
|
|
160
173
|
function removeListingPageConfig(routeConfig) {
|
|
161
174
|
if (routeConfig.paginate) {
|
|
@@ -212,9 +225,12 @@ export async function generateRoute(config, params) {
|
|
|
212
225
|
config,
|
|
213
226
|
globalContext
|
|
214
227
|
};
|
|
215
|
-
const
|
|
216
|
-
|
|
217
|
-
|
|
228
|
+
const routeWithOrder = { ...routeConfig, _routeOrder: 0 };
|
|
229
|
+
const routes = await (routeConfig.paginate
|
|
230
|
+
? renderPaginatedTemplates(renderContext)([{ ...removeListingPageConfig(routeConfig), _routeOrder: 0 }])
|
|
231
|
+
: renderTemplates(renderContext)([routeWithOrder]));
|
|
232
|
+
// Flatten routes to pages since there's only one route
|
|
233
|
+
const pages = routes.flatMap((route) => route.pages);
|
|
218
234
|
return {
|
|
219
235
|
pages,
|
|
220
236
|
stats
|
package/dist/types.d.ts
CHANGED
|
@@ -28,6 +28,10 @@ export type RenderedPage = {
|
|
|
28
28
|
path: string;
|
|
29
29
|
contents: string | Buffer;
|
|
30
30
|
};
|
|
31
|
+
export type RenderedRoute = {
|
|
32
|
+
pages: RenderedPage[];
|
|
33
|
+
order: number;
|
|
34
|
+
};
|
|
31
35
|
export type RenderTemplate = (path: string, template: string, context: TemplateContext) => Promise<RenderedPage>;
|
|
32
36
|
export type RenderTemplateDecorator = (renderTemplate: RenderTemplate) => RenderTemplate;
|
|
33
37
|
export type GraphQLConnectorParams = {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@takeshape/ssg",
|
|
3
|
-
"version": "11.
|
|
3
|
+
"version": "11.125.1",
|
|
4
4
|
"description": "Static Site Generator",
|
|
5
5
|
"homepage": "https://www.takeshape.io",
|
|
6
6
|
"repository": {
|
|
@@ -42,10 +42,10 @@
|
|
|
42
42
|
"pluralize": "8.0.0",
|
|
43
43
|
"pumpify": "2.0.1",
|
|
44
44
|
"resolve": "1.22.8",
|
|
45
|
-
"@takeshape/
|
|
46
|
-
"@takeshape/streams": "11.
|
|
47
|
-
"@takeshape/util": "11.
|
|
48
|
-
"@takeshape/
|
|
45
|
+
"@takeshape/prism": "11.125.1",
|
|
46
|
+
"@takeshape/streams": "11.125.1",
|
|
47
|
+
"@takeshape/util": "11.125.1",
|
|
48
|
+
"@takeshape/routing": "11.125.1"
|
|
49
49
|
},
|
|
50
50
|
"devDependencies": {
|
|
51
51
|
"@types/bluebird": "3.5.33",
|