summaryrefslogtreecommitdiff
path: root/IkiWiki/Setup/Standard.pm
blob: b7583097daf84851b0ebc43900ae941e79677695 (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. if (! $config{refresh} || $config{wrappers}) {
  31. debug("generating wrappers..");
  32. my @wrappers=@{$setup{wrappers}};
  33. delete $setup{wrappers};
  34. my %startconfig=(%config);
  35. foreach my $wrapper (@wrappers) {
  36. %config=(%startconfig, verbose => 0, %setup, %{$wrapper});
  37. checkconfig();
  38. gen_wrapper();
  39. }
  40. %config=(%startconfig);
  41. }
  42. foreach my $c (keys %setup) {
  43. if (defined $setup{$c}) {
  44. if (! ref $setup{$c}) {
  45. $config{$c}=possibly_foolish_untaint($setup{$c});
  46. }
  47. elsif (ref $setup{$c} eq 'ARRAY') {
  48. $config{$c}=[map { possibly_foolish_untaint($_) } @{$setup{$c}}]
  49. }
  50. elsif (ref $setup{$c} eq 'HASH') {
  51. foreach my $key (keys %{$setup{$c}}) {
  52. $config{$c}{$key}=possibly_foolish_untaint($setup{$c}{$key});
  53. }
  54. }
  55. }
  56. else {
  57. $config{$c}=undef;
  58. }
  59. }
  60. if (! $config{refresh}) {
  61. $config{rebuild}=1;
  62. debug("rebuilding wiki..");
  63. }
  64. else {
  65. debug("refreshing wiki..");
  66. }
  67. loadplugins();
  68. checkconfig();
  69. lockwiki();
  70. loadindex();
  71. refresh();
  72. debug("done");
  73. saveindex();
  74. }
  75. 1