-
Notifications
You must be signed in to change notification settings - Fork 257
/
scully.scully-docs.config.ts
214 lines (189 loc) · 6.54 KB
/
scully.scully-docs.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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
import {
SPSRouteRenderer,
prod,
scullyConfig,
registerPlugin,
ScullyConfig,
setPluginConfig,
log,
logError,
enableSPS,
} from '@scullyio/scully';
import { docLink } from '@scullyio/scully-plugin-docs-link-update';
import { GoogleAnalytics } from '@scullyio/scully-plugin-google-analytics';
import { LogRocket } from '@scullyio/scully-plugin-logrocket';
import { Sentry } from '@scullyio/scully-plugin-sentry';
import { copyToClipboard } from '@scullyio/scully-plugin-copy-to-clipboard';
import { removeScripts, RemoveScriptsConfig } from '@scullyio/scully-plugin-remove-scripts';
const { marked } = require('marked');
import { readFileSync } from 'fs-extra';
import { JSDOM } from 'jsdom';
import { loadRenderer } from './scully/loadRenderer';
// import { criticalCSS } from '@scullyio/scully-plugin-critical-css';
// import { localCacheReady } from '@scullyio/scully-plugin-local-cache';
import 'prismjs/components/prism-yaml';
import 'prismjs/components/prism-docker';
import 'prismjs/components/prism-bash';
import 'prismjs/components/prism-markdown';
import { join } from 'path';
import { cpus } from 'os';
const { window } = new JSDOM('<!doctype html><html><body></body></html>');
const { document } = window;
// global.console.log = (first, ...args) => log(typeof first === 'string' ? first.slice(0, 120) : first, ...args);
// global.console.error = (first, ...args) => logError(String(first).slice(0, 60));
// const jsdom = require('jsdom');
// conFst { JSDOM } = jsdom;
setPluginConfig('md', { enableSyntaxHighlighting: true });
// setPluginConfig(criticalCSS, {
// inlineImages: false,
// });
// const defaultPostRenderers = [];
// const defaultPostRenderers = [LogRocket, GoogleAnalytics, removeScripts, 'seoHrefOptimise', criticalCSS, copyToClipboard];
const defaultPostRenderers = [LogRocket, GoogleAnalytics, removeScripts, 'seoHrefOptimise', copyToClipboard, 'critters'];
if (prod) {
/*
* Config for production
* */
setPluginConfig(LogRocket, { app: 'herodevs', id: 'scully' });
setPluginConfig(GoogleAnalytics, { globalSiteTag: 'UA-171495765-1' });
defaultPostRenderers.unshift(Sentry);
setPluginConfig(Sentry, {
key: 'c614241b1af34dbea5ad051000ffab7d',
org: 'o426873',
project: '5370245',
});
} else {
/*
* Config for test
*/
setPluginConfig(LogRocket, { app: 'test', id: 'test' });
setPluginConfig(GoogleAnalytics, { globalSiteTag: 'test' });
}
setPluginConfig<RemoveScriptsConfig>(removeScripts, {
keepTransferstate: false,
// keepAttributes: [],
});
export const config: Promise<ScullyConfig> = createConfig();
async function createConfig(): Promise<ScullyConfig> {
await loadRenderer();
// await localCacheReady();
return {
projectRoot: './apps/scully-docs/src',
projectName: 'scully-docs',
outDir: './dist/static/doc-sites',
distFolder: './dist/apps/scully-docs',
spsModulePath: './apps/scully-docs/src/app/app.sps.module.ts',
defaultPostRenderers,
// extraRoutes: [],
maxRenderThreads: cpus().length * 2,
routes: {
'/docs/:slug': {
type: 'contentFolder',
postRenderers: ['docs-toc', docLink, ...defaultPostRenderers],
slug: {
folder: './docs',
},
},
'/scully-user': {
type: 'default',
postRenderers: ['contentText'],
contentType: 'html',
content: () =>
`<iframe src="https://docs.google.com/forms/d/e/1FAIpQLSe2FgkdQfpZ9JwNqVOs8bNlPHGpvZJcvUXvTgqdt64qYLeqzA/viewform?embedded=true" width="640" height="1088" frameborder="0" marginheight="0" marginwidth="0">Loading…</iframe>`,
},
'/ngconf': {
type: 'default',
postRenderers: ['contentText', ...defaultPostRenderers],
contentType: 'md',
content: () => {
return `# Ng-Conf 2021
### To enter our Scully Thank-you Giveaway
[click here](https://forms.gle/1Un68gVYdiz3Atxc8)
### To sign up for the Scully Server Beta
[click here](https://forms.gle/kHHLLvrtSJyjbtXY8)
`;
},
},
'/support': {
type: 'default',
postRenderers: ['contentText', ...defaultPostRenderers],
contentType: 'md',
content: async () => {
const fm: any = await import('front-matter');
const contentFile = join(scullyConfig.homeFolder, 'docs_extraPages/support.md');
const { body } = fm(readFileSync(contentFile).toString('utf-8'));
return body;
},
},
},
puppeteerLaunchOptions: {
defaultViewport: null,
devtools: false,
},
};
}
registerPlugin('postProcessByDom', 'docs-toc', async (dom, route) => {
const headingIds = getHeadings(readFileSync(route.templateFile, 'utf-8').toString());
const toc = `<ul>${headingIds.map(createLi).join('')}</ul>`;
const heads = headingIds.map((h) => h[1]);
const last = heads.pop();
const desc = `Scully documentation page containing ${heads.join(',')} and ${last}`;
const {
window: { document },
} = dom;
const tocDiv = document.createElement('div');
tocDiv.id = 'toc-doc';
tocDiv.innerHTML = toc;
const meta = document.createElement('meta');
meta.name = 'description';
meta.content = desc;
document.head.appendChild(meta);
try {
document.querySelector('scully-content').parentNode.appendChild(tocDiv);
} catch (e) {}
return dom;
function createLi([id, desc]) {
return `
<li><a href="#${id}">${desc}</a></li>`;
}
});
function getHeadings(content: string): [string, string][] {
const exceptions = [
// '# angular tutorial',
// 'overview',
// 'my blog post',
`first build your app,`,
`run scully`,
'#heading 1 ### subheading 1 ## heading 2 ### subheading 2',
].map((e) => e.trim().toLowerCase());
return content
.split('\n')
.filter(
(line) => line.startsWith('#') && !exceptions.some((exception) => line.toLowerCase().includes(exception.toLowerCase().trim()))
)
.map((line) => {
const outer = document.createElement('div');
outer.innerHTML = marked(line.trim());
const elm = outer.firstChild;
try {
// extract Id
const id = elm['id'] as string;
const desc = elm.textContent;
return [id, desc];
} catch (e) {
console.log('oops', e);
return ['', ''];
}
});
}
registerPlugin('postProcessByHtml', 'critters', async (html, route) => {
const Critters = await import('critters');
const critter = new Critters({
path: scullyConfig.distFolder,
publicPath: scullyConfig.distFolder,
pruneSource: true,
logLevel: 'silent',
inlineFonts: true,
});
return await critter.process(html);
});