diff options
author | Gustav Eek <gustav.eek@fripost.org> | 2019-10-23 17:48:01 +0200 |
---|---|---|
committer | Gustav Eek <gustav.eek@fripost.org> | 2019-10-23 17:48:01 +0200 |
commit | c814e0bebff84c6a39c5991c26bbbf01540cd223 (patch) | |
tree | e2b5ba90603428f8cac4bf7c996540c7b7f4b019 /.ikiwiki | |
parent | 8c7611e5cae75c1bf448b74fcf2262f3e54642c6 (diff) |
Debug output cleanup and addition.
Diffstat (limited to '.ikiwiki')
-rwxr-xr-x | .ikiwiki/IkiWiki/Plugin/pandoc.pm | 177 |
1 files changed, 130 insertions, 47 deletions
diff --git a/.ikiwiki/IkiWiki/Plugin/pandoc.pm b/.ikiwiki/IkiWiki/Plugin/pandoc.pm index a7def67..249e9d0 100755 --- a/.ikiwiki/IkiWiki/Plugin/pandoc.pm +++ b/.ikiwiki/IkiWiki/Plugin/pandoc.pm @@ -11,6 +11,8 @@ use File::Path qw/make_path/; use JSON; use Data::Dumper; +$Data::Dumper::Indent = 3; + my $fh = undef; my $dh = undef; my $fnm = undef; @@ -19,18 +21,6 @@ my $next = 0; my $base = '/tmp/pandoc'; mkdir($base); -opendir($dh, $base) || die "Can't open $base: $!"; -foreach $f (grep(/[0-9][0-9]*$/, readdir($dh))) { - $f =~ /^(.*)-([0-9][0-9]*)$/; - $next = $2 + 1 if ($2 >= $next); -} -closedir $dh; -$fnm = sprintf "%s/%s-%.3d", $base, "verify", $next; -open($fh, '>', $fnm) or die "Could not"; -print $fh "Hej du glade på fil\n"; -print $fh "Detta är filen i '/home/gustav/git/fripost/wiki/.ikiwiki/IkiWiki/Plugin'\n"; -close $fh; -print "Closed $fnm\n"; # activate with 'generate_$format' in meta; turn on all with 'generate_all_formats'. my %extra_formats = ( @@ -43,19 +33,47 @@ my %extra_formats = ( latex => { ext=>'tex', label=>'LaTeX', format=>'latex', extra=>['--standalone'], order=>7 }, ); -sub import { +sub debug_get_filename_prefix { + + my $place = shift; + my $page = shift; + my $fnm_pfx = undef; opendir($dh, $base) || die "Can't open $base: $!"; - foreach $f (grep(/[0-9][0-9]*$/, readdir($dh))) { - $f =~ /^(.*)-([0-9][0-9]*)$/; - $next = $2 + 1 if ($2 >= $next); + foreach $f (grep(/^[0-9][0-9]*/, readdir($dh))) { + $f =~ /^([0-9][0-9]*)\.(.*)$/; + $next = $1 + 1 if ($1 >= $next); + } + close($dh); + if ($page) { + $fnm_pfx = sprintf "%s/%.3d.%s.%s", $base, $next, $place, + $page =~ s/\//-/rg; + } else { + $fnm_pfx = sprintf "%s/%.3d.%s", $base, $next, $place; } - closedir $dh; - $fnm = sprintf "%s/%s-%.3d", $base, "import", $next; + return $fnm_pfx; +} + +# DEBUG Print +print "D: First file read.\n"; +$fnm = debug_get_filename_prefix ("verify"); +open($fh, '>', $fnm) or die "Could not"; +print $fh "Hej du glade på fil\n"; +print $fh "Detta är filen i '/home/gustav/git/fripost/wiki/.ikiwiki/IkiWiki/Plugin'\n"; +close $fh; +# END + + +sub import { + + # DEBUG Print + print "D: Run import.\n"; + my $fnm_pfx = debug_get_filename_prefix ("import",""); + my $fnm = $fnm_pfx; open($fh, '>', $fnm) or die "Could not open $fnm ."; print $fh "Import.\n"; close $fh; - print "Closed $fnm\n"; + # END my $markdown_ext = $config{pandoc_markdown_ext} || "mdwn"; @@ -105,6 +123,11 @@ sub import { sub getsetup () { + + # DEBUG + print "D: Run getsetup.\n"; + # END + return plugin => { safe => 1, @@ -381,12 +404,6 @@ sub getsetup () { sub htmlize ($@) { - opendir($dh, $base) || die "Can't open $base: $!"; - foreach $f (grep(/[0-9][0-9]*$/, readdir($dh))) { - $f =~ /^(.*)-([0-9][0-9]*)$/; - $next = $2 + 1 if ($2 >= $next); - } - my $format = shift; my %params = @_; my $page = $params{page}; @@ -395,11 +412,26 @@ sub htmlize ($@) { local(*PANDOC_IN, *JSON_IN, *JSON_OUT, *PANDOC_OUT); my @args = (); - $fnm = sprintf "%s/%s-%.3d", $base, "htmlize", $next; + # DEBUG Print params + print "D: Run htmlize for ", $page, "\n"; + my $fnm_pfx = debug_get_filename_prefix ("htmlize", $page); + my $m = 0; + $fnm = sprintf "%s.%.1d.%s", $fnm_pfx, $m++, "params"; open($fh, '>', $fnm) or die "Could not"; - print $fh Dumper($page), "\n"; + $Data::Dumper::Indent = 2; + print $fh Dumper(%params), "\n"; close $fh; - print "Closed $fnm\n"; + # END + + # DEBUG Print half way pagestate pagestate + $fnm = sprintf "%s.%.1d.%s", $fnm_pfx, $m++, "early-pagestate"; + open($fh, '>>', $fnm); + my %pagestate_dumper = ( + $page => $pagestate{$page}, + ); + print $fh Data::Dumper->Dump([\%pagestate_dumper], [qw("pagestate")]), "\n"; + close $fh; + # END # The default assumes pandoc is in PATH my $command = $config{pandoc_command} || "pandoc"; @@ -479,10 +511,6 @@ sub htmlize ($@) { $content =~ s{<div class="inline" id="(\d+)"></div>} {::INLINE::PLACEHOLDER::$1::}g; - $fnm = sprintf "%s/%s-%.3d", $base, "content-1", $next; - open($fh, '>>', $fnm); - print $fh Dumper($content), "\n"; - print PANDOC_OUT $content; close PANDOC_OUT; @@ -504,11 +532,19 @@ sub htmlize ($@) { warn "WARNING: Unexpected format for meta block. Incompatible version of Pandoc?\n"; } + # DEBUG Half way content which is plenty data + print "D: Pandoc command: ", " ", $command, " ", '-f', " ", + $markdown_fmt, " ", '-t', " ", 'json', " ", @args, + "\n"; + + $fnm = sprintf "%s.%.1d.%s", $fnm_pfx, $m++, "early-content"; + open($fh, '>>', $fnm); + print $fh Data::Dumper->Dump([$content], [qw(content)]), "\n"; print $fh Data::Dumper->Dump([$json_content], [qw(json_content)]), "\n"; print $fh Data::Dumper->Dump([$decoded_json], [qw(decoded_json)]), "\n"; print $fh Data::Dumper->Dump([$meta], [qw(meta)]), "\n"; close $fh; - print "Closed $fnm\n"; + # END # Get some selected meta attributes, more specifically: # (title date bibliography csl subtitle abstract summary description @@ -524,17 +560,9 @@ sub htmlize ($@) { $scalar_meta{$_.'_template'} = undef for @format_keys; my %bool_meta = map { ("generate_$_"=>0) } keys %extra_formats; - my %list_meta = map { ($_=>[]) } qw/author references/; + my %list_meta = map { ($_=>[]) } qw/author references tags/; $list_meta{$_.'_extra_options'} = [] for @format_keys; - $fnm = sprintf "%s/%s-%.3d", $base, "meta", $next; - open($fh, '>', $fnm) or die "Could not"; - print $fh Data::Dumper->Dump([\%scalar_meta], [qw(scalar_meta)]), "\n"; - print $fh Data::Dumper->Dump([\%bool_meta], [qw(bool_meta)]), "\n"; - print $fh Data::Dumper->Dump([\%list_meta], [qw(list_meta)]), "\n"; - close $fh; - print "Closed $fnm\n"; - my $have_bibl = 0; foreach my $k (keys %scalar_meta) { next unless $meta->{$k}; @@ -660,26 +688,45 @@ sub htmlize ($@) { waitpid $to_html_pid, 0; + print "D: Pandoc command: ", " ", $command, " ", '-f', " ", + 'json', " ", '-t', $htmlformat, " ", @html_args, "\n"; + $content = Encode::decode_utf8(join('', @html)); # Reinstate placeholders for inline plugin: $content =~ s{::INLINE::PLACEHOLDER::(\d+)::} {<div class="inline" id="$1"></div>}g; - $fnm = sprintf "%s/%s-%.3d", $base, "meta", $next; + # DEBUG Print meta + $fnm = sprintf "%s.%.1d.%s", $fnm_pfx, $m++, "meta"; open($fh, '>>', $fnm) or die "Could not"; print $fh "\n"; print $fh Data::Dumper->Dump([\%scalar_meta], [qw(scalar_meta)]), "\n"; print $fh Data::Dumper->Dump([\%bool_meta], [qw(bool_meta)]), "\n"; print $fh Data::Dumper->Dump([\%list_meta], [qw(list_meta)]), "\n"; close $fh; - print "Closed $fnm\n"; + # END + + # DEBUG Print pagestate again + $fnm = sprintf "%s.%.1d.%s", $fnm_pfx, $m++, "return-pagestate"; + open($fh, '>>', $fnm); + my %pagestate_dumper = ( + $page => $pagestate{$page}, + ); + print $fh Data::Dumper->Dump([\%pagestate_dumper], [qw("pagestate")]), "\n"; + close $fh; + # END - $fnm = sprintf "%s/%s-%.3d", $base, "content-2", $next; + # DEBUG Print return content + $fnm = sprintf "%s.%.1d.%s", $fnm_pfx, $m++, "return-content"; open($fh, '>>', $fnm); print $fh Dumper($content), "\n"; close $fh; - print "Closed $fnm\n"; + # END + + # DEBUG + print "D: Return htmlize.\n"; + # END return $content; } @@ -689,17 +736,37 @@ sub pagetemplate (@) { my %params = @_; my $page = $params{page}; + + # DEBUG + print "D: Run pagetemplate for $page\n"; + # END + my $template = $params{template}; foreach my $k (keys %{$pagestate{$page}{meta}}) { next unless $k =~ /^pandoc_/; $template->param($k => $pagestate{$page}{meta}{$k}); } + + # DEBUG Print pagetemplate data + my $fnm_pfx = debug_get_filename_prefix ("pagetemplate", $page); + my $m = 0; + my $fnm = sprintf "%s.%.1d.%s", $fnm_pfx, $m++, "data"; + open($fh, '>', $fnm) or die "Could not"; + print $fh Data::Dumper->Dump([%params], [qw(params)]), "\n"; + print $fh Data::Dumper->Dump([$template], [qw(teplate)]), "\n"; + close $fh; + # END + + return $template; } sub pageactions { - + my %args = @_; my $page = $args{page}; + + print "D: Run pageactions for ", $page, "\n"; + my @links = (); return unless $pagestate{$page}{pandoc_extra_formats}; my @exts = sort { @@ -722,6 +789,11 @@ sub pageactions { sub export_file { my ($page, $ext, $json_content, $command, @args) = @_; + + # DEBUG + print "D: Run export_file for $page.\n"; + # END + my ($export_path, $export_url) = _export_file_path_and_url($page, $ext); my $subdir = $1 if $export_path =~ /(.*)\//; my @extra_args = @{ $extra_formats{$ext}->{extra} }; @@ -773,6 +845,11 @@ sub export_file { @args, @extra_args) or die "Could not open pipe for $ext: $!"; print EXPORT $json_content; close EXPORT or die "Could not close pipe for $ext: $!"; + + print "D: Pandoc command: ", " ", $command, " ", '-f' => + 'json', " ", '-t' => $to_format, " ", '-o' => + $tmp_export_path, " ", @args, " ", @extra_args; + if ($indirect_pdf && $tmp_export_path ne $export_path) { my @latexmk_args = qw(-quiet -silent); if (grep { /xelatex/ } @extra_args) { @@ -813,6 +890,12 @@ sub remove_exported_file { if ($@) { warn "WARNING: remove_exported_file; page=$page, ext=$ext: $@\n"; } + + # DEBUG + print "D: remove_exported_file: ", + "file removed for $page and $ext: $export_path.\n"; + # END + } } |