-
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.
* feat: Markdown * feat: Markdown, front matter reader * feat: Markdown, code block highlighting
- Loading branch information
Showing
23 changed files
with
207 additions
and
12 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
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,55 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/* | ||
* This file is part of the yassg project. | ||
* | ||
* (c) sigwin.hr | ||
* | ||
* This source file is subject to the MIT license that is bundled | ||
* with this source code in the file LICENSE. | ||
*/ | ||
|
||
namespace Sigwin\YASSG\Decoder; | ||
|
||
use League\CommonMark\ConverterInterface; | ||
use League\CommonMark\Extension\FrontMatter\FrontMatterProviderInterface; | ||
use Sigwin\YASSG\FileDecoder; | ||
|
||
final class MarkdownFileDecoder implements FileDecoder | ||
{ | ||
use FileDecoderTrait; | ||
|
||
private const EXTENSIONS = ['md', 'markdown']; | ||
|
||
private ConverterInterface $converter; | ||
|
||
public function __construct(ConverterInterface $converter) | ||
{ | ||
$this->converter = $converter; | ||
} | ||
|
||
public function decode(\SplFileInfo $file): array | ||
{ | ||
$path = $file->getRealPath(); | ||
if ($path === false) { | ||
throw new \RuntimeException('Invalid file path'); | ||
} | ||
|
||
$content = file_get_contents($path); | ||
if ($content === false) { | ||
throw new \RuntimeException('Failed to read file'); | ||
} | ||
|
||
$result = $this->converter->convert($content); | ||
$metadata = []; | ||
if ($result instanceof FrontMatterProviderInterface) { | ||
/** @var array<string, string> $metadata */ | ||
$metadata = $result->getFrontMatter(); | ||
} | ||
$metadata['body'] = $result->getContent(); | ||
|
||
return $metadata; | ||
} | ||
} |
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
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,18 @@ | ||
--- | ||
slug: hello-world | ||
--- | ||
# Hello World! | ||
|
||
here I am, writing some Markdown. | ||
|
||
Fine. | ||
|
||
```php{4} | ||
class HelloWorld | ||
{ | ||
public function __construct() | ||
{ | ||
echo 'Hello World!'; | ||
} | ||
} | ||
``` |
This file was deleted.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
35 changes: 35 additions & 0 deletions
35
tests/functional/site/fixtures/en/a/hello-world/index.html
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 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="utf-8"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1"> | ||
<script src="https://cdn.tailwindcss.com?plugins=typography"></script> | ||
|
||
<title>hello-world</title> | ||
|
||
<link rel="stylesheet" href="/sub/dir/another/assets/app.d4da4e7e.css" integrity="sha384-t9qUhz8OfBEKvYdnnNndPZAf+S5Q3p0dBnxLn+5SShoNhInHUF+Bu8WJTo+FQJYJ"> | ||
</head> | ||
<body> | ||
|
||
<main class="min-h-full flex flex-col justify-center py-12 sm:px-6 lg:px-8"> | ||
<div class="mt-8 sm:mx-auto sm:w-full sm:max-w-xl"> | ||
<div class="bg-white py-8 px-4 shadow sm:rounded-lg sm:px-10 prose"> | ||
<h1>Hello World!</h1> | ||
<p>here I am, writing some Markdown.</p> | ||
<p>Fine.</p> | ||
<pre><code class="language-php hljs php" data-lang="php"><span class="loc"><span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">HelloWorld</span></span></span> | ||
<span class="loc"><span class="hljs-class"></span>{</span> | ||
<span class="loc"> <span class="hljs-keyword">public</span> <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">__construct</span><span class="hljs-params">()</span></span></span> | ||
<span class="loc highlighted"><span class="hljs-function"> </span>{</span> | ||
<span class="loc"> <span class="hljs-keyword">echo</span> <span class="hljs-string">'Hello World!'</span>;</span> | ||
<span class="loc"> }</span> | ||
<span class="loc">}</span> | ||
<span class="loc"></span></code></pre> | ||
|
||
</div> | ||
</div> | ||
</main> | ||
|
||
<script src="/sub/dir/another/assets/runtime.4d1205b9.js" integrity="sha384-J2jFm3DPgrcqyvls0fZlS51nUYgiBB+JLwWiU5v7vxEbLwKolmaHrRuz4BjP6qaE"></script><script src="/sub/dir/another/assets/app.9267444a.js" integrity="sha384-WbAUi92ziCGFD1kGZRzpOP8Nxymnw5vXM3szOB1JmBrCU+MVGXBRReCttizXHDdI"></script> | ||
</body> | ||
</html> |
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
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
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,20 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/* | ||
* This file is part of the yassg project. | ||
* | ||
* (c) sigwin.hr | ||
* | ||
* This source file is subject to the MIT license that is bundled | ||
* with this source code in the file LICENSE. | ||
*/ | ||
|
||
namespace Sigwin\YASSG\Test\Functional\Site\Model; | ||
|
||
final class Article | ||
{ | ||
public string $slug; | ||
public string $body; | ||
} |
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,16 @@ | ||
{% extends 'layout.html.twig' %} | ||
|
||
{# query the database #} | ||
{% set article = yassg_find_one_by('articles', {condition: {'item.slug': slug}}) %} | ||
|
||
{% block title %}{{ article.slug }}{% endblock %} | ||
|
||
{% block body %} | ||
<main class="min-h-full flex flex-col justify-center py-12 sm:px-6 lg:px-8"> | ||
<div class="mt-8 sm:mx-auto sm:w-full sm:max-w-xl"> | ||
<div class="bg-white py-8 px-4 shadow sm:rounded-lg sm:px-10 prose"> | ||
{{ article.body|raw }} | ||
</div> | ||
</div> | ||
</main> | ||
{% endblock %} |
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