Skip to content

Commit 9a7168a

Browse files
authored
Merge pull request #6 from librarianphp/custom-index-tpl
Add custom index template config option
2 parents 94a1386 + a217548 commit 9a7168a

File tree

5 files changed

+9
-6
lines changed

5 files changed

+9
-6
lines changed

src/StaticBuilder.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,11 @@ public function getIndexPage(): string
7070
$indexPage = null;
7171

7272
if ($this->siteConfig->site_index !== null) {
73+
$pageTpl = $this->siteConfig->site_index_tpl ?? 'content/single.html.twig';
7374
$page = $this->contentProvider->fetch($this->siteConfig->site_index);
74-
$indexPage = $this->getSinglePage($page);
75+
$indexPage = $this->twigServiceProvider->render($pageTpl, [
76+
'content' => $page,
77+
]);
7578
}
7679

7780
if ($indexPage === null) {

tests/Feature/CommandTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,4 @@
88
test('command "build" calls methods from StaticBuilder', function () {
99
$app = getLibrarian();
1010
$app->runCommand(['minicli', 'build']);
11-
})->expectOutputRegex("/Finished building static website/");
11+
})->expectOutputRegex("/Finished building static website/");

tests/Pest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ function getCustomIndexPageApp(): App
9090
{
9191
$config = getDefaultAppConfig();
9292
$config['site_index'] = 'posts/test0';
93+
$config['site_index_tpl'] = 'content/index.html.twig';
9394

9495
$app = new App($config);
9596
$app->addService('builder', new StaticBuilder());
@@ -100,4 +101,3 @@ function getCustomIndexPageApp(): App
100101

101102
return $app;
102103
}
103-
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
template index

tests/Unit/StaticBuilderTest.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
use Librarian\Provider\TwigServiceProvider;
77
use Minicli\App;
88

9-
beforeEach(function() {
9+
beforeEach(function () {
1010
$app = new App(getDefaultAppConfig());
1111
$app->addService('builder', new StaticBuilder());
1212
$app->addService('twig', new TwigServiceProvider());
@@ -46,7 +46,7 @@
4646
expect(is_file($app->builder->outputPath . '/index.html'))->toBeTrue();
4747

4848
$content = file_get_contents($app->builder->outputPath . '/index.html');
49-
expect($content)->toMatch("/template single/");
49+
expect($content)->toMatch("/template index/");
5050
});
5151

5252
test('StaticBuilder builds paginated tag pages', function () {
@@ -70,4 +70,3 @@
7070
$builder->cleanUp();
7171
expect(is_file($builder->outputPath . '/index.html'))->toBeFalse();
7272
});
73-

0 commit comments

Comments
 (0)