]> BookStack Code Mirror - hacks/commitdiff
Added page export contents hack
authorDan Brown <redacted>
Thu, 16 Mar 2023 04:22:01 +0000 (04:22 +0000)
committerDan Brown <redacted>
Thu, 16 Mar 2023 04:22:01 +0000 (04:22 +0000)
content/page-export-contents/exports/page.blade.php [new file with mode: 0644]
content/page-export-contents/index.md [new file with mode: 0644]

diff --git a/content/page-export-contents/exports/page.blade.php b/content/page-export-contents/exports/page.blade.php
new file mode 100644 (file)
index 0000000..178d84d
--- /dev/null
@@ -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
\ No newline at end of file
diff --git a/content/page-export-contents/index.md b/content/page-export-contents/index.md
new file mode 100644 (file)
index 0000000..ef67a68
--- /dev/null
@@ -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">}}