diff --git a/app/Http/Controllers/PluginController.php b/app/Http/Controllers/PluginController.php index 6dc65708..de8de735 100644 --- a/app/Http/Controllers/PluginController.php +++ b/app/Http/Controllers/PluginController.php @@ -24,6 +24,25 @@ class PluginController extends Controller } } + public function readme(PluginManager $plugins, $name) + { + $plugin = $plugins->get($name); + if (empty($plugin)) { + return abort(404, trans('admin.plugins.operations.no-readme-notice')); + } + + $readmePath = $plugin->getReadme(); + if (empty($readmePath)) { + return abort(404, trans('admin.plugins.operations.no-readme-notice')); + } + + $title = $plugin->title; + $path = $plugin->getPath().'/'.$readmePath; + $content = resolve('parsedown')->text(file_get_contents($path)); + + return view('admin.plugin.readme', compact('content', 'title')); + } + public function manage(Request $request, PluginManager $plugins) { $name = $request->input('name'); @@ -95,6 +114,7 @@ class PluginController extends Controller 'version' => $plugin->version, 'url' => $plugin->url, 'enabled' => $plugin->isEnabled(), + 'readme' => (bool) $plugin->getReadme(), 'config' => $plugin->hasConfig(), 'dependencies' => [ 'all' => $plugin->require, diff --git a/app/Services/Plugin.php b/app/Services/Plugin.php index cd062dfb..16c01c60 100644 --- a/app/Services/Plugin.php +++ b/app/Services/Plugin.php @@ -9,6 +9,12 @@ use Illuminate\Support\Str; class Plugin { + const README_FILES = [ + 'README.md', + 'readme.md', + 'README.MD', + ]; + /** * The full directory of this plugin. * @@ -58,6 +64,13 @@ class Plugin return "$baseUrl/{$this->name}/assets/$relativeUri?v=".$this->version; } + public function getReadme() + { + return Arr::first(self::README_FILES, function ($filename) { + return file_exists($this->path.'/'.$filename); + }); + } + public function hasConfig(): bool { return $this->hasConfigClass() || $this->hasConfigView(); diff --git a/resources/assets/src/views/admin/Plugins.vue b/resources/assets/src/views/admin/Plugins.vue index b993391c..d831485b 100644 --- a/resources/assets/src/views/admin/Plugins.vue +++ b/resources/assets/src/views/admin/Plugins.vue @@ -11,34 +11,42 @@