]> sipb.mit.edu Git - ikiwiki.git/blob - doc/forum/converting_binary_files.mdwn
Merge remote-tracking branch 'spalax/calendar-autocreate'
[ikiwiki.git] / doc / forum / converting_binary_files.mdwn
1 I would like to use ikiwiki to build a static site which needs some transformations to be made on binary assets. A simple example is to translate a .odp presentation to .pdf using (e.g.) unoconv. If I add a new .odp attachment, or push one into the repo, I want the corresponding .pdf to appear in the generated site. What's the right place to hook in to do this?
2
3 I've made an experimental prototype which hooks into needsbuild, builds the pages then and there, and at the same time removes them from the list of pages to be built.
4
5 ~~~
6 sub needsbuild {
7     my $files=shift;
8     my $nfiles=[];
9     foreach my $f (@$files) {
10         if ($f =~ /\.odp$/) {
11             my $g = $f;
12             $g =~ s/\.odp$/\.pdf/;
13             debug("building $f to $g");
14             will_render($f, $g);
15             if (system("unoconv","-f","pdf","-o",IkiWiki::dirname("$config{destdir}/$g"),srcfile($f)) != 0) {
16                 error("unoconv: failed to translate $f to $g");
17             }
18         }
19         else {
20             push @$nfiles, $f;
21         }
22     };
23     return $nfiles;
24 }
25 ~~~
26
27 It appears to work, but is this the right way to do it, bearing in mind ikiwiki's dependency tracking and the like? And is the usage of will_render() correct?
28
29 [[BrianCandler]]