mirror of
https://github.com/getgrav/grav.git
synced 2026-02-10 16:47:49 +01:00
only add language prefix for links, not images.
This commit is contained in:
@@ -111,6 +111,7 @@ trait ParsedownGravTrait
|
||||
$excerpt['extent'] = $excerpt['extent'] + strlen($matches[1]) - 1;
|
||||
return $excerpt;
|
||||
} else {
|
||||
$excerpt['type'] = 'image';
|
||||
$excerpt = parent::inlineImage($excerpt);
|
||||
}
|
||||
|
||||
@@ -186,6 +187,12 @@ trait ParsedownGravTrait
|
||||
|
||||
protected function inlineLink($excerpt)
|
||||
{
|
||||
if (isset($excerpt['type'])) {
|
||||
$type = $excerpt['type'];
|
||||
} else {
|
||||
$type = 'link';
|
||||
}
|
||||
|
||||
// do some trickery to get around Parsedown requirement for valid URL if its Twig in there
|
||||
if (preg_match($this->twig_link_regex, $excerpt['text'], $matches)) {
|
||||
$excerpt['text'] = str_replace($matches[1], '/', $excerpt['text']);
|
||||
@@ -204,7 +211,7 @@ trait ParsedownGravTrait
|
||||
// if there is no scheme, the file is local
|
||||
if (!isset($url['scheme']) && (count($url) > 0)) {
|
||||
// convert the URl is required
|
||||
$excerpt['element']['attributes']['href'] = Uri::convertUrl($this->page, Uri::buildUrl($url));
|
||||
$excerpt['element']['attributes']['href'] = Uri::convertUrl($this->page, Uri::buildUrl($url), $type);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -482,12 +482,20 @@ class Uri
|
||||
*
|
||||
* @return string the more friendly formatted url
|
||||
*/
|
||||
public static function convertUrl(Page $page, $markdown_url)
|
||||
public static function convertUrl(Page $page, $markdown_url, $type = 'link')
|
||||
{
|
||||
$grav = Grav::instance();
|
||||
|
||||
// Link processing should prepend language
|
||||
$language_append = '';
|
||||
if ($type == 'link') {
|
||||
$active_language = $grav['language']->getActive();
|
||||
$language_append = $active_language ? '/'.$active_language : '';
|
||||
}
|
||||
|
||||
|
||||
$pages_dir = $grav['locator']->findResource('page://');
|
||||
$base_url = rtrim($grav['base_url'] . $grav['pages']->base(), '/');
|
||||
$base_url = rtrim($grav['base_url'] . $grav['pages']->base(), '/') . $language_append;
|
||||
|
||||
// if absolute and starts with a base_url move on
|
||||
if (pathinfo($markdown_url, PATHINFO_DIRNAME) == '.' && $page->url() == '/') {
|
||||
|
||||
Reference in New Issue
Block a user