Skip to content

Commit

Permalink
Merge pull request #156 from NaokiTsuchiya/issue/155
Browse files Browse the repository at this point in the history
Set ALPS profile title to the title element of index.html
  • Loading branch information
koriym authored May 28, 2022
2 parents 4fd7b61 + a9d5615 commit 64f0f3d
Show file tree
Hide file tree
Showing 8 changed files with 84 additions and 43 deletions.
4 changes: 2 additions & 2 deletions docs/blog/index.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<html lang="en">
<head>
<title>ALPS</title>
<title>ALPS Blog</title>
<meta charset="UTF-8">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/github-markdown-css/3.0.1/github-markdown.min.css">
<style>
Expand Down Expand Up @@ -59,4 +59,4 @@ <h1>ALPS Blog</h1>

</div>
</body>
</html>
</html>
2 changes: 1 addition & 1 deletion docs/blog/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,4 @@ An ALPS profile example for ASD
* [collection](docs/tag.collection.md)
* [item](docs/tag.item.md)
* Links
* rel: issue <a rel="issue" href="https://github.com/alps-asd/app-state-diagram/issues">https://github.com/alps-asd/app-state-diagram/issues</a>
* rel: issue <a rel="issue" href="https://github.com/alps-asd/app-state-diagram/issues">https://github.com/alps-asd/app-state-diagram/issues</a>
2 changes: 1 addition & 1 deletion docs/filter/index.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<html lang="en">
<head>
<title>ALPS</title>
<title>ALPS example</title>
<meta charset="UTF-8">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/github-markdown-css/3.0.1/github-markdown.min.css">
<style>
Expand Down
70 changes: 35 additions & 35 deletions docs/filter/tag_profile.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion docs/todomvc/index.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<html lang="en">
<head>
<title>ALPS</title>
<title>MVC ToDo List</title>
<meta charset="UTF-8">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/github-markdown-css/3.0.1/github-markdown.min.css">
<style>
Expand Down
4 changes: 2 additions & 2 deletions src/IndexPage.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public function __construct(Profile $profile, string $mode = DumpDocs::MODE_HTML
$ext = $mode === DumpDocs::MODE_MARKDOWN ? 'md' : DumpDocs::MODE_HTML;
$semantics = $this->semantics($descriptors, $ext);
$tags = $this->tags($profile->tags, $ext);
$htmlTitle = htmlspecialchars($profile->title);
$htmlTitle = htmlspecialchars($profile->title ?: 'ALPS');
$htmlDoc = nl2br(htmlspecialchars($profile->doc));
$profileImage = $mode === DumpDocs::MODE_HTML ? 'docs/asd.html' : 'profile.svg';
$md = <<<EOT
Expand All @@ -57,7 +57,7 @@ public function __construct(Profile $profile, string $mode = DumpDocs::MODE_HTML
{$semantics}{$tags}{$linkRelations}
EOT;
$this->file = sprintf('%s/index.%s', dirname($profile->alpsFile), $ext);
$this->content = $mode === DumpDocs::MODE_MARKDOWN ? $md : (new MdToHtml())('ALPS', $md);
$this->content = $mode === DumpDocs::MODE_MARKDOWN ? $md : (new MdToHtml())($htmlTitle, $md);
}

/**
Expand Down
7 changes: 7 additions & 0 deletions tests/Fake/title.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"$schema": "https://alps-io.github.io/schemas/alps.json",
"alps": {
"title": "Title",
"descriptor": []
}
}
36 changes: 35 additions & 1 deletion tests/IndexPageTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,13 @@ public function testInvoke(): string
return $html;
}

public function testInvokeMarkdownMode(): void
public function testInvokeMarkdownMode(): string
{
$alpsFile = __DIR__ . '/Fake/alps.json';
$content = (new IndexPage(new Profile($alpsFile, new LabelName()), DumpDocs::MODE_MARKDOWN))->content;
$this->assertStringContainsString('[About](docs/semantic.About.md) (semantic)', $content);

return $content;
}

/**
Expand Down Expand Up @@ -77,4 +79,36 @@ public function testMultipleLinkRelationsString(): void
$this->assertStringContainsString('<li>rel: about <a rel="about" href="https://github.com/alps-asd/app-state-diagram/">https://github.com/alps-asd/app-state-diagram/</a></li>', $html);
$this->assertStringContainsString('<li>rel: repository <a rel="repository" href="https://github.com/alps-asd/app-state-diagram/">https://github.com/alps-asd/app-state-diagram/</a></li>', $html);
}

public function testTitle(): void
{
$alpsFile = __DIR__ . '/Fake/title.json';
$html = (new IndexPage(new Profile($alpsFile, new LabelName())))->content;

$this->assertStringContainsString('<title>Title</title>', $html);
}

public function testTitleMarkdownMode(): void
{
$alpsFile = __DIR__ . '/Fake/title.json';
$content = (new IndexPage(new Profile($alpsFile, new LabelName()), DumpDocs::MODE_MARKDOWN))->content;

$this->assertStringContainsString('# Title', $content);
}

/**
* @depends testInvoke
*/
public function testNoTitle(string $content): void
{
$this->assertStringContainsString('<title>ALPS</title>', $content);
}

/**
* @depends testInvokeMarkdownMode
*/
public function testNoTitleMarkdownMode(string $content): void
{
$this->assertStringContainsString('# ALPS', $content);
}
}

0 comments on commit 64f0f3d

Please sign in to comment.