|
| 1 | +<?php |
| 2 | + |
| 3 | +$usageFiles = call_user_func(function (array $a): array { |
| 4 | + asort($a); |
| 5 | + return $a; |
| 6 | +}, (new Finder('./docs')) |
| 7 | + ->includeName('*.md') |
| 8 | + ->excludeWholeName('./docs/release_notes/*')//TMP |
| 9 | + ->excludeWholeName('./docs/snippets/*')//TMP |
| 10 | + ->find()); |
| 11 | + |
| 12 | +$resourceFiles = call_user_func(function (array $a): array { |
| 13 | + asort($a); |
| 14 | + return $a; |
| 15 | +}, |
| 16 | + // Images |
| 17 | + (new Finder('./docs')) |
| 18 | + ->includeName('*.png') |
| 19 | + ->includeName('*.jpg') |
| 20 | + ->find(), |
| 21 | +); |
| 22 | + |
| 23 | +$exclusionTests = array_merge_recursive(UrlTester::getDefaultExclusionTests(), [ |
| 24 | + 'url' => [ |
| 25 | + function (string $url, string $file = null): bool { |
| 26 | + return 'docs/index.md' === $file && str_starts_with($url, 'docs/'); |
| 27 | + }, |
| 28 | + function (string $url, string $file = null): bool { |
| 29 | + // ibexa.co APIs needing authentication, namespaces, commercial aliases, etc. |
| 30 | + return str_starts_with($url, 'https://updates.ibexa.co') // 401 |
| 31 | + || str_starts_with($url, 'https://support.ibexa.co') // 302 → /login |
| 32 | + || str_starts_with($url, 'https://connect.ibexa.co') // 302 → https://ibexa.integromat.celonis.com/ |
| 33 | + || str_starts_with($url, 'http://ibexa.co/namespaces/') // 301 |
| 34 | + || str_starts_with($url, 'http://ibexa.co/xmlns/') // 301 |
| 35 | + || str_starts_with($url, 'http://ez.no/namespaces/') //301 |
| 36 | + || str_starts_with($url, 'https://api.cloud.ibexa.co') // 301, PLATFORMSH_CLI_API_URL |
| 37 | + //|| str_starts_with($url, 'https://admin.perso.ibexa.co/api/') // 400 |
| 38 | + || str_starts_with($url, 'https://admin.perso.ibexa.co/') // 404 |
| 39 | + || str_starts_with($url, 'https://event.perso.ibexa.co/api/') // 400 |
| 40 | + || str_starts_with($url, 'https://event.perso.ibexa.co/ebl/') // 404 |
| 41 | + || str_starts_with($url, 'https://import.perso.ibexa.co/api/') // 400 |
| 42 | + || str_starts_with($url, 'https://reco.perso.ibexa.co') // 403 |
| 43 | + ; |
| 44 | + }, |
| 45 | + function (string $url, string $file = null): bool { |
| 46 | + // Third parties APIs, namespaces, etc. |
| 47 | + return str_starts_with($url, 'https://api.fastly.com') // 301 or 403 |
| 48 | + || str_starts_with($url, 'https://unsplash.com') // 405 |
| 49 | + || str_starts_with($url, 'http://docbook.org/ns/') // 301 |
| 50 | + || str_starts_with($url, 'http://www.w3.org/1999/xlink') // 301 → https |
| 51 | + ; |
| 52 | + }, |
| 53 | + function (string $url, string $file = null): bool { |
| 54 | + return (bool)preg_match('@(https?:)?//([a-z]+\.)?(localhost|127.0.0.1)(:[0-9]+)?(/.*|$)@', $url); |
| 55 | + }, |
| 56 | + function (string $url, string $file = null): bool { |
| 57 | + // Fake, placeholders, local servers, etc. |
| 58 | + return str_contains($url, 'foobar.com') |
| 59 | + || str_contains($url, 'mydomain.com') |
| 60 | + || str_contains($url, '//my_site.com') |
| 61 | + || str_contains($url, '//address.of/') |
| 62 | + || str_contains($url, '//some/file/here') |
| 63 | + || str_contains($url, '//mydoc.pdf') |
| 64 | + || str_contains($url, 'var/ezdemo_site/') |
| 65 | + || str_contains($url, '//server_uri') |
| 66 | + || str_contains($url, '//FRA_server_uri') |
| 67 | + || str_contains($url, '//user:password@host') |
| 68 | + || str_contains($url, '//user:pass@localhost') |
| 69 | + || str_contains($url, '//varnish') |
| 70 | + || str_contains($url, '//my.varnish.server') |
| 71 | + ; |
| 72 | + }, |
| 73 | + function (string $url, string $file = null): bool { |
| 74 | + return str_starts_with($url, '/assets/') |
| 75 | + || str_contains($url, '{{ asset('); |
| 76 | + }, |
| 77 | + function (string $url, string $file = null): bool { |
| 78 | + return false !== strpos($url, 'javascript:'); |
| 79 | + }, |
| 80 | + function (string $url, string $file = null): bool { |
| 81 | + return str_contains($url, '{{ path(') |
| 82 | + //|| str_contains($url, '{{ ez_path(') |
| 83 | + || str_contains($url, '{{ ibexa_path(') |
| 84 | + || str_contains($url, '{{ ibexa_url(') |
| 85 | + //|| str_contains($url, "|e('html_attr')") |
| 86 | + || str_contains($url, '{{ image_uri }}') |
| 87 | + || str_contains($url, '{{ ibexa_checkout_step_path(') |
| 88 | + || str_contains($url, '{{ ibexa_checkout_step_url(') |
| 89 | + ; |
| 90 | + }, |
| 91 | + ], |
| 92 | + 'location' => [ |
| 93 | + function (string $url, string $location, string $file = null): bool { |
| 94 | + return $url === $location && str_starts_with($url, 'https://twitter.com/'); |
| 95 | + }, |
| 96 | + function (string $url, string $location, string $file = null): bool { |
| 97 | + return str_starts_with($url, 'https://youtu.be/') && explode('/', $url)[3] . '&feature=youtu.be' === explode('?v=', $location)[1]; |
| 98 | + }, |
| 99 | + function (string $url, string $location, string $file = null): bool { |
| 100 | + return str_starts_with($url, 'https://www.facebook.com/') && str_starts_with($location, 'https://www.facebook.com/unsupportedbrowser'); |
| 101 | + } |
| 102 | + ], |
| 103 | + 'fragment' => [ |
| 104 | + function (string $url, string $file = null): bool { |
| 105 | + return str_starts_with($url, 'https://classic.yarnpkg.com/en/docs/') |
| 106 | + || str_starts_with($url, 'https://ddev.readthedocs.io/'); |
| 107 | + }, |
| 108 | + ], |
| 109 | +]); |
| 110 | + |
| 111 | +$replacements = [//TODO Get from mkdocs.yml |
| 112 | + '[[= symfony_doc =]]' => 'https://symfony.com/doc/5.4', |
| 113 | + '[[= user_doc =]]' => 'https://doc.ibexa.co/projects/userguide/en/master', |
| 114 | +]; |
| 115 | + |
| 116 | +$find = true; |
0 commit comments