Added page export contents hack

This commit is contained in:
Dan Brown 2023-03-16 04:22:01 +00:00
commit 9843d55aae
Signed by: danb
GPG key ID: 46D9F943C24A2EF9

View file

@ -0,0 +1,34 @@
@extends('layouts.export')
@section('title', $page->name)
@section('content')
<div dir="auto">
<h1 class="break-text" id="bkmrk-page-title">{{$page->name}}</h1>
@php
$toc = (new \BookStack\Entities\Tools\PageContent($page))->getNavigation($page->html);
@endphp
@if(!empty($toc))
<hr>
<div style="color: #888;"><strong>Page Contents</strong></div>
<ul>
@foreach($toc as $tocEntry)
<li style="margin-left: {{ ($tocEntry['level'] - 1) * 16 }}px;"><a href="{{ $tocEntry['link'] }}">{{ $tocEntry['text'] }}</a></li>
@endforeach
</ul>
<hr>
@endif
<div style="clear:left;"></div>
{!! $page->renderedHTML ?? $page->html !!}
</div>
<hr>
<div class="text-muted text-small">
@include('exports.parts.meta', ['entity' => $page])
</div>
@endsection

View file

@ -0,0 +1,20 @@
+++
title = "Page Export Contents List"
author = "@ssddanbrown"
date = 2023-03-16T00:00:00Z
updated = 2023-03-16T00:00:00Z
tested = "v23.02.1"
+++
This hack uses the visual theme system to customize the page export template file, used for both PDF and HTML exports, to add a simple linked "Contents" list to the top of the file, generated from the headers within the document.
#### Considerations
- The "Page Contents" header is hardcoded in English.
- This contents list will not show page numbers for the PDF export.
- The contents will show when headers are used in page content.
- This hack uses internal an "PageContent" content class, and it's methods, which will likely change in future BookStack versions.
#### Code
{{<hack file="exports/page.blade.php" type="visual">}}