mirror of
https://github.com/DirectoryLister/DirectoryLister.git
synced 2025-09-02 02:12:37 +02:00
Initial README parsing support
This commit is contained in:
@@ -3,6 +3,7 @@
|
||||
namespace App\Controllers;
|
||||
|
||||
use DI\Container;
|
||||
use Parsedown;
|
||||
use PHLAK\Config\Config;
|
||||
use Slim\Psr7\Request;
|
||||
use Slim\Psr7\Response;
|
||||
@@ -19,6 +20,9 @@ class DirectoryController
|
||||
/** @var Container Application container */
|
||||
protected $container;
|
||||
|
||||
/** @var Parsedown Parsedown component */
|
||||
protected $parsedown;
|
||||
|
||||
/** @var Twig Twig templating component */
|
||||
protected $view;
|
||||
|
||||
@@ -29,10 +33,15 @@ class DirectoryController
|
||||
* @param \PHLAK\Config\Config $config
|
||||
* @param \Slim\Views\Twig $view
|
||||
*/
|
||||
public function __construct(Container $container, Config $config, Twig $view)
|
||||
{
|
||||
public function __construct(
|
||||
Container $container,
|
||||
Config $config,
|
||||
Parsedown $parsedown,
|
||||
Twig $view
|
||||
) {
|
||||
$this->container = $container;
|
||||
$this->config = $config;
|
||||
$this->parsedown = $parsedown;
|
||||
$this->view = $view;
|
||||
}
|
||||
|
||||
@@ -65,11 +74,20 @@ class DirectoryController
|
||||
$files->depth(0);
|
||||
}
|
||||
|
||||
$readmeFiles = Finder::create()->in($path)->depth(0)->name('/^README\.md$/i');
|
||||
if ($readmeFiles->hasResults() && ! $search) {
|
||||
$readmeArray = iterator_to_array($readmeFiles);
|
||||
$readme = $this->parsedown->parse(
|
||||
array_shift($readmeArray)->getContents()
|
||||
);
|
||||
}
|
||||
|
||||
return $this->view->render($response, 'index.twig', [
|
||||
'breadcrumbs' => $this->breadcrumbs($path),
|
||||
'files' => $files,
|
||||
'is_root' => $this->isRoot($path),
|
||||
'search' => $search ?? null,
|
||||
'readme' => $readme ?? null,
|
||||
]);
|
||||
}
|
||||
|
||||
|
@@ -49,4 +49,11 @@ return [
|
||||
* Defualt value: 1000000000
|
||||
*/
|
||||
'max_hash_size' => Helpers::env('MAX_HASH_SIZE'),
|
||||
|
||||
/**
|
||||
* Parse and render README files inline.
|
||||
*
|
||||
* Default value: true
|
||||
*/
|
||||
'render_readme' => Helpers::env('RENDER_README', true),
|
||||
];
|
||||
|
@@ -12,4 +12,5 @@ $fa-font-path: "./webfonts";
|
||||
// Fonts
|
||||
@import url("https://fonts.googleapis.com/css?family=Work+Sans:200,400&display=swap");
|
||||
|
||||
@import "markdown.scss";
|
||||
@import "dark-mode.scss";
|
||||
|
104
app/resources/sass/markdown.scss
Normal file
104
app/resources/sass/markdown.scss
Normal file
@@ -0,0 +1,104 @@
|
||||
.markdown {
|
||||
@apply font-sans;
|
||||
|
||||
a {
|
||||
@apply text-blue-600;
|
||||
@apply underline;
|
||||
|
||||
&:hover {
|
||||
@apply text-blue-800;
|
||||
}
|
||||
}
|
||||
|
||||
p,
|
||||
blockquote,
|
||||
ul,
|
||||
ol,
|
||||
dl,
|
||||
table,
|
||||
pre {
|
||||
@apply my-4;
|
||||
}
|
||||
|
||||
ul,
|
||||
ol {
|
||||
@apply pl-8;
|
||||
}
|
||||
|
||||
ul {
|
||||
@apply list-disc;
|
||||
}
|
||||
|
||||
ol {
|
||||
@apply list-decimal;
|
||||
}
|
||||
|
||||
h1 {
|
||||
@apply text-4xl;
|
||||
@apply border-b;
|
||||
@apply border-gray-400;
|
||||
}
|
||||
|
||||
h2 {
|
||||
@apply text-3xl;
|
||||
@apply border-b;
|
||||
@apply border-gray-400;
|
||||
}
|
||||
|
||||
h3 {
|
||||
@apply text-2xl;
|
||||
}
|
||||
|
||||
h4 {
|
||||
@apply text-xl;
|
||||
}
|
||||
|
||||
h5 {
|
||||
@apply text-base;
|
||||
}
|
||||
|
||||
h6 {
|
||||
@apply text-base;
|
||||
@apply text-gray-600;
|
||||
}
|
||||
|
||||
h1,
|
||||
h2,
|
||||
h3,
|
||||
h4,
|
||||
h5,
|
||||
h6 {
|
||||
@apply font-bold;
|
||||
@apply leading-relaxed;
|
||||
@apply mt-8;
|
||||
@apply mb-4;
|
||||
}
|
||||
|
||||
h1 + p,
|
||||
h2 + p,
|
||||
h3 + p {
|
||||
@apply mt-4;
|
||||
}
|
||||
|
||||
pre {
|
||||
@apply bg-gray-200;
|
||||
@apply rounded-sm;
|
||||
@apply p-4;
|
||||
@apply font-mono;
|
||||
@apply text-sm;
|
||||
@apply whitespace-pre;
|
||||
}
|
||||
|
||||
hr {
|
||||
@apply border-t-2;
|
||||
@apply border-gray-400;
|
||||
}
|
||||
|
||||
& > :first-child {
|
||||
@apply mt-0;
|
||||
}
|
||||
|
||||
& > :last-child {
|
||||
@apply mb-0;
|
||||
}
|
||||
}
|
@@ -29,6 +29,18 @@
|
||||
{{ include('components/file.twig') }}
|
||||
{% endfor %}
|
||||
</ul>
|
||||
|
||||
{% if readme %}
|
||||
<div id="readme" class="rounded-lg overflow-hidden shadow-md my-12">
|
||||
<div class="flex items-center bg-blue-600 px-4 py-3 text-white">
|
||||
<i class="fab fa-readme fa-lg pr-3"></i> README.md
|
||||
</div>
|
||||
|
||||
<article class="bg-gray-100 border rounded-b-lg px-12 py-8 markdown">
|
||||
{{ readme | raw }}
|
||||
</article>
|
||||
</div>
|
||||
{% endif %}
|
||||
</div>
|
||||
|
||||
{% include 'components/footer.twig' %}
|
||||
|
@@ -11,6 +11,7 @@
|
||||
],
|
||||
"require": {
|
||||
"php": ">=7.1",
|
||||
"erusev/parsedown": "^1.7",
|
||||
"phlak/config": "^6.0",
|
||||
"php-di/php-di": "^6.0",
|
||||
"php-di/slim-bridge": "^3.0",
|
||||
|
48
composer.lock
generated
48
composer.lock
generated
@@ -4,8 +4,54 @@
|
||||
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
|
||||
"This file is @generated automatically"
|
||||
],
|
||||
"content-hash": "ee34e3c83048ffcba5f28c84ad5d06b4",
|
||||
"content-hash": "b8d61605ee4f40b6ef5db770276ac304",
|
||||
"packages": [
|
||||
{
|
||||
"name": "erusev/parsedown",
|
||||
"version": "1.7.4",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/erusev/parsedown.git",
|
||||
"reference": "cb17b6477dfff935958ba01325f2e8a2bfa6dab3"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/erusev/parsedown/zipball/cb17b6477dfff935958ba01325f2e8a2bfa6dab3",
|
||||
"reference": "cb17b6477dfff935958ba01325f2e8a2bfa6dab3",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
"ext-mbstring": "*",
|
||||
"php": ">=5.3.0"
|
||||
},
|
||||
"require-dev": {
|
||||
"phpunit/phpunit": "^4.8.35"
|
||||
},
|
||||
"type": "library",
|
||||
"autoload": {
|
||||
"psr-0": {
|
||||
"Parsedown": ""
|
||||
}
|
||||
},
|
||||
"notification-url": "https://packagist.org/downloads/",
|
||||
"license": [
|
||||
"MIT"
|
||||
],
|
||||
"authors": [
|
||||
{
|
||||
"name": "Emanuil Rusev",
|
||||
"email": "hello@erusev.com",
|
||||
"homepage": "http://erusev.com"
|
||||
}
|
||||
],
|
||||
"description": "Parser for Markdown.",
|
||||
"homepage": "http://parsedown.org",
|
||||
"keywords": [
|
||||
"markdown",
|
||||
"parser"
|
||||
],
|
||||
"time": "2019-12-30T22:54:17+00:00"
|
||||
},
|
||||
{
|
||||
"name": "fig/http-message-util",
|
||||
"version": "1.1.3",
|
||||
|
Reference in New Issue
Block a user