summaryrefslogtreecommitdiff
path: root/IkiWiki/Setup/Standard.pm
blob: b1418ae34743272c583e35cdbe915026a236c258 (plain)
  1. #!/usr/bin/perl
  2. # Standard ikiwiki setup module.
  3. # Parameters to import should be all the standard ikiwiki config stuff,
  4. # plus an array of wrappers to set up.
  5. use warnings;
  6. use strict;
  7. use IkiWiki::Wrapper;
  8. use IkiWiki::Render;
  9. package IkiWiki::Setup::Standard;
  10. sub import {
  11. IkiWiki::setup_standard(@_);
  12. }
  13. package IkiWiki;
  14. sub setup_standard {
  15. my %setup=%{$_[1]};
  16. $setup{plugin}=$config{plugin};
  17. if (exists $setup{add_plugins}) {
  18. push @{$setup{plugin}}, @{$setup{add_plugins}};
  19. delete $setup{add_plugins};
  20. }
  21. if (exists $setup{disable_plugins}) {
  22. foreach my $plugin (@{$setup{disable_plugins}}) {
  23. $setup{plugin}=[grep { $_ ne $plugin } @{$setup{plugin}}];
  24. }
  25. delete $setup{disable_plugins};
  26. }
  27. if (exists $setup{exclude}) {
  28. $config{wiki_file_prune_regexp}=qr/$config{wiki_file_prune_regexp}|$setup{exclude}/;
  29. }
  30. debug("generating wrappers..");
  31. my @wrappers=@{$setup{wrappers}};
  32. delete $setup{wrappers};
  33. my %startconfig=(%config);
  34. foreach my $wrapper (@wrappers) {
  35. %config=(%startconfig, verbose => 0, %setup, %{$wrapper});
  36. checkconfig();
  37. gen_wrapper();
  38. }
  39. %config=(%startconfig);
  40. foreach my $c (keys %setup) {
  41. if (defined $setup{$c}) {
  42. if (! ref $setup{$c}) {
  43. $config{$c}=possibly_foolish_untaint($setup{$c});
  44. }
  45. elsif (ref $setup{$c} eq 'ARRAY') {
  46. $config{$c}=[map { possibly_foolish_untaint($_) } @{$setup{$c}}]
  47. }
  48. }
  49. else {
  50. $config{$c}=undef;
  51. }
  52. }
  53. if (! $config{refresh}) {
  54. $config{rebuild}=1;
  55. debug("rebuilding wiki..");
  56. }
  57. else {
  58. debug("refreshing wiki..");
  59. }
  60. loadplugins();
  61. checkconfig();
  62. lockwiki();
  63. loadindex();
  64. refresh();
  65. debug("done");
  66. saveindex();
  67. }
  68. 1