Skip to content

Commit

Permalink
Entities can now be exported as markdown
Browse files Browse the repository at this point in the history
  • Loading branch information
spitfire305 committed Mar 4, 2024
1 parent d00d28c commit a455bec
Show file tree
Hide file tree
Showing 7 changed files with 149 additions and 1 deletion.
10 changes: 10 additions & 0 deletions app/Http/Controllers/Entity/ExportController.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use App\Models\Entity;
use App\Services\Entity\ExportService;
use App\Traits\GuestAuthTrait;
use Illuminate\Support\Str;

/**
* Class ExportController
Expand All @@ -30,6 +31,15 @@ public function json(Campaign $campaign, Entity $entity)
return $this->service->entity($entity)->json();
}

public function markdown(Campaign $campaign, Entity $entity)
{
$this->authEntityView($entity);

return response()->view('entities.pages.print.markdown', ['entity' => $entity, 'model' => $entity->child])
->header('Content-Type', 'application/md')
->header('Content-disposition','attachment; filename="' . Str::slug($entity->name) . '.md"');
}

public function html(Campaign $campaign, Entity $entity)
{
$this->authEntityView($entity);
Expand Down
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
"laravel/ui": "^4.2.1",
"laravelcollective/html": "^6.0",
"league/flysystem-aws-s3-v3": "^3.5",
"league/html-to-markdown": "^5.1",
"livewire/livewire": "^3.3",
"mailerlite/mailerlite-php": "^1.0",
"mcamara/laravel-localization": "^1.7",
Expand Down
91 changes: 90 additions & 1 deletion composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions lang/en/crud.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
'go_to' => 'Go to :name',
'help' => 'Help',
'json-export' => 'Export (JSON)',
'markdown-export' => 'Export (Markdown)',
'manage_links' => 'Manage Links',
'move' => 'Move',
'new' => 'New',
Expand Down
4 changes: 4 additions & 0 deletions resources/views/entities/components/header.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,10 @@
<x-icon class="fa-solid fa-download"></x-icon>
{{ __('crud.actions.json-export') }}
</x-dropdowns.item>
<x-dropdowns.item link="{{ route('entities.markdown.export', [$campaign, $entity]) }}">
<x-icon class="fa-solid fa-download"></x-icon>
{{ __('crud.actions.markdown-export') }}
</x-dropdowns.item>
@endif
@if ((empty($disableCopyCampaign) || !$disableCopyCampaign) && auth()->check() && auth()->user()->hasOtherCampaigns($model->campaign_id))
<hr class="m-0" />
Expand Down
42 changes: 42 additions & 0 deletions resources/views/entities/pages/print/markdown.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?php /**
* @var \App\Models\MiscModel $model
* @var \App\Models\Entity $entity
*/
use Illuminate\Support\Str;
$converter = new League\HTMLToMarkdown\HtmlConverter();
$converter->getConfig()->setOption('strip_tags', true);
$converter->getEnvironment()->addConverter(new League\HTMLToMarkdown\Converter\TableConverter());
?>
<head>
<title>{!! Str::slug($entity->name) !!}</title>
</head>

# {!! $entity->name !!}

@if ($model instanceof \App\Models\Character && $model->isDead())
{{ __('characters.hints.is_dead') }}
@endif
@if ($model instanceof \App\Models\Quest && $model->isCompleted())
{{ __('quests.fields.is_completed') }}
@endif
@if ($model instanceof \App\Models\Organisation && $model->isDefunct())
{{ __('organisations.hints.is_defunct') }}
@endif
@if ($model instanceof \App\Models\Creature && $model->isExtinct())
{{ __('creatures.hints.is_extinct') }}
@endif

@if ($model instanceof \App\Models\Character && !empty($model->title))
{{ $model->title }}
@endif

@if (!empty($model->type))
{{ $model->type }}
@endif

{!! $converter->convert($model->entry) !!}

@foreach ($entity->posts as $post)
# {!! $post->name !!}
{!! $converter->convert($post->entry) !!}
@endforeach
1 change: 1 addition & 0 deletions routes/campaigns/entities.php
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,7 @@
// Export
Route::get('/w/{campaign}/entities/{entity}/html-export', 'Entity\ExportController@html')->name('entities.html-export');
Route::get('/w/{campaign}/entities/{entity}.json', 'Entity\ExportController@json')->name('entities.json.export');
Route::get('/w/{campaign}/entities/{entity}.md', 'Entity\ExportController@markdown')->name('entities.markdown.export');


Route::get('/w/{campaign}/entities/{entity}/template', 'Entity\TemplateController@update')->name('entities.template');
Expand Down

0 comments on commit a455bec

Please sign in to comment.