mirror of
https://github.com/silverstripe/silverstripe-docsviewer
synced 2024-10-22 11:05:56 +02:00
FIX: Relative paths from index files showing wrong
This commit is contained in:
parent
ecac89c0c7
commit
113e997b09
@ -385,10 +385,20 @@ class DocumentationParser {
|
||||
// For "sapphire/en/current/topics/templates", this would be "templates"
|
||||
$relativePath = dirname($page->getRelativePath());
|
||||
|
||||
if(strpos($page->getRelativePath(), 'index.md')) {
|
||||
$relativeLink = $page->getRelativeLink();
|
||||
} else {
|
||||
$relativeLink = dirname($page->getRelativeLink());
|
||||
}
|
||||
|
||||
if($relativePath == '.') {
|
||||
$relativePath = '';
|
||||
}
|
||||
|
||||
if($relativeLink == ".") {
|
||||
$relativeLink = '';
|
||||
}
|
||||
|
||||
// file base link
|
||||
$fileBaseLink = Director::makeRelative(dirname($page->getPath()));
|
||||
|
||||
@ -416,10 +426,10 @@ class DocumentationParser {
|
||||
// Rewrite public URL
|
||||
if(preg_match('/^\//', $url)) {
|
||||
// Absolute: Only path to module base
|
||||
$relativeUrl = Controller::join_links($baselink, $url);
|
||||
$relativeUrl = Controller::join_links($baselink, $url, '/');
|
||||
} else {
|
||||
// Relative: Include path to module base and any folders
|
||||
$relativeUrl = Controller::join_links($baselink, $relativePath, $url);
|
||||
$relativeUrl = Controller::join_links($baselink, $relativeLink, $url, '/');
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -6,7 +6,7 @@
|
||||
*/
|
||||
class DocumentationParserTest extends SapphireTest {
|
||||
|
||||
protected $entity, $entityAlt, $page, $subPage, $subSubPage, $filePage, $metaDataPage;
|
||||
protected $entity, $entityAlt, $page, $subPage, $subSubPage, $filePage, $metaDataPage, $indexPage;
|
||||
|
||||
public function tearDown() {
|
||||
parent::tearDown();
|
||||
@ -65,9 +65,120 @@ class DocumentationParserTest extends SapphireTest {
|
||||
DOCSVIEWER_PATH . '/tests/docs-parser/en/MetaDataTest.md'
|
||||
);
|
||||
|
||||
$this->indexPage = new DocumentationPage(
|
||||
$this->entity,
|
||||
'index.md',
|
||||
DOCSVIEWER_PATH. '/tests/docs/en/index.md'
|
||||
);
|
||||
|
||||
$manifest = new DocumentationManifest(true);
|
||||
}
|
||||
|
||||
public function testRelativeLinks() {
|
||||
// index.md
|
||||
$result = DocumentationParser::rewrite_relative_links(
|
||||
$this->indexPage->getMarkdown(),
|
||||
$this->indexPage
|
||||
);
|
||||
|
||||
$this->assertContains(
|
||||
'[link: subfolder index](dev/docs/en/documentationparsertest/2.4/subfolder/)',
|
||||
$result
|
||||
);
|
||||
|
||||
// test.md
|
||||
|
||||
$result = DocumentationParser::rewrite_relative_links(
|
||||
$this->page->getMarkdown(),
|
||||
$this->page
|
||||
);
|
||||
|
||||
$this->assertContains(
|
||||
'[link: subfolder index](dev/docs/en/documentationparsertest/2.4/subfolder/)',
|
||||
$result
|
||||
);
|
||||
$this->assertContains(
|
||||
'[link: subfolder page](dev/docs/en/documentationparsertest/2.4/subfolder/subpage/)',
|
||||
$result
|
||||
);
|
||||
$this->assertContains(
|
||||
'[link: http](http://silverstripe.org)',
|
||||
$result
|
||||
);
|
||||
$this->assertContains(
|
||||
'[link: api](api:DataObject)',
|
||||
$result
|
||||
);
|
||||
|
||||
|
||||
$result = DocumentationParser::rewrite_relative_links(
|
||||
$this->subPage->getMarkdown(),
|
||||
$this->subPage
|
||||
);
|
||||
|
||||
# @todo this should redirect to /subpage/
|
||||
$this->assertContains(
|
||||
'[link: relative](dev/docs/en/documentationparsertest/2.4/subfolder/subpage.md/)',
|
||||
$result
|
||||
);
|
||||
|
||||
$this->assertContains(
|
||||
'[link: absolute index](dev/docs/en/documentationparsertest/2.4/)',
|
||||
$result
|
||||
);
|
||||
|
||||
# @todo this should redirect to /
|
||||
$this->assertContains(
|
||||
'[link: absolute index with name](dev/docs/en/documentationparsertest/2.4/index/)',
|
||||
$result
|
||||
);
|
||||
|
||||
$this->assertContains(
|
||||
'[link: relative index](dev/docs/en/documentationparsertest/2.4/)',
|
||||
$result
|
||||
);
|
||||
|
||||
$this->assertContains(
|
||||
'[link: relative parent page](dev/docs/en/documentationparsertest/2.4/test/)',
|
||||
$result
|
||||
);
|
||||
|
||||
$this->assertContains(
|
||||
'[link: absolute parent page](dev/docs/en/documentationparsertest/2.4/test/)',
|
||||
$result
|
||||
);
|
||||
|
||||
$result = DocumentationParser::rewrite_relative_links(
|
||||
$this->subSubPage->getMarkdown(),
|
||||
$this->subSubPage
|
||||
);
|
||||
|
||||
$this->assertContains(
|
||||
'[link: absolute index](dev/docs/en/documentationparsertest/2.4/)',
|
||||
$result
|
||||
);
|
||||
|
||||
$this->assertContains(
|
||||
'[link: relative index](dev/docs/en/documentationparsertest/2.4/subfolder/)',
|
||||
$result
|
||||
);
|
||||
|
||||
$this->assertContains(
|
||||
'[link: relative parent page](dev/docs/en/documentationparsertest/2.4/subfolder/subpage/)',
|
||||
$result
|
||||
);
|
||||
|
||||
$this->assertContains(
|
||||
'[link: relative grandparent page](dev/docs/en/documentationparsertest/2.4/test/)',
|
||||
$result
|
||||
);
|
||||
|
||||
$this->assertContains(
|
||||
'[link: absolute page](dev/docs/en/documentationparsertest/2.4/test/)',
|
||||
$result
|
||||
);
|
||||
}
|
||||
|
||||
public function testGenerateHtmlId() {
|
||||
$this->assertEquals('title-one', DocumentationParser::generate_html_id('title one'));
|
||||
$this->assertEquals('title-one', DocumentationParser::generate_html_id('Title one'));
|
||||
@ -207,92 +318,7 @@ HTML;
|
||||
|
||||
}
|
||||
|
||||
public function testRelativeLinks() {
|
||||
$result = DocumentationParser::rewrite_relative_links(
|
||||
$this->page->getMarkdown(),
|
||||
$this->page
|
||||
);
|
||||
|
||||
$this->assertContains(
|
||||
'[link: subfolder index](dev/docs/en/documentationparsertest/2.4/subfolder/)',
|
||||
$result
|
||||
);
|
||||
$this->assertContains(
|
||||
'[link: subfolder page](dev/docs/en/documentationparsertest/2.4/subfolder/subpage)',
|
||||
$result
|
||||
);
|
||||
$this->assertContains(
|
||||
'[link: http](http://silverstripe.org)',
|
||||
$result
|
||||
);
|
||||
$this->assertContains(
|
||||
'[link: api](api:DataObject)',
|
||||
$result
|
||||
);
|
||||
|
||||
$result = DocumentationParser::rewrite_relative_links(
|
||||
$this->subPage->getMarkdown(),
|
||||
$this->subPage
|
||||
);
|
||||
|
||||
$this->assertContains(
|
||||
'[link: relative](dev/docs/en/documentationparsertest/2.4/subfolder/subpage.md)',
|
||||
$result
|
||||
);
|
||||
|
||||
$this->assertContains(
|
||||
'[link: absolute index](dev/docs/en/documentationparsertest/2.4/)',
|
||||
$result
|
||||
);
|
||||
$this->assertContains(
|
||||
'[link: absolute index with name](dev/docs/en/documentationparsertest/2.4/index)',
|
||||
$result
|
||||
);
|
||||
$this->assertContains(
|
||||
'[link: relative index](dev/docs/en/documentationparsertest/2.4/)',
|
||||
$result
|
||||
);
|
||||
|
||||
$this->assertContains(
|
||||
'[link: relative parent page](dev/docs/en/documentationparsertest/2.4/test)',
|
||||
$result
|
||||
);
|
||||
|
||||
$this->assertContains(
|
||||
'[link: absolute parent page](dev/docs/en/documentationparsertest/2.4/test)',
|
||||
$result
|
||||
);
|
||||
|
||||
$result = DocumentationParser::rewrite_relative_links(
|
||||
$this->subSubPage->getMarkdown(),
|
||||
$this->subSubPage
|
||||
);
|
||||
|
||||
$this->assertContains(
|
||||
'[link: absolute index](dev/docs/en/documentationparsertest/2.4/)',
|
||||
$result
|
||||
);
|
||||
|
||||
$this->assertContains(
|
||||
'[link: relative index](dev/docs/en/documentationparsertest/2.4/subfolder/)',
|
||||
$result
|
||||
);
|
||||
|
||||
$this->assertContains(
|
||||
'[link: relative parent page](dev/docs/en/documentationparsertest/2.4/subfolder/subpage)',
|
||||
$result
|
||||
);
|
||||
|
||||
$this->assertContains(
|
||||
'[link: relative grandparent page](dev/docs/en/documentationparsertest/2.4/test)',
|
||||
$result
|
||||
);
|
||||
|
||||
$this->assertContains(
|
||||
'[link: absolute page](dev/docs/en/documentationparsertest/2.4/test)',
|
||||
$result
|
||||
);
|
||||
}
|
||||
|
||||
public function testRetrieveMetaData() {
|
||||
DocumentationParser::retrieve_meta_data($this->metaDataPage);
|
||||
|
Loading…
Reference in New Issue
Block a user