première tentative d'export du body en md, pas très concluant

This commit is contained in:
antonin gallon 2025-12-10 14:54:12 +01:00
parent 8c8295b677
commit c4892e919c
16 changed files with 477 additions and 0 deletions

View file

@ -0,0 +1,50 @@
<?php
Kirby::plugin('tonnom/epub-export', [
'api' => [
'routes' => [
[
'pattern' => 'epub-export/(:any)',
'method' => 'POST',
'action' => function () {
$pageId = get('id');
$page = page($pageId);
throw new Exception($page);
if (!$page) {
throw new Exception("Page introuvable");
}
// Markdown du champ Body
$markdown = $page->body()->toMarkdown();
// Emplacement du fichier
$root = kirby()->root('media') . '/exports';
Dir::make($root);
$filename = $page->id() . '.md';
$filepath = $root . '/' . $filename;
file_put_contents($filepath, $markdown);
return [
'message' => 'OK',
'file' => $filename,
'path' => $filepath,
'url' => kirby()->url('media') . '/exports/' . $filename,
];
}
]
]
],
'sections' => [
'epubexport' => [
'props' => [
'pageId' => function () {
return $this->model()->id();
},
],
'component' => 'export-button'
]
]
]);