Show broken links in red, external link with an arrow. fixes #395
This commit is contained in:
parent
2644a7881c
commit
8ac4137007
@ -88,6 +88,16 @@ class Config extends ArrayObject
|
||||
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()
|
||||
{
|
||||
// As the global configuration is always present, we
|
||||
|
@ -6,7 +6,7 @@ use League\CommonMark\Inline\Element\AbstractInline;
|
||||
use League\CommonMark\Inline\Element\Link;
|
||||
use Todaymade\Daux\Config;
|
||||
use Todaymade\Daux\DauxHelper;
|
||||
use Todaymade\Daux\Exception;
|
||||
use Todaymade\Daux\Exception\LinkNotFoundException;
|
||||
use Todaymade\Daux\Tree\Entry;
|
||||
|
||||
class LinkRenderer extends \League\CommonMark\Inline\Renderer\LinkRenderer
|
||||
@ -24,7 +24,7 @@ class LinkRenderer extends \League\CommonMark\Inline\Renderer\LinkRenderer
|
||||
/**
|
||||
* @param string $url
|
||||
* @return Entry
|
||||
* @throws Exception
|
||||
* @throws LinkNotFoundException
|
||||
*/
|
||||
protected function resolveInternalFile($url)
|
||||
{
|
||||
@ -55,14 +55,14 @@ class LinkRenderer extends \League\CommonMark\Inline\Renderer\LinkRenderer
|
||||
return $file;
|
||||
}
|
||||
|
||||
throw new Exception("Could not locate file '$url'");
|
||||
throw new LinkNotFoundException("Could not locate file '$url'");
|
||||
}
|
||||
|
||||
/**
|
||||
* @param AbstractInline|Link $inline
|
||||
* @param ElementRendererInterface $htmlRenderer
|
||||
* @return HtmlElement
|
||||
* @throws Exception
|
||||
* @throws LinkNotFoundException
|
||||
*/
|
||||
public function render(AbstractInline $inline, ElementRendererInterface $htmlRenderer)
|
||||
{
|
||||
@ -81,15 +81,28 @@ class LinkRenderer extends \League\CommonMark\Inline\Renderer\LinkRenderer
|
||||
|
||||
$url = $inline->getUrl();
|
||||
|
||||
// Absolute urls, empty urls and anchors
|
||||
// should not go through the url resolver
|
||||
if (empty($url) || $url[0] == '#' || preg_match('|^(?:[a-z]+:)?//|', $url)) {
|
||||
// empty urls and anchors should
|
||||
// not go through the url resolver
|
||||
if (empty($url) || $url[0] == '#') {
|
||||
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());
|
||||
} catch(LinkNotFoundException $e) {
|
||||
if ($this->daux->isStatic()) {
|
||||
throw $e;
|
||||
}
|
||||
|
||||
$element->setAttribute('class', 'broken');
|
||||
}
|
||||
|
||||
$element->setAttribute('href', $url);
|
||||
|
||||
|
5
libs/Exception/LinkNotFoundException.php
Normal file
5
libs/Exception/LinkNotFoundException.php
Normal file
@ -0,0 +1,5 @@
|
||||
<?php namespace Todaymade\Daux\Exception;
|
||||
|
||||
class LinkNotFoundException extends \Todaymade\Daux\Exception
|
||||
{
|
||||
}
|
@ -110,7 +110,7 @@ class Builder
|
||||
}
|
||||
|
||||
$uri = static::removeSortingInformations($name);
|
||||
if ($config['mode'] === Daux::STATIC_MODE) {
|
||||
if ($config->isStatic()) {
|
||||
$uri .= '.html';
|
||||
}
|
||||
|
||||
@ -184,7 +184,7 @@ class Builder
|
||||
if (!$raw) {
|
||||
$title = static::getName($path);
|
||||
$uri = DauxHelper::slug($title);
|
||||
if ($parent->getConfig()['mode'] === Daux::STATIC_MODE) {
|
||||
if ($parent->getConfig()->isStatic()) {
|
||||
$uri .= '.html';
|
||||
}
|
||||
}
|
||||
|
@ -106,6 +106,7 @@ blockquote {
|
||||
table {
|
||||
width: 100%;
|
||||
padding: 0;
|
||||
border-collapse: collapse;
|
||||
|
||||
tr {
|
||||
border-top: 1px solid #eee;
|
||||
|
2
themes/daux/css/theme-blue.min.css
vendored
2
themes/daux/css/theme-blue.min.css
vendored
File diff suppressed because one or more lines are too long
2
themes/daux/css/theme-green.min.css
vendored
2
themes/daux/css/theme-green.min.css
vendored
File diff suppressed because one or more lines are too long
2
themes/daux/css/theme-navy.min.css
vendored
2
themes/daux/css/theme-navy.min.css
vendored
File diff suppressed because one or more lines are too long
2
themes/daux/css/theme-red.min.css
vendored
2
themes/daux/css/theme-red.min.css
vendored
File diff suppressed because one or more lines are too long
@ -5,6 +5,14 @@ Base tags
|
||||
a {
|
||||
text-decoration: none;
|
||||
color: @light;
|
||||
|
||||
&.external::after {
|
||||
content: " " url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAoAAAAKCAYAAACNMs+9AAAAVklEQVR4Xn3PgQkAMQhDUXfqTu7kTtkpd5RA8AInfArtQ2iRXFWT2QedAfttj2FsPIOE1eCOlEuoWWjgzYaB/IkeGOrxXhqB+uA9Bfcm0lAZuh+YIeAD+cAqSz4kCMUAAAAASUVORK5CYII=);
|
||||
}
|
||||
|
||||
&.broken {
|
||||
color: red;
|
||||
}
|
||||
}
|
||||
|
||||
p {
|
||||
|
2
themes/daux_singlepage/css/main.min.css
vendored
2
themes/daux_singlepage/css/main.min.css
vendored
File diff suppressed because one or more lines are too long
Loading…
Reference in New Issue
Block a user