-
Notifications
You must be signed in to change notification settings - Fork 257
/
scully.sps-sample.config.ts
70 lines (65 loc) · 1.89 KB
/
scully.sps-sample.config.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
import { ScullyConfig, enableSPS, registerPlugin, HandledRoute, SPSRouteRenderer } from '@scullyio/scully';
import '@scullyio/scully-plugin-extra';
import '@scullyio/scully-plugin-from-data';
import { JSDOM } from 'jsdom';
import { cpus } from 'os';
const defaultPostRenderers: string[] = ['blah', 'blahAh', 'seoHrefOptimise'];
/**
* enables the Scully Platrom Server
* (disables puppeteer, and uses
* Angular Platform-server to
* render the pages )
*/
enableSPS();
export const config: ScullyConfig = {
projectName: 'sps-sample',
outDir: './dist/static/sps-sample',
defaultPostRenderers,
spsModulePath: './apps/sps-sample/src/app/app.sps.module.ts',
// maxRenderThreads: 4,
/** this seems the optimal for SPS */
maxRenderThreads: cpus().length * 3,
routes: {
'/demo/:id': {
type: 'extra',
numberOfPages: 2500,
},
'/docs/:slug': {
type: 'contentFolder',
slug: {
folder: './docs',
},
// postRenderers: ['seoHrefOptimise'],
},
'/user/:id': {
// Type is mandatory
type: 'json',
/**
* Every parameter in the route must exist here
*/
id: {
url: 'http://localhost:8200/users',
// resultsHandler: (raw) => raw.filter((row) => row.id < 102),
property: 'id',
},
},
},
};
registerPlugin('postProcessByHtml', 'blah', async (html, route) => {
return html.replace('<h2>', '<h2>blah ');
});
registerPlugin('postProcessByDom', 'addMyToc', async (dom: JSDOM, route: HandledRoute) => {
const {
window: { document },
} = dom;
const toc = document.createElement('ul');
toc.classList.add('toc');
const h2 = Array.from(document.querySelectorAll('h2'));
for (const header of h2) {
const li = document.createElement('li');
li.innerHTML = `<a href="${header.id}">${header.innerHTML}</a>`;
toc.appendChild(li);
}
document.body.appendChild(toc);
return dom;
});