forked from bookstack/hacks
Added page export contents hack
This commit is contained in:
parent e77e38081a
commit 9843d55aae
2 changed files with 54 additions and 0 deletions
34 content/page-export-contents/exports/page.blade.php Normal file
34
content/page-export-contents/exports/page.blade.php Normal 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 |
20 content/page-export-contents/index.md Normal file
20
content/page-export-contents/index.md Normal 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">}} |
Loading…
Add table
Add a link
Reference in a new issue