This repository was archived by the owner on Jul 27, 2024. It is now read-only.
File tree 2 files changed +13
-8
lines changed
2 files changed +13
-8
lines changed Original file line number Diff line number Diff line change 17
17
// Script logic
18
18
////////////////
19
19
20
+ // Get all list of all books in the system
20
21
$ books = getAllBooks ();
22
+ // Get a reference to our output location
21
23
$ outDir = realpath ($ exportLocation );
22
24
25
+ // Mapping for export formats to the resulting export file extensions
23
26
$ extensionByFormat = [
24
27
'pdf ' => 'pdf ' ,
25
28
'html ' => 'html ' ,
26
29
'plaintext ' => 'txt ' ,
30
+ 'markdown ' => 'md ' ,
27
31
];
28
32
33
+ // Loop over each book, exporting each one-by-one and saving its
34
+ // contents into the output location, using the books slug as
35
+ // the file name.
29
36
foreach ($ books as $ book ) {
30
37
$ id = $ book ['id ' ];
31
38
$ extension = $ extensionByFormat [$ exportFormat ] ?? $ exportFormat ;
37
44
/**
38
45
* Get all books from the system API.
39
46
*/
40
- function getAllBooks () {
47
+ function getAllBooks (): array {
41
48
$ count = 100 ;
42
49
$ offset = 0 ;
43
50
$ total = 0 ;
@@ -47,12 +54,7 @@ function getAllBooks() {
47
54
$ endpoint = 'api/books? ' . http_build_query (['count ' => $ count , 'offset ' => $ offset ]);
48
55
$ resp = apiGetJson ($ endpoint );
49
56
50
- // Only set total on first request, due to API bug:
51
- // https://github.com/BookStackApp/BookStack/issues/2043
52
- if ($ offset == 0 ) {
53
- $ total = $ resp ['total ' ] ?? 0 ;
54
- }
55
-
57
+ $ total = $ resp ['total ' ] ?? 0 ;
56
58
$ newBooks = $ resp ['data ' ] ?? [];
57
59
array_push ($ allBooks , ...$ newBooks );
58
60
$ offset += $ count ;
Original file line number Diff line number Diff line change 1
1
# Export All Books
2
2
3
- This script will export all books in your preferred format (PDF, HTML or TXT).
3
+ This script will export all books in your preferred format (PDF, HTML, Markdown or TXT).
4
4
5
5
## Requirements
6
6
@@ -34,4 +34,7 @@ php export-books.php pdf ./
34
34
35
35
# Export as HTML to an existing "html" directory
36
36
php export-books.php html ./html
37
+
38
+ # Export as Markdown to an existing "md-files" directory
39
+ php export-books.php markdown ./md-files
37
40
```
You can’t perform that action at this time.
0 commit comments