mirror of
https://github.com/silverstripe/silverstripe-docsviewer
synced 2024-10-22 09:05:56 +00:00
BUGFIX Fixed relative and absolute links
This commit is contained in:
parent
089c844892
commit
e024be8806
@ -232,11 +232,17 @@ class DocumentationEntity extends ViewableData {
|
|||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
public function Link($version = false, $lang = false) {
|
public function Link($version = false, $lang = false) {
|
||||||
|
return Controller::join_links(
|
||||||
|
Director::absoluteBaseURL(),
|
||||||
|
$this->getRelativeLink($version, $lang)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
function getRelativeLink($version = false, $lang = false) {
|
||||||
if(!$version) $version = '';
|
if(!$version) $version = '';
|
||||||
if(!$lang) $lang = 'en';
|
if(!$lang) $lang = 'en';
|
||||||
|
|
||||||
return Controller::join_links(
|
return Controller::join_links(
|
||||||
Director::absoluteBaseURL(),
|
|
||||||
DocumentationViewer::get_link_base(),
|
DocumentationViewer::get_link_base(),
|
||||||
$this->moduleFolder,
|
$this->moduleFolder,
|
||||||
$lang,
|
$lang,
|
||||||
|
@ -248,7 +248,8 @@ class DocumentationParser {
|
|||||||
* @param String $baselink
|
* @param String $baselink
|
||||||
* @return String Markdown
|
* @return String Markdown
|
||||||
*/
|
*/
|
||||||
static function rewrite_relative_links($md, $page, $baselink) {
|
static function rewrite_relative_links($md, $page, $baselink = null) {
|
||||||
|
if(!$baselink) $baselink = $page->getEntity()->getRelativeLink();
|
||||||
|
|
||||||
$re = '/
|
$re = '/
|
||||||
([^\!]?) # exclude image format
|
([^\!]?) # exclude image format
|
||||||
@ -261,12 +262,12 @@ class DocumentationParser {
|
|||||||
/x';
|
/x';
|
||||||
preg_match_all($re, $md, $matches);
|
preg_match_all($re, $md, $matches);
|
||||||
|
|
||||||
// relative path (to module base folder), without the filename
|
// relative path (relative to module base folder), without the filename.
|
||||||
|
// For "sapphire/en/current/topics/templates", this would be "templates"
|
||||||
$relativePath = dirname($page->getRelativePath());
|
$relativePath = dirname($page->getRelativePath());
|
||||||
if($relativePath == '.') $relativePath = '';
|
if($relativePath == '.') $relativePath = '';
|
||||||
|
|
||||||
if($matches) {
|
if($matches) {
|
||||||
|
|
||||||
foreach($matches[0] as $i => $match) {
|
foreach($matches[0] as $i => $match) {
|
||||||
$title = $matches[2][$i];
|
$title = $matches[2][$i];
|
||||||
$url = $matches[3][$i];
|
$url = $matches[3][$i];
|
||||||
@ -278,10 +279,12 @@ class DocumentationParser {
|
|||||||
$urlParts = parse_url($url);
|
$urlParts = parse_url($url);
|
||||||
if($urlParts && isset($urlParts['scheme'])) continue;
|
if($urlParts && isset($urlParts['scheme'])) continue;
|
||||||
|
|
||||||
// Rewrite URL (relative or absolute)
|
// Rewrite URL
|
||||||
if(preg_match('/^\//', $url)) {
|
if(preg_match('/^\//', $url)) {
|
||||||
|
// Absolute: Only path to module base
|
||||||
$relativeUrl = Controller::join_links($baselink, $url);
|
$relativeUrl = Controller::join_links($baselink, $url);
|
||||||
} else {
|
} else {
|
||||||
|
// Relative: Include path to module base and any folders
|
||||||
$relativeUrl = Controller::join_links($baselink, $relativePath, $url);
|
$relativeUrl = Controller::join_links($baselink, $relativePath, $url);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -488,7 +488,7 @@ class DocumentationViewer extends Controller {
|
|||||||
if($page = $this->getPage()) {
|
if($page = $this->getPage()) {
|
||||||
|
|
||||||
// Remove last portion of path (filename), we want a link to the folder base
|
// Remove last portion of path (filename), we want a link to the folder base
|
||||||
$html = DocumentationParser::parse($page, $this->Link(array_slice($this->Remaining, 0)));
|
$html = DocumentationParser::parse($page);
|
||||||
return DBField::create("HTMLText", $html);
|
return DBField::create("HTMLText", $html);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
@ -561,7 +561,6 @@ class DocumentationViewer extends Controller {
|
|||||||
/**
|
/**
|
||||||
* Return the base link to this documentation location
|
* Return the base link to this documentation location
|
||||||
*
|
*
|
||||||
* @todo Make this work on non /dev/
|
|
||||||
* @return String
|
* @return String
|
||||||
*/
|
*/
|
||||||
public function Link($path = false) {
|
public function Link($path = false) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user