From 9b611caf3208ea05988f4d0bdeacac9eb0c0e59d Mon Sep 17 00:00:00 2001 From: Gustav Eek Date: Sat, 14 Dec 2019 19:48:24 +0100 Subject: Feature. Plugin. Provide sets of meta keys for inclusion Add further lists of meta keys to include (*hash_meta_keys* and *list_hash_meta_keys*), add them to the *list_meta* map in subroutine *htmlize* and provide them to *pagestate* *meta*. This makes available, e.g. the *reference* attribute in page templates. The commit require some explanation. Until now, meta attributes were available as * Bolean meta (*bool_meta*) * Scalar meta (*scalar_meta*) * List meta (*list_meta*) All meta attributes in documents are provided as page template variables with a 'pandoc_'-prefix. On top of that, attributes listed in *scalar_meta_keys* are made available as regular template variables, without prefix. Lists are problematic. Pure lists are pushed with 'pandoc_' prefix, but they can not be used. The alternative would be via loops (see ), but inside loops one need to call for a variable and the pushed attribute does not provide one. This commit properly makes available the *reference* attribute, which is of type list of associated list. This construct actually fully natural fulfil the limitations of lists. Template loops generate the items, whose values are available with keys as variable names: --- references: - id: refone title: Ref-MetaInlines-in-MetaList - id: reftwo title: Ref-MetaInlines-in-MetaList ... Which is called like this: How is hacky. The items in *hash_meta_keys* and *list_hash_meta_keys* are added to *list_meta_keys* and undergo the list processing. The list processing contradictory adopted better for *list_hash_meta_keys* than for *list_meta_keys*. --- .ikiwiki/IkiWiki/Plugin/pandoc.pm | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/.ikiwiki/IkiWiki/Plugin/pandoc.pm b/.ikiwiki/IkiWiki/Plugin/pandoc.pm index 7551215..adff519 100755 --- a/.ikiwiki/IkiWiki/Plugin/pandoc.pm +++ b/.ikiwiki/IkiWiki/Plugin/pandoc.pm @@ -42,6 +42,12 @@ my @list_meta_keys = qw/ author /; +my @hash_meta_keys = qw/ + experiment + /; + +my @list_hash_meta_keys = qw/ + references /; sub debug_get_filename_prefix { @@ -564,7 +570,8 @@ sub htmlize ($@) { $scalar_meta{$_.'_template'} = undef for @format_keys; my %bool_meta = map { ("generate_$_"=>0) } keys %extra_formats; - my %list_meta = map { ($_=>[]) } @list_meta_keys; + my %list_meta = map { ($_=>[]) } ( + @list_meta_keys, @list_hash_meta_keys, @hash_meta_keys); $list_meta{$_.'_extra_options'} = [] for @format_keys; my $have_bibl = 0; @@ -594,6 +601,7 @@ sub htmlize ($@) { $list_meta{$k} = unwrap_c($meta->{$k}); $list_meta{$k} = [$list_meta{$k}] unless ref $list_meta{$k} eq 'ARRAY'; $have_bibl = 1 if $k eq 'references'; + $pagestate{$page}{meta}{$k} = $list_meta{$k}; $pagestate{$page}{meta}{"pandoc_$k"} = $list_meta{$k}; } # Try to add other keys as scalars, with pandoc_ prefix only. @@ -752,7 +760,9 @@ sub pagetemplate (@) { foreach my $k (keys %{$pagestate{$page}{meta}}) { next unless - (grep {/^$k$/} (@scalar_meta_keys, @list_meta_keys)) || + (grep {/^$k$/} ( + @scalar_meta_keys, @list_meta_keys, + @hash_meta_keys, @list_hash_meta_keys)) || ($k =~ /^(pandoc_)/); $template->param($k => $pagestate{$page}{meta}{$k}); } -- cgit v1.2.3