diff --git a/user_guide_src/add-edit-this-page b/user_guide_src/add-edit-this-page new file mode 100755 index 000000000000..cb036524369d --- /dev/null +++ b/user_guide_src/add-edit-this-page @@ -0,0 +1,62 @@ +#!/usr/bin/env php +' . PHP_EOL; + echo ' e.g: ' . $argv[0] . ' user_guide_src/build/html/' . PHP_EOL; + + exit(1); +} + +$dir = realpath($argv[1]); + +if ($dir === false || ! is_dir($dir)) { + throw new RuntimeException('Cannot find directory: ' . $dir); +} + +$iterator = new RecursiveIteratorIterator( + new RecursiveDirectoryIterator( + $dir, + FilesystemIterator::CURRENT_AS_FILEINFO | + FilesystemIterator::KEY_AS_PATHNAME | + FilesystemIterator::SKIP_DOTS + ) +); + +$files = new RegexIterator( + $iterator, + '/\A.+\.html\z/', + RecursiveRegexIterator::MATCH +); + +foreach ($files as $filePath => $fileInfo) { + echo 'processing... ' . PHP_EOL; + + $uriPath = str_replace('.html', '.rst', str_replace($dir, '', $filePath)); + $gitHubLink = 'Edit this page'; + + $content = file_get_contents($filePath); + + $pattern = '!">Edit this page!u'; + if (preg_match($pattern, $content) === 1) { + // Move the cursor up 1 line + echo "\033[1A"; + echo 'skip: ' . $filePath . PHP_EOL; + + continue; + } + + $pattern = '/