Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix broken links #1060

Merged
merged 1 commit into from
Jan 3, 2020
Merged

Fix broken links #1060

merged 1 commit into from
Jan 3, 2020

Conversation

voronkovich
Copy link
Contributor

The Symfony's documentation was greatly updated and many links in the app's source files are broken. I found all broken links and fixed each one of them where it was possible.

I used this command to extract the links from the source code, so I could miss out some of them:

grep -ERhoe 'https?://[^[:space:]]*\w' src assets config tests templates | sort -u

@noniagriconomie
Copy link
Contributor

noniagriconomie commented Jan 3, 2020

@voronkovich nice one 👍

just an idea, can it be usefull to "automate" this? on this repo and all sf repo (I saw symfony/recipes#715, and i am sure on /symfony and /symfony-docs as well)

a small sh or php script, launched once a week or manually for example
it founds the http(s) endpoints and requests them, then checks if != 200 (also no redirection) => stderr
so that a human can fix/improve those links :)


EDIT: from the command above, and testing httpclient :)

improvement:

  • exludes some known uri (schema xml, DIC, etc)
  • send notification to doc core team?
<?php

require_once __DIR__.'/vendor/autoload.php';

use Symfony\Component\HttpClient\HttpClient;
use Symfony\Component\Process\Exception\ProcessFailedException;
use Symfony\Component\Process\Process;

$folders = ['vendor/symfony/symfony'];
$shellCommandline = \sprintf('grep -ERhoe "https?://[^[:space:]]*\w" %s', \implode(' ', $folders));

$process = Process::fromShellCommandline($shellCommandline);
$process->run();

if (!$process->isSuccessful()) {
    throw new ProcessFailedException($process);
}

$output = $process->getOutput();
$links = \explode(PHP_EOL, $output);

$httpClient = HttpClient::create();
$cacheLinks = [];
$brokenlinks = [];

foreach ($links as $link) {
	if (!isset($cacheLinks[$link])) {
		$cacheLinks[] = $link;
		try {
			$response = $httpClient->request('GET', $link, ['max_redirects' => 0,]);
			$statusCode = $response->getStatusCode();
			if (200 !== $statusCode) {
				$brokenlinks[$statusCode][] = $link;
			}
		} catch (\Throwable $e) {
		}
	}
}

var_dump($brokenlinks);

exit(0);

composer require

    "require": {
        "symfony/process": "^5.1@dev",
        "symfony/http-client": "^5.1@dev"
    },

@jkufner
Copy link
Contributor

jkufner commented Jan 3, 2020

It is a good idea to incorporate these checks into CI pipeline. I've done that for my static websites and it turned up very useful.

@javiereguiluz
Copy link
Member

Oleg, this is great! Thanks a lot for fixing all these wrong links. We appreciate it a lot!

@javiereguiluz javiereguiluz merged commit 24eeceb into symfony:master Jan 3, 2020
@voronkovich voronkovich deleted the broken-links branch January 3, 2020 17:19
@voronkovich
Copy link
Contributor Author

@noniagriconomie, Many links contain fragments (http://link#fragment), so your script should check that a requested page has a corresponding element if the fragment presents in URI. To do this you could use the symfony/browser-kit.

@noniagriconomie
Copy link
Contributor

@voronkovich yeah just a poc I have done, still i use it in a local project :)
but yeay in sf codebase, need to excluded some urls and thise anchors urls

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants