|
7 | 7 | } |
8 | 8 |
|
9 | 9 | return function (Pimple\Container $container) { |
| 10 | + $container['markdown.cache'] = function () { |
| 11 | + return new Symfony\Component\Cache\Adapter\FilesystemAdapter( |
| 12 | + 'markdown', |
| 13 | + 0, |
| 14 | + __DIR__ . '/../tmp/cache' |
| 15 | + ); |
| 16 | + }; |
| 17 | + |
10 | 18 | $container['data.components'] = function (Pimple\Container $container) { |
11 | 19 | return React\Website\Data\components($container['github.client']); |
12 | 20 | }; |
|
78 | 86 | }; |
79 | 87 | }); |
80 | 88 |
|
| 89 | + $container['markdown.renderer'] = $container->extend('markdown.renderer', function (callable $renderer, Pimple\Container $container) { |
| 90 | + return function ( |
| 91 | + string $content, |
| 92 | + Berti\Document $document, |
| 93 | + array $documentCollection, |
| 94 | + array $assetCollection |
| 95 | + ) use ($renderer, $container) { |
| 96 | + /** @var \Psr\Cache\CacheItemPoolInterface $cache */ |
| 97 | + $cache = $container['markdown.cache']; |
| 98 | + |
| 99 | + $repository = $container['github.repository_detector'](dirname($document->input->getRealPath())) ?: null; |
| 100 | + |
| 101 | + $cacheKey = 'markdown' . md5($repository . $content); |
| 102 | + |
| 103 | + $cacheItem = $cache->getItem($cacheKey); |
| 104 | + |
| 105 | + if ($cacheItem->isHit()) { |
| 106 | + return $cacheItem->get(); |
| 107 | + } |
| 108 | + |
| 109 | + $html = $renderer( |
| 110 | + $content, |
| 111 | + $document, |
| 112 | + $documentCollection, |
| 113 | + $assetCollection |
| 114 | + ); |
| 115 | + |
| 116 | + $cacheItem->set($html); |
| 117 | + $cache->save($cacheItem); |
| 118 | + |
| 119 | + return $html; |
| 120 | + }; |
| 121 | + }); |
| 122 | + |
81 | 123 | $container['template.renderer'] = $container->extend('template.renderer', function (callable $renderer, Pimple\Container $container) { |
82 | 124 | return function (string $name, array $context = []) use ($renderer, $container) { |
83 | 125 | return React\Website\Berti\template_renderer( |
|
0 commit comments