Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Entities can now be exported as markdown #829

Merged
merged 3 commits into from
Mar 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions app/Http/Controllers/Entity/ExportController.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
use App\Models\Entity;
use App\Services\Entity\ExportService;
use App\Traits\GuestAuthTrait;
use League\HTMLToMarkdown\HtmlConverter;
use League\HTMLToMarkdown\Converter\TableConverter;
use Illuminate\Support\Str;

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

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

$converter = new HtmlConverter();
$converter->getConfig()->setOption('strip_tags', true);
$converter->getEnvironment()->addConverter(new TableConverter());

return response()->view('entities.pages.print.markdown', ['entity' => $entity, 'model' => $entity->child, 'converter' => $converter])
->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: 0 additions & 1 deletion app/Observers/EntityObserver.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
use App\Services\Entity\TagService;
use App\Services\ImageService;
use App\Services\PermissionService;
use Illuminate\Support\Str;
use App\Facades\Domain;

class EntityObserver
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
34 changes: 34 additions & 0 deletions resources/views/entities/pages/print/markdown.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php /**
* @var \App\Models\MiscModel $model
* @var \App\Models\Entity $entity
*/?>

# {!! $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
Loading