@adobe/helix-html-pipeline 1.0.0
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/.eslintrc.cjs +33 -0
- package/.husky/pre-commit +4 -0
- package/.mocha-multi.json +6 -0
- package/.nycrc.json +10 -0
- package/.releaserc.cjs +16 -0
- package/CHANGELOG.md +6 -0
- package/CODE_OF_CONDUCT.md +74 -0
- package/CONTRIBUTING.md +74 -0
- package/LICENSE.txt +264 -0
- package/README.md +45 -0
- package/docs/API.md +12 -0
- package/package.json +101 -0
- package/src/PipelineContent.d.ts +69 -0
- package/src/PipelineContent.js +26 -0
- package/src/PipelineRequest.d.ts +26 -0
- package/src/PipelineRequest.js +36 -0
- package/src/PipelineResponse.d.ts +32 -0
- package/src/PipelineResponse.js +44 -0
- package/src/PipelineState.d.ts +72 -0
- package/src/PipelineState.js +42 -0
- package/src/PipelineStatusError.d.ts +14 -0
- package/src/PipelineStatusError.js +17 -0
- package/src/html-pipe.js +100 -0
- package/src/index.d.ts +98 -0
- package/src/index.js +18 -0
- package/src/json-pipe.js +87 -0
- package/src/steps/add-heading-ids.js +32 -0
- package/src/steps/create-page-blocks.js +78 -0
- package/src/steps/create-pictures.js +35 -0
- package/src/steps/extract-metadata.js +257 -0
- package/src/steps/fetch-config.js +42 -0
- package/src/steps/fetch-content.js +83 -0
- package/src/steps/fetch-metadata.js +53 -0
- package/src/steps/fix-sections.js +36 -0
- package/src/steps/folder-mapping.js +61 -0
- package/src/steps/get-metadata.js +170 -0
- package/src/steps/make-html.js +34 -0
- package/src/steps/parse-markdown.js +42 -0
- package/src/steps/removeHlxProps.js +34 -0
- package/src/steps/render-code.js +25 -0
- package/src/steps/render.js +158 -0
- package/src/steps/rewrite-blob-images.js +44 -0
- package/src/steps/rewrite-icons.js +93 -0
- package/src/steps/set-custom-response-headers.js +41 -0
- package/src/steps/set-x-surrogate-key-header.js +35 -0
- package/src/steps/split-sections.js +57 -0
- package/src/steps/stringify-response.js +39 -0
- package/src/steps/utils.js +107 -0
- package/src/utils/hast-util-to-dom.js +190 -0
- package/src/utils/heading-handler.js +42 -0
- package/src/utils/icon-handler.js +40 -0
- package/src/utils/json-filter.js +143 -0
- package/src/utils/last-modified.js +48 -0
- package/src/utils/link-handler.js +25 -0
- package/src/utils/mdast-to-vdom.js +323 -0
- package/src/utils/mdast-util-gfm-nolink.js +93 -0
- package/src/utils/path.js +103 -0
- package/src/utils/remark-gfm-nolink.js +128 -0
- package/src/utils/section-handler.js +69 -0
- package/src/utils/table-handler.js +27 -0
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright 2022 Adobe. All rights reserved.
|
|
3
|
+
* This file is licensed to you under the Apache License; Version 2.0 (the "License");
|
|
4
|
+
* you may not use this file except in compliance with the License. You may obtain a copy
|
|
5
|
+
* of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
6
|
+
*
|
|
7
|
+
* Unless required by applicable law or agreed to in writing; software distributed under
|
|
8
|
+
* the License is distributed on an "AS IS" BASIS; WITHOUT WARRANTIES OR REPRESENTATIONS
|
|
9
|
+
* OF ANY KIND; either express or implied. See the License for the specific language
|
|
10
|
+
* governing permissions and limitations under the License.
|
|
11
|
+
*/
|
|
12
|
+
import {Node} from "unist";
|
|
13
|
+
import GithubSlugger from 'github-slugger';
|
|
14
|
+
|
|
15
|
+
declare enum SourceType {
|
|
16
|
+
CONTENT = 'content',
|
|
17
|
+
CODE = 'code',
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
declare class PipelineContent {
|
|
21
|
+
/**
|
|
22
|
+
* source of content: `content` or `code`
|
|
23
|
+
* @default 'content'
|
|
24
|
+
*/
|
|
25
|
+
sourceBus: SourceType;
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* http status of the content fetch response
|
|
29
|
+
*/
|
|
30
|
+
status: number;
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* raw data of the content
|
|
34
|
+
*/
|
|
35
|
+
data: string;
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* http headers of the content fetch response
|
|
39
|
+
*/
|
|
40
|
+
headers: object;
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* the source location of the loaded content
|
|
44
|
+
*/
|
|
45
|
+
sourceLocation: string;
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* Markdown AST of the parsed content
|
|
49
|
+
*/
|
|
50
|
+
mdast: Node;
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* document specific metadata
|
|
54
|
+
*/
|
|
55
|
+
meta: object;
|
|
56
|
+
title: string;
|
|
57
|
+
intro: string;
|
|
58
|
+
image: string;
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* slugger to use for heading id calculations
|
|
62
|
+
*/
|
|
63
|
+
slugger: GithubSlugger;
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* The transformed document (jsom) representation
|
|
67
|
+
*/
|
|
68
|
+
document: Document;
|
|
69
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright 2022 Adobe. All rights reserved.
|
|
3
|
+
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
* you may not use this file except in compliance with the License. You may obtain a copy
|
|
5
|
+
* of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
6
|
+
*
|
|
7
|
+
* Unless required by applicable law or agreed to in writing, software distributed under
|
|
8
|
+
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
|
|
9
|
+
* OF ANY KIND, either express or implied. See the License for the specific language
|
|
10
|
+
* governing permissions and limitations under the License.
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* State of the pipeline
|
|
15
|
+
* @class PipelineState
|
|
16
|
+
*/
|
|
17
|
+
export class PipelineContent {
|
|
18
|
+
/**
|
|
19
|
+
* Creates the pipeline content
|
|
20
|
+
*/
|
|
21
|
+
constructor() {
|
|
22
|
+
Object.assign(this, {
|
|
23
|
+
sourceBus: 'content',
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright 2022 Adobe. All rights reserved.
|
|
3
|
+
* This file is licensed to you under the Apache License; Version 2.0 (the "License");
|
|
4
|
+
* you may not use this file except in compliance with the License. You may obtain a copy
|
|
5
|
+
* of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
6
|
+
*
|
|
7
|
+
* Unless required by applicable law or agreed to in writing; software distributed under
|
|
8
|
+
* the License is distributed on an "AS IS" BASIS; WITHOUT WARRANTIES OR REPRESENTATIONS
|
|
9
|
+
* OF ANY KIND; either express or implied. See the License for the specific language
|
|
10
|
+
* governing permissions and limitations under the License.
|
|
11
|
+
*/
|
|
12
|
+
import {PathInfo, PipelineContent, S3Loader} from "./index";
|
|
13
|
+
|
|
14
|
+
declare interface PipelineRequestInit {
|
|
15
|
+
method?:string,
|
|
16
|
+
headers?:Map<string, string> | object;
|
|
17
|
+
body?:string;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
declare class PipelineRequest {
|
|
21
|
+
constructor(url:URL|string, opts?:RequestInit);
|
|
22
|
+
url: URL;
|
|
23
|
+
method: string;
|
|
24
|
+
headers: Map<string, string>;
|
|
25
|
+
body: string;
|
|
26
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright 2022 Adobe. All rights reserved.
|
|
3
|
+
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
* you may not use this file except in compliance with the License. You may obtain a copy
|
|
5
|
+
* of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
6
|
+
*
|
|
7
|
+
* Unless required by applicable law or agreed to in writing, software distributed under
|
|
8
|
+
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
|
|
9
|
+
* OF ANY KIND, either express or implied. See the License for the specific language
|
|
10
|
+
* governing permissions and limitations under the License.
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Request of a pipeline
|
|
15
|
+
* @class PipelineRequest
|
|
16
|
+
*/
|
|
17
|
+
export class PipelineRequest {
|
|
18
|
+
/**
|
|
19
|
+
* Creates the pipeline request
|
|
20
|
+
* @param {URL|string} url
|
|
21
|
+
* @param {PipelineRequestInit} [init]
|
|
22
|
+
*/
|
|
23
|
+
constructor(url, init = {}) {
|
|
24
|
+
let headers = init.headers ?? new Map();
|
|
25
|
+
if (typeof headers.get !== 'function') {
|
|
26
|
+
headers = new Map(Object.entries(init.headers));
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
Object.assign(this, {
|
|
30
|
+
url: url instanceof URL ? url : new URL(url),
|
|
31
|
+
method: init.method ?? 'GET',
|
|
32
|
+
body: init.body,
|
|
33
|
+
headers,
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright 2022 Adobe. All rights reserved.
|
|
3
|
+
* This file is licensed to you under the Apache License; Version 2.0 (the "License");
|
|
4
|
+
* you may not use this file except in compliance with the License. You may obtain a copy
|
|
5
|
+
* of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
6
|
+
*
|
|
7
|
+
* Unless required by applicable law or agreed to in writing; software distributed under
|
|
8
|
+
* the License is distributed on an "AS IS" BASIS; WITHOUT WARRANTIES OR REPRESENTATIONS
|
|
9
|
+
* OF ANY KIND; either express or implied. See the License for the specific language
|
|
10
|
+
* governing permissions and limitations under the License.
|
|
11
|
+
*/
|
|
12
|
+
declare interface PipelineResponseInit {
|
|
13
|
+
status?: number;
|
|
14
|
+
headers: Map<string, string> | object;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
declare class PipelineResponse {
|
|
18
|
+
constructor(body?:string, init?:PipelineResponseInit);
|
|
19
|
+
status: number;
|
|
20
|
+
document?: Document;
|
|
21
|
+
body: string;
|
|
22
|
+
headers: Map<string, string>;
|
|
23
|
+
error: any;
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* the last modified time of the response. this is the max of the last-modified times of the
|
|
27
|
+
* various source. e.g. if the `head.html` is newer than the `content`, then the last-modified
|
|
28
|
+
* header will be the one of the `head.html`
|
|
29
|
+
*/
|
|
30
|
+
lastModifiedTime: number;
|
|
31
|
+
}
|
|
32
|
+
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright 2022 Adobe. All rights reserved.
|
|
3
|
+
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
* you may not use this file except in compliance with the License. You may obtain a copy
|
|
5
|
+
* of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
6
|
+
*
|
|
7
|
+
* Unless required by applicable law or agreed to in writing, software distributed under
|
|
8
|
+
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
|
|
9
|
+
* OF ANY KIND, either express or implied. See the License for the specific language
|
|
10
|
+
* governing permissions and limitations under the License.
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Response of a pipeline
|
|
15
|
+
* @class PipelineResponse
|
|
16
|
+
*/
|
|
17
|
+
export class PipelineResponse {
|
|
18
|
+
/**
|
|
19
|
+
* Creates the pipeline response
|
|
20
|
+
*/
|
|
21
|
+
constructor(body = undefined, init = {}) {
|
|
22
|
+
let headers = init.headers ?? new Map([['content-type', 'text/html; charset=utf-8']]);
|
|
23
|
+
if (typeof headers.get !== 'function') {
|
|
24
|
+
headers = new Map(Object.entries(init.headers));
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
Object.assign(this, {
|
|
28
|
+
status: init.status ?? 200,
|
|
29
|
+
body,
|
|
30
|
+
document: undefined,
|
|
31
|
+
headers,
|
|
32
|
+
error: undefined,
|
|
33
|
+
lastModifiedTime: 0,
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Returns the json parsed object of `this.body`.
|
|
39
|
+
* @returns {object}
|
|
40
|
+
*/
|
|
41
|
+
json() {
|
|
42
|
+
return JSON.parse(this.body);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright 2022 Adobe. All rights reserved.
|
|
3
|
+
* This file is licensed to you under the Apache License; Version 2.0 (the "License");
|
|
4
|
+
* you may not use this file except in compliance with the License. You may obtain a copy
|
|
5
|
+
* of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
6
|
+
*
|
|
7
|
+
* Unless required by applicable law or agreed to in writing; software distributed under
|
|
8
|
+
* the License is distributed on an "AS IS" BASIS; WITHOUT WARRANTIES OR REPRESENTATIONS
|
|
9
|
+
* OF ANY KIND; either express or implied. See the License for the specific language
|
|
10
|
+
* governing permissions and limitations under the License.
|
|
11
|
+
*/
|
|
12
|
+
import {PathInfo, S3Loader, PipelineTimer} from "./index";
|
|
13
|
+
import {PipelineContent} from "./PipelineContent";
|
|
14
|
+
|
|
15
|
+
declare interface PipelineOptions {
|
|
16
|
+
log: Console;
|
|
17
|
+
s3Loader: S3Loader;
|
|
18
|
+
owner: string;
|
|
19
|
+
repo: string;
|
|
20
|
+
ref: string;
|
|
21
|
+
partition: string;
|
|
22
|
+
path: string;
|
|
23
|
+
contentBusId: string;
|
|
24
|
+
timer: PipelineTimer;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
declare class PipelineState {
|
|
28
|
+
constructor(opts: PipelineOptions);
|
|
29
|
+
log: Console;
|
|
30
|
+
info: PathInfo;
|
|
31
|
+
content: PipelineContent;
|
|
32
|
+
contentBusId: string;
|
|
33
|
+
s3Loader: S3Loader;
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Content bus partition
|
|
37
|
+
* @example 'live'
|
|
38
|
+
* @example 'preview'
|
|
39
|
+
*/
|
|
40
|
+
partition: string;
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* Repository owner
|
|
44
|
+
*/
|
|
45
|
+
owner: string;
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* Repository name
|
|
49
|
+
*/
|
|
50
|
+
repo: string;
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* Repository ref
|
|
54
|
+
*/
|
|
55
|
+
ref: string;
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* helix-config.json once loaded (contains fstab, head.html, etc)
|
|
59
|
+
*/
|
|
60
|
+
helixConfig?: object;
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* metadata.json once loaded
|
|
64
|
+
*/
|
|
65
|
+
metadata?: object;
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* optional timer that is used to measure the timing
|
|
69
|
+
*/
|
|
70
|
+
timer?: PipelineTimer;
|
|
71
|
+
}
|
|
72
|
+
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright 2022 Adobe. All rights reserved.
|
|
3
|
+
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
* you may not use this file except in compliance with the License. You may obtain a copy
|
|
5
|
+
* of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
6
|
+
*
|
|
7
|
+
* Unless required by applicable law or agreed to in writing, software distributed under
|
|
8
|
+
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
|
|
9
|
+
* OF ANY KIND, either express or implied. See the License for the specific language
|
|
10
|
+
* governing permissions and limitations under the License.
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
import { getPathInfo } from './utils/path.js';
|
|
14
|
+
import { PipelineContent } from './PipelineContent.js';
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* State of the pipeline
|
|
18
|
+
* @class PipelineState
|
|
19
|
+
*/
|
|
20
|
+
export class PipelineState {
|
|
21
|
+
/**
|
|
22
|
+
* Creates the pipeline state
|
|
23
|
+
* @param {PipelineOptions} opts
|
|
24
|
+
*/
|
|
25
|
+
constructor(opts) {
|
|
26
|
+
Object.assign(this, {
|
|
27
|
+
log: opts.log ?? console,
|
|
28
|
+
info: getPathInfo(opts.path),
|
|
29
|
+
content: new PipelineContent(),
|
|
30
|
+
// todo: compute content-bus id from fstab
|
|
31
|
+
contentBusId: opts.contentBusId,
|
|
32
|
+
owner: opts.owner,
|
|
33
|
+
repo: opts.repo,
|
|
34
|
+
ref: opts.ref,
|
|
35
|
+
partition: opts.partition,
|
|
36
|
+
helixConfig: undefined,
|
|
37
|
+
metadata: undefined,
|
|
38
|
+
s3Loader: opts.s3Loader,
|
|
39
|
+
timer: opts.timer,
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright 2022 Adobe. All rights reserved.
|
|
3
|
+
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
* you may not use this file except in compliance with the License. You may obtain a copy
|
|
5
|
+
* of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
6
|
+
*
|
|
7
|
+
* Unless required by applicable law or agreed to in writing, software distributed under
|
|
8
|
+
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
|
|
9
|
+
* OF ANY KIND, either express or implied. See the License for the specific language
|
|
10
|
+
* governing permissions and limitations under the License.
|
|
11
|
+
*/
|
|
12
|
+
declare class PipelineStatusError extends Error {
|
|
13
|
+
code:number;
|
|
14
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright 2022 Adobe. All rights reserved.
|
|
3
|
+
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
* you may not use this file except in compliance with the License. You may obtain a copy
|
|
5
|
+
* of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
6
|
+
*
|
|
7
|
+
* Unless required by applicable law or agreed to in writing, software distributed under
|
|
8
|
+
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
|
|
9
|
+
* OF ANY KIND, either express or implied. See the License for the specific language
|
|
10
|
+
* governing permissions and limitations under the License.
|
|
11
|
+
*/
|
|
12
|
+
export class PipelineStatusError extends Error {
|
|
13
|
+
constructor(code, message) {
|
|
14
|
+
super(message);
|
|
15
|
+
this.code = code;
|
|
16
|
+
}
|
|
17
|
+
}
|
package/src/html-pipe.js
ADDED
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright 2021 Adobe. All rights reserved.
|
|
3
|
+
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
* you may not use this file except in compliance with the License. You may obtain a copy
|
|
5
|
+
* of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
6
|
+
*
|
|
7
|
+
* Unless required by applicable law or agreed to in writing, software distributed under
|
|
8
|
+
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
|
|
9
|
+
* OF ANY KIND, either express or implied. See the License for the specific language
|
|
10
|
+
* governing permissions and limitations under the License.
|
|
11
|
+
*/
|
|
12
|
+
import { cleanupHeaderValue } from '@adobe/helix-shared-utils';
|
|
13
|
+
import addHeadingIds from './steps/add-heading-ids.js';
|
|
14
|
+
import createPageBlocks from './steps/create-page-blocks.js';
|
|
15
|
+
import createPictures from './steps/create-pictures.js';
|
|
16
|
+
import extractMetaData from './steps/extract-metadata.js';
|
|
17
|
+
import fetchConfig from './steps/fetch-config.js';
|
|
18
|
+
import fetchContent from './steps/fetch-content.js';
|
|
19
|
+
import fetchMetadata from './steps/fetch-metadata.js';
|
|
20
|
+
import fixSections from './steps/fix-sections.js';
|
|
21
|
+
import folderMapping from './steps/folder-mapping.js';
|
|
22
|
+
import getMetadata from './steps/get-metadata.js';
|
|
23
|
+
import html from './steps/make-html.js';
|
|
24
|
+
import parseMarkdown from './steps/parse-markdown.js';
|
|
25
|
+
import removeHlxProps from './steps/removeHlxProps.js';
|
|
26
|
+
import render from './steps/render.js';
|
|
27
|
+
import renderCode from './steps/render-code.js';
|
|
28
|
+
import rewriteBlobImages from './steps/rewrite-blob-images.js';
|
|
29
|
+
import rewriteIcons from './steps/rewrite-icons.js';
|
|
30
|
+
import setXSurrogateKeyHeader from './steps/set-x-surrogate-key-header.js';
|
|
31
|
+
import setCustomResponseHeaders from './steps/set-custom-response-headers.js';
|
|
32
|
+
import splitSections from './steps/split-sections.js';
|
|
33
|
+
import tohtml from './steps/stringify-response.js';
|
|
34
|
+
import { PipelineStatusError } from './PipelineStatusError.js';
|
|
35
|
+
import { PipelineResponse } from './PipelineResponse.js';
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Runs the default pipeline and returns the response.
|
|
39
|
+
* @param {PipelineState} state
|
|
40
|
+
* @param {PipelineRequest} req
|
|
41
|
+
* @returns {PipelineResponse}
|
|
42
|
+
*/
|
|
43
|
+
export async function htmlPipe(state, req) {
|
|
44
|
+
const { log } = state;
|
|
45
|
+
|
|
46
|
+
/** @type PipelineResponse */
|
|
47
|
+
const res = new PipelineResponse();
|
|
48
|
+
|
|
49
|
+
try { // fetch config first, since we need to compute the content-bus-id from the fstab ...
|
|
50
|
+
await fetchConfig(state, req, res);
|
|
51
|
+
// ...and apply the folder mapping
|
|
52
|
+
await folderMapping(state, req, res);
|
|
53
|
+
|
|
54
|
+
// load metadata and content in parallel
|
|
55
|
+
await Promise.all([
|
|
56
|
+
fetchMetadata(state, req, res),
|
|
57
|
+
fetchContent(state, req, res),
|
|
58
|
+
]);
|
|
59
|
+
|
|
60
|
+
if (res.error) {
|
|
61
|
+
// if content loading produced an error, we're done.
|
|
62
|
+
log.error(`error running pipeline: ${res.status} ${res.error}`);
|
|
63
|
+
res.headers.set('x-error', cleanupHeaderValue(res.error));
|
|
64
|
+
return res;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
if (state.content.sourceBus === 'code') {
|
|
68
|
+
await renderCode(state, req, res);
|
|
69
|
+
} else {
|
|
70
|
+
await parseMarkdown(state);
|
|
71
|
+
await splitSections(state);
|
|
72
|
+
await getMetadata(state); // this one extracts the metadata from the mdast
|
|
73
|
+
await html(state);
|
|
74
|
+
await rewriteBlobImages(state);
|
|
75
|
+
await rewriteIcons(state);
|
|
76
|
+
await fixSections(state);
|
|
77
|
+
await createPageBlocks(state);
|
|
78
|
+
await createPictures(state);
|
|
79
|
+
await extractMetaData(state, req);
|
|
80
|
+
await addHeadingIds(state);
|
|
81
|
+
await render(state, req, res);
|
|
82
|
+
await removeHlxProps(state, req, res);
|
|
83
|
+
await tohtml(state, req, res);
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
await setCustomResponseHeaders(state, req, res);
|
|
87
|
+
await setXSurrogateKeyHeader(state, req, res);
|
|
88
|
+
} catch (e) {
|
|
89
|
+
res.error = e.message;
|
|
90
|
+
if (e instanceof PipelineStatusError) {
|
|
91
|
+
res.status = e.code;
|
|
92
|
+
} else {
|
|
93
|
+
res.status = 500;
|
|
94
|
+
}
|
|
95
|
+
log.error(`error running pipeline: ${res.status} ${res.error}`, e);
|
|
96
|
+
res.headers.set('x-error', cleanupHeaderValue(res.error));
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
return res;
|
|
100
|
+
}
|
package/src/index.d.ts
ADDED
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright 2021 Adobe. All rights reserved.
|
|
3
|
+
* This file is licensed to you under the Apache License; Version 2.0 (the "License");
|
|
4
|
+
* you may not use this file except in compliance with the License. You may obtain a copy
|
|
5
|
+
* of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
6
|
+
*
|
|
7
|
+
* Unless required by applicable law or agreed to in writing; software distributed under
|
|
8
|
+
* the License is distributed on an "AS IS" BASIS; WITHOUT WARRANTIES OR REPRESENTATIONS
|
|
9
|
+
* OF ANY KIND; either express or implied. See the License for the specific language
|
|
10
|
+
* governing permissions and limitations under the License.
|
|
11
|
+
*/
|
|
12
|
+
import {PipelineState} from "./PipelineState";
|
|
13
|
+
import {PipelineRequest} from "./PipelineRequest";
|
|
14
|
+
import {PipelineResponse} from "./PipelineResponse";
|
|
15
|
+
|
|
16
|
+
export * from './PipelineContent';
|
|
17
|
+
export * from './PipelineRequest';
|
|
18
|
+
export * from './PipelineResponse';
|
|
19
|
+
export * from './PipelineState';
|
|
20
|
+
export * from './PipelineStatusError';
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Path Info
|
|
24
|
+
*/
|
|
25
|
+
declare interface PathInfo {
|
|
26
|
+
/**
|
|
27
|
+
* Resource path
|
|
28
|
+
* @example '/express/index.md'
|
|
29
|
+
* @example '/en/query-index.json'
|
|
30
|
+
*/
|
|
31
|
+
resourcePath: string;
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Web path
|
|
35
|
+
* @example '/express/'
|
|
36
|
+
* @example '/blogs/may-21'
|
|
37
|
+
* @example '/en/query-index.json'
|
|
38
|
+
*/
|
|
39
|
+
path: string;
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* extension / type of resource
|
|
43
|
+
* @example '.html'
|
|
44
|
+
* @example '.md'
|
|
45
|
+
*/
|
|
46
|
+
extension: string;
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* selector
|
|
50
|
+
* @example 'plain'
|
|
51
|
+
*/
|
|
52
|
+
selector?: string;
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* original path as passed via request
|
|
56
|
+
*/
|
|
57
|
+
originalPath: string;
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* original filename as passed via request
|
|
61
|
+
*/
|
|
62
|
+
originalFilename: string;
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* original extension as passed via request
|
|
66
|
+
*/
|
|
67
|
+
originalExtension: string;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
declare interface S3Loader {
|
|
71
|
+
/**
|
|
72
|
+
* Loads a S3 object from the given bucket and key.
|
|
73
|
+
* @param {string} bucketId
|
|
74
|
+
* @param {string} key
|
|
75
|
+
*/
|
|
76
|
+
getObject(bucketId, key): Promise<PipelineResponse>;
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* Retrieves the head metadata of a S3 object from the given bucket and key.
|
|
80
|
+
* @param {string} bucketId
|
|
81
|
+
* @param {string} key
|
|
82
|
+
*/
|
|
83
|
+
headObject(bucketId, key): Promise<PipelineResponse>;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* Timer
|
|
88
|
+
*/
|
|
89
|
+
declare interface PipelineTimer {
|
|
90
|
+
/**
|
|
91
|
+
* Records the timestamp of the given `step`
|
|
92
|
+
*/
|
|
93
|
+
update(step:string): void;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
declare interface PipelineStep {
|
|
97
|
+
async(state: PipelineState, req: PipelineRequest, resp: PipelineResponse): Promise<void>;
|
|
98
|
+
}
|
package/src/index.js
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright 2022 Adobe. All rights reserved.
|
|
3
|
+
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
* you may not use this file except in compliance with the License. You may obtain a copy
|
|
5
|
+
* of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
6
|
+
*
|
|
7
|
+
* Unless required by applicable law or agreed to in writing, software distributed under
|
|
8
|
+
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
|
|
9
|
+
* OF ANY KIND, either express or implied. See the License for the specific language
|
|
10
|
+
* governing permissions and limitations under the License.
|
|
11
|
+
*/
|
|
12
|
+
export * from './html-pipe.js';
|
|
13
|
+
export * from './json-pipe.js';
|
|
14
|
+
export * from './PipelineContent.js';
|
|
15
|
+
export * from './PipelineRequest.js';
|
|
16
|
+
export * from './PipelineResponse.js';
|
|
17
|
+
export * from './PipelineState.js';
|
|
18
|
+
export * from './PipelineStatusError.js';
|