summaryrefslogtreecommitdiff
path: root/IkiWiki/Setup/Standard.pm
blob: 7512c258758eb7e7a577d73e08b2679dc5a6e6b0 (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{render} && (! $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{render}) {
  61. commandline_render();
  62. }
  63. elsif (! $config{refresh}) {
  64. $config{rebuild}=1;
  65. debug("rebuilding wiki..");
  66. }
  67. else {
  68. debug("refreshing wiki..");
  69. }
  70. loadplugins();
  71. checkconfig();
  72. lockwiki();
  73. loadindex();
  74. refresh();
  75. debug("done");
  76. saveindex();
  77. }
  78. 1