guidesplit.pl 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. #!/usr/bin/perl
  2. # Work on the files that are created by makeinfo for html output
  3. # split into many small files.
  4. # This will walk though the files listed on the command line, install
  5. # Sebastian Rose's key reader and add a small top-level-only table
  6. # of contents that will be placed into a special region and visible
  7. # in all subfiles. The small contents is a constant and has to be updated
  8. # by hand, currently.
  9. $contents = <<EOF;
  10. <div id="table-of-contents">
  11. <h2>Table of Contents</h2>
  12. <div id="text-table-of-contents">
  13. <ul>
  14. <li><a name="Top" href="index.html#Top">Org Mode Compact Guide</a>
  15. <li><a name="Introduction" href="Introduction.html#Introduction">1 Introduction</a>
  16. <li><a name="Document-Structure" href="Document-Structure.html#Document-Structure">2 Document Structure</a>
  17. <li><a name="Tables" href="Tables.html#Tables">3 Tables</a>
  18. <li><a name="Hyperlinks" href="Hyperlinks.html#Hyperlinks">4 Hyperlinks</a>
  19. <li><a name="TODO-Items" href="TODO-Items.html#TODO-Items">5 TODO Items</a>
  20. <li><a name="Tags" href="Tags.html#Tags">6 Tags</a>
  21. <li><a name="Properties" href="Properties.html#Properties">7 Properties</a>
  22. <li><a name="Dates-and-Times" href="Dates-and-Times.html#Dates-and-Times">8 Dates and Times</a>
  23. <li><a name="Capture" href="Capture-_002d-Refile-_002d-Archive.html#Capture-_002d-Refile-_002d-Archive">9 Capture-Refile-Archive</a>
  24. <li><a name="Agenda-Views" href="Agenda-Views.html#Agenda-Views">10 Agenda Views</a>
  25. <li><a name="Markup" href="Markup.html#Markup">11 Markup</a>
  26. <li><a name="Exporting" href="Exporting.html#Exporting">12 Exporting</a>
  27. <li><a name="Publishing" href="Publishing.html#Publishing">13 Publishing</a>
  28. <li><a name="Working-With-Source-Code" href="Working-With-Source-Code.html#Working-With-Source-Code">14 Source code</a>
  29. <li><a name="Miscellaneous" href="Miscellaneous.html#Miscellaneous">15 Miscellaneous</a>
  30. </li></ul>
  31. </div>
  32. </div>
  33. </div>
  34. EOF
  35. $script = <<'EOF';
  36. </style><link rel="stylesheet" href="https://orgmode.org/org.css" type="text/css" />
  37. <script type="text/javascript" src="https://orgmode.org/org-keys.js"></script>
  38. <script type="text/javascript">
  39. <!--/*--><![CDATA[/*><!--*/
  40. OrgKeyReader.registerHref('h', 'index.html');
  41. OrgKeyReader.registerHref('t', 'index.html');
  42. /*]]>*/-->
  43. </script>
  44. EOF
  45. while ($page = shift) {
  46. system "mv $page $page.orig";
  47. open IN,"<$page.orig" or die "Cannot read from $page.orig\n";
  48. undef $/;
  49. $all = <IN>;
  50. close IN;
  51. $all =~ s/<meta http-equiv="Content-Style-Type" content="text\/css">/$&\n$script/;
  52. $all =~ s/^<body>/<body onload="OrgKeyReader.init();">\n$contents/m;
  53. open OUT,">$page" or die "Cannot write to $page\n";
  54. print OUT $all;
  55. close OUT;
  56. system "rm $page.orig";
  57. }