Show broken links in red, external link with an arrow. fixes #395

Cette révision appartient à :
Stéphane Goetz 2016-08-16 23:25:06 +02:00
Parent 2644a7881c
révision 8ac4137007
11 fichiers modifiés avec 53 ajouts et 16 suppressions

Voir le fichier

@ -88,6 +88,16 @@ class Config extends ArrayObject
return array_key_exists('languages', $this) && !empty($this['languages']); return array_key_exists('languages', $this) && !empty($this['languages']);
} }
public function isLive()
{
return $this['mode'] == Daux::LIVE_MODE;
}
public function isStatic()
{
return $this['mode'] == Daux::STATIC_MODE;
}
public function shouldInheritIndex() public function shouldInheritIndex()
{ {
// As the global configuration is always present, we // As the global configuration is always present, we

Voir le fichier

@ -6,7 +6,7 @@ use League\CommonMark\Inline\Element\AbstractInline;
use League\CommonMark\Inline\Element\Link; use League\CommonMark\Inline\Element\Link;
use Todaymade\Daux\Config; use Todaymade\Daux\Config;
use Todaymade\Daux\DauxHelper; use Todaymade\Daux\DauxHelper;
use Todaymade\Daux\Exception; use Todaymade\Daux\Exception\LinkNotFoundException;
use Todaymade\Daux\Tree\Entry; use Todaymade\Daux\Tree\Entry;
class LinkRenderer extends \League\CommonMark\Inline\Renderer\LinkRenderer class LinkRenderer extends \League\CommonMark\Inline\Renderer\LinkRenderer
@ -24,7 +24,7 @@ class LinkRenderer extends \League\CommonMark\Inline\Renderer\LinkRenderer
/** /**
* @param string $url * @param string $url
* @return Entry * @return Entry
* @throws Exception * @throws LinkNotFoundException
*/ */
protected function resolveInternalFile($url) protected function resolveInternalFile($url)
{ {
@ -55,14 +55,14 @@ class LinkRenderer extends \League\CommonMark\Inline\Renderer\LinkRenderer
return $file; return $file;
} }
throw new Exception("Could not locate file '$url'"); throw new LinkNotFoundException("Could not locate file '$url'");
} }
/** /**
* @param AbstractInline|Link $inline * @param AbstractInline|Link $inline
* @param ElementRendererInterface $htmlRenderer * @param ElementRendererInterface $htmlRenderer
* @return HtmlElement * @return HtmlElement
* @throws Exception * @throws LinkNotFoundException
*/ */
public function render(AbstractInline $inline, ElementRendererInterface $htmlRenderer) public function render(AbstractInline $inline, ElementRendererInterface $htmlRenderer)
{ {
@ -81,15 +81,28 @@ class LinkRenderer extends \League\CommonMark\Inline\Renderer\LinkRenderer
$url = $inline->getUrl(); $url = $inline->getUrl();
// Absolute urls, empty urls and anchors // empty urls and anchors should
// should not go through the url resolver // not go through the url resolver
if (empty($url) || $url[0] == '#' || preg_match('|^(?:[a-z]+:)?//|', $url)) { if (empty($url) || $url[0] == '#') {
return $element; return $element;
} }
$file = $this->resolveInternalFile($url); // Absolute urls, shouldn't either
if (preg_match('|^(?:[a-z]+:)?//|', $url)) {
$element->setAttribute('class', 'external');
return $element;
}
try {
$file = $this->resolveInternalFile($url);
$url = DauxHelper::getRelativePath($this->daux->getCurrentPage()->getUrl(), $file->getUrl()); $url = DauxHelper::getRelativePath($this->daux->getCurrentPage()->getUrl(), $file->getUrl());
} catch(LinkNotFoundException $e) {
if ($this->daux->isStatic()) {
throw $e;
}
$element->setAttribute('class', 'broken');
}
$element->setAttribute('href', $url); $element->setAttribute('href', $url);

Voir le fichier

@ -0,0 +1,5 @@
<?php namespace Todaymade\Daux\Exception;
class LinkNotFoundException extends \Todaymade\Daux\Exception
{
}

Voir le fichier

@ -110,7 +110,7 @@ class Builder
} }
$uri = static::removeSortingInformations($name); $uri = static::removeSortingInformations($name);
if ($config['mode'] === Daux::STATIC_MODE) { if ($config->isStatic()) {
$uri .= '.html'; $uri .= '.html';
} }
@ -184,7 +184,7 @@ class Builder
if (!$raw) { if (!$raw) {
$title = static::getName($path); $title = static::getName($path);
$uri = DauxHelper::slug($title); $uri = DauxHelper::slug($title);
if ($parent->getConfig()['mode'] === Daux::STATIC_MODE) { if ($parent->getConfig()->isStatic()) {
$uri .= '.html'; $uri .= '.html';
} }
} }

Voir le fichier

@ -106,6 +106,7 @@ blockquote {
table { table {
width: 100%; width: 100%;
padding: 0; padding: 0;
border-collapse: collapse;
tr { tr {
border-top: 1px solid #eee; border-top: 1px solid #eee;

Diff de fichier supprimé car une ou plusieurs lignes sont trop longues

Diff de fichier supprimé car une ou plusieurs lignes sont trop longues

Diff de fichier supprimé car une ou plusieurs lignes sont trop longues

Diff de fichier supprimé car une ou plusieurs lignes sont trop longues

Voir le fichier

@ -5,6 +5,14 @@ Base tags
a { a {
text-decoration: none; text-decoration: none;
color: @light; color: @light;
&.external::after {
content: " " url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAoAAAAKCAYAAACNMs+9AAAAVklEQVR4Xn3PgQkAMQhDUXfqTu7kTtkpd5RA8AInfArtQ2iRXFWT2QedAfttj2FsPIOE1eCOlEuoWWjgzYaB/IkeGOrxXhqB+uA9Bfcm0lAZuh+YIeAD+cAqSz4kCMUAAAAASUVORK5CYII=);
}
&.broken {
color: red;
}
} }
p { p {

Diff de fichier supprimé car une ou plusieurs lignes sont trop longues