-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0e9cc22
commit a74a837
Showing
6 changed files
with
158 additions
and
128 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,6 +18,8 @@ | |
use StaticSiteGenerator\Steps\ProcessMarkdownStep; | ||
use StaticSiteGenerator\Steps\ProcessTwigStep; | ||
use StaticSiteGenerator\Steps\WriteFilesStep; | ||
use StaticSiteGenerator\Support\MarkdownConverterFactory; | ||
use StaticSiteGenerator\Support\TwigEnvironmentFactory; | ||
use StaticSiteGenerator\ValueObjects\SiteMetadata; | ||
|
||
final readonly class StaticSiteGenerator | ||
|
@@ -28,27 +30,20 @@ public function __construct( | |
private string $inputDirectory, | ||
private string $outputDirectory, | ||
) { | ||
$releaseTimestamp = getenv('RELEASE_TIMESTAMP') ?: (new \DateTimeImmutable())->format('YmdHis'); | ||
|
||
$siteMetadata = new SiteMetadata( | ||
[ | ||
'author' => 'Damien Dart', | ||
'authorEmail' => '[email protected]', | ||
'metaTwitterAuthor' => '@damiendart', | ||
'metaTwitterSite' => '@damiendart', | ||
'metaOpengraphImage' => "https://www.robotinaponcho.net/assets/opengraph.{$releaseTimestamp}.png", | ||
'releaseTimestamp' => $releaseTimestamp, | ||
'urlBase' => 'https://www.robotinaponcho.net/', | ||
], | ||
); | ||
$markdownConverterFactory = new MarkdownConverterFactory(); | ||
$siteMetadata = new SiteMetadata(); | ||
|
||
$this->pipeline = new Pipeline( | ||
new ProcessFrontMatterStep(), | ||
new GenerateSlugsStep(), | ||
new GenerateCollectionsStep($siteMetadata), | ||
new GenerateSitemapEntriesStep($siteMetadata), | ||
new ProcessMarkdownStep(), | ||
new ProcessTwigStep($this->inputDirectory, $siteMetadata), | ||
new ProcessMarkdownStep($markdownConverterFactory), | ||
new ProcessTwigStep( | ||
$this->inputDirectory, | ||
$siteMetadata, | ||
new TwigEnvironmentFactory($markdownConverterFactory), | ||
), | ||
new MinifyHtmlStep(), | ||
new WriteFilesStep($this->outputDirectory), | ||
); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
<?php | ||
|
||
/* | ||
* Copyright (C) Damien Dart, <[email protected]>. | ||
* This file is distributed under the MIT licence. For more information, | ||
* please refer to the accompanying "LICENCE" file. | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace StaticSiteGenerator\Support; | ||
|
||
use League\CommonMark\ConverterInterface; | ||
use League\CommonMark\Environment\Environment; | ||
use League\CommonMark\Extension\CommonMark\CommonMarkCoreExtension; | ||
use League\CommonMark\Extension\DescriptionList\DescriptionListExtension; | ||
use League\CommonMark\Extension\SmartPunct\SmartPunctExtension; | ||
use League\CommonMark\Extension\Table\TableExtension; | ||
use League\CommonMark\MarkdownConverter; | ||
|
||
final class MarkdownConverterFactory | ||
{ | ||
public function make(): ConverterInterface | ||
{ | ||
$environment = new Environment(); | ||
|
||
$environment | ||
->addExtension(new CommonMarkCoreExtension()) | ||
->addExtension(new DescriptionListExtension()) | ||
->addExtension(new SmartPunctExtension()) | ||
->addExtension(new TableExtension()); | ||
|
||
return new MarkdownConverter($environment); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
<?php | ||
|
||
/* | ||
* Copyright (C) Damien Dart, <[email protected]>. | ||
* This file is distributed under the MIT licence. For more information, | ||
* please refer to the accompanying "LICENCE" file. | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace StaticSiteGenerator\Support; | ||
|
||
use Michelf\SmartyPantsTypographer; | ||
use Twig\Environment; | ||
use Twig\Loader\LoaderInterface; | ||
use Twig\TwigFilter; | ||
|
||
final readonly class TwigEnvironmentFactory | ||
{ | ||
public function __construct( | ||
private MarkdownConverterFactory $markdownConverterFactory, | ||
) {} | ||
|
||
public function make(LoaderInterface $loader): Environment | ||
{ | ||
$environment = new Environment( | ||
$loader, | ||
['strict_variables' => true], | ||
); | ||
|
||
$environment->addFilter(new TwigFilter('dedent', 'StaticSiteGenerator\dedent')); | ||
|
||
$environment->addFilter( | ||
new TwigFilter( | ||
'markdown', | ||
function (string $string): string { | ||
$converter = $this->markdownConverterFactory->make(); | ||
|
||
return $converter | ||
->convert($string) | ||
->getContent(); | ||
}, | ||
['is_safe' => ['html']], | ||
), | ||
); | ||
|
||
$environment->addFilter( | ||
new TwigFilter( | ||
'smartypants', | ||
[SmartyPantsTypographer::class, 'defaultTransform'], | ||
['is_safe' => ['html']], | ||
), | ||
); | ||
|
||
$environment->addFilter( | ||
new TwigFilter( | ||
'widont', | ||
static function (?string $string): string { | ||
$string ??= ''; | ||
|
||
if (str_word_count($string) < 4) { | ||
return $string; | ||
} | ||
|
||
if ( | ||
mb_strlen( | ||
join( | ||
' ', | ||
\array_slice( | ||
explode(' ', $string), | ||
-2, | ||
), | ||
), | ||
) > 14 | ||
) { | ||
return $string; | ||
} | ||
|
||
return preg_replace( | ||
'/\s+(\S+)$/', | ||
' $1', | ||
rtrim($string), | ||
); | ||
}, | ||
['is_safe' => ['html']], | ||
), | ||
); | ||
|
||
return $environment; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,7 +12,20 @@ | |
|
||
final class SiteMetadata | ||
{ | ||
public function __construct( | ||
public array $metadata, | ||
) {} | ||
public array $metadata; | ||
|
||
public function __construct() | ||
{ | ||
$releaseTimestamp = getenv('RELEASE_TIMESTAMP') ?: (new \DateTimeImmutable())->format('YmdHis'); | ||
|
||
$this->metadata = [ | ||
'author' => 'Damien Dart', | ||
'authorEmail' => '[email protected]', | ||
'metaTwitterAuthor' => '@damiendart', | ||
'metaTwitterSite' => '@damiendart', | ||
'metaOpengraphImage' => "https://www.robotinaponcho.net/assets/opengraph.{$releaseTimestamp}.png", | ||
'releaseTimestamp' => $releaseTimestamp, | ||
'urlBase' => 'https://www.robotinaponcho.net/', | ||
]; | ||
} | ||
} |