summaryrefslogtreecommitdiff
path: root/IkiWiki/Setup/Standard.pm
blob: d42ceffa08d0767743d5036ab9b6948a2ffd19da (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 (! $config{refresh}) {
  28. debug("generating wrappers..");
  29. my @wrappers=@{$setup{wrappers}};
  30. delete $setup{wrappers};
  31. my %startconfig=(%config);
  32. foreach my $wrapper (@wrappers) {
  33. %config=(%startconfig, verbose => 0, %setup, %{$wrapper});
  34. checkconfig();
  35. gen_wrapper();
  36. }
  37. %config=(%startconfig);
  38. }
  39. else {
  40. delete $setup{wrappers};
  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. }
  51. else {
  52. $config{$c}=undef;
  53. }
  54. }
  55. if (! $config{refresh}) {
  56. $config{rebuild}=1;
  57. debug("rebuilding wiki..");
  58. }
  59. else {
  60. debug("refreshing wiki..");
  61. }
  62. checkconfig();
  63. lockwiki();
  64. loadindex();
  65. refresh();
  66. debug("done");
  67. saveindex();
  68. }
  69. 1