1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 | import { removeIgnoredSearchParams } from './removeIgnoredSearchParams.js';
|
9 | import '../_version.js';
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 |
|
17 |
|
18 |
|
19 |
|
20 | export function* generateURLVariations(url, { ignoreURLParametersMatching = [/^utm_/, /^fbclid$/], directoryIndex = 'index.html', cleanURLs = true, urlManipulation, } = {}) {
|
21 | const urlObject = new URL(url, location.href);
|
22 | urlObject.hash = '';
|
23 | yield urlObject.href;
|
24 | const urlWithoutIgnoredParams = removeIgnoredSearchParams(urlObject, ignoreURLParametersMatching);
|
25 | yield urlWithoutIgnoredParams.href;
|
26 | if (directoryIndex && urlWithoutIgnoredParams.pathname.endsWith('/')) {
|
27 | const directoryURL = new URL(urlWithoutIgnoredParams.href);
|
28 | directoryURL.pathname += directoryIndex;
|
29 | yield directoryURL.href;
|
30 | }
|
31 | if (cleanURLs) {
|
32 | const cleanURL = new URL(urlWithoutIgnoredParams.href);
|
33 | cleanURL.pathname += '.html';
|
34 | yield cleanURL.href;
|
35 | }
|
36 | if (urlManipulation) {
|
37 | const additionalURLs = urlManipulation({ url: urlObject });
|
38 | for (const urlToAttempt of additionalURLs) {
|
39 | yield urlToAttempt.href;
|
40 | }
|
41 | }
|
42 | }
|