2 # Ikiwiki plugin for Emacs Muse.
3 # Author: Michael Olson
4 # License: GPLv2 or later
6 # In your ikiwiki.setup file, set the muse_init option to the location
7 # of the init file for Muse. Some examples provided in the
8 # examples/ikiwiki directory are muse-init-simple.el and
9 # muse-init-project.el.
11 package IkiWiki
::Plugin
::muse
;
22 hook
(type
=> "getsetup", id
=> "muse", call
=> \
&getsetup
);
23 hook
(type
=> "scan", id
=> "muse", call
=> \
&scan
);
24 hook
(type
=> "filter", id
=> "muse", call
=> \
&filter
);
25 hook
(type
=> "htmlize", id
=> "muse", call
=> \
&htmlize
);
32 rebuild
=> 1, # format plugin
36 example
=> "~/ikiwiki/muse-init.el",
37 description
=> "the location of your Muse init file",
44 # Handle Muse directives
47 return unless pagetype
($pagesources{$params{page
}}) eq 'muse';
48 my $canmeta = UNIVERSAL
::can
('IkiWiki::Plugin::meta', 'preprocess');
49 my $cantag = UNIVERSAL
::can
('IkiWiki::Plugin::tag', 'preprocess_tag');
50 return unless $canmeta || $cantag;
53 $_ = $params{content
};
55 while ( m/ \G \# ([a-zA-Z-]+) \s+ (.+?) \n+ /sgx ) {
56 my ($key, $val) = ($1, $2);
57 if ( $key =~ m/^(tags?|category)$/s ) {
60 IkiWiki
::Plugin
::tag
::preprocess_tag
(
61 (map { $_ => '' } (split /\s+/, $val)),
62 page
=> $params{page
},
63 destpage
=> $params{page
},
70 if ( $key eq 'date' ) {
71 # Support pyblosxom-style dates (YYYY-MM-DD(-hh-mm)?)
72 my $re = qr
/ ^ ([0-9]{4}) - ([0-1][0-9]) - ([0-3][0-9])
73 (?
: - ([0-2][0-9]) - ([0-5][0-9]) )?
$ /sx
;
74 if ( $val =~ m/$re/ ) {
75 my @array = (0, $5 || 0, $4 || 0, $3, $2, $1 - 1900);
76 $val = Date
::Format
::strftime
("%a, %e %b %Y %T", @array);
80 IkiWiki
::Plugin
::meta
::preprocess
(
82 page
=> $params{page
},
83 destpage
=> $params{page
},
88 if ( $params{muse_filter
} ) {
89 # Make "wantarray" work in the meta plugin
98 # Pass the content of the page to Muse for publishing
101 return $params{content
}
102 unless pagetype
($pagesources{$params{page
}}) eq 'muse';
104 # Force detection of the Muse #date directive
106 content
=> $params{content
},
107 page
=> $params{page
},
111 my $content = Encode
::encode_utf8
($params{content
});
112 my $qname = $params{page
};
115 my ($fh, $filename) = File
::Temp
::tempfile
();
118 my $qfile = $filename;
121 system qw( emacs -q --no-site-file -batch -l ),
122 $config{muse_init
}, '--eval',
123 qq{(muse
-ikiwiki
-publish
-file
"$qfile" "$qname")};
125 open my $ifh, '<', $filename;
137 return Encode
::decode_utf8
($content);
140 # Fake handler to make publishing work
143 return $params{content
};