Almost-minimal filesystem based blog.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

214 lines
7.1 KiB

17 years ago
17 years ago
17 years ago
17 years ago
17 years ago
17 years ago
17 years ago
17 years ago
17 years ago
17 years ago
17 years ago
17 years ago
17 years ago
17 years ago
17 years ago
17 years ago
17 years ago
17 years ago
17 years ago
17 years ago
17 years ago
17 years ago
17 years ago
17 years ago
  1. NAME
  2. Display - module to display fragments of text on the web and elsewhere
  3. SYNOPSIS
  4. #!/usr/bin/perl
  5. use Display qw(%WalaConf %DISPLAY_CONF &handle);
  6. do 'conf.pl' if -e 'conf.pl'; # grab config
  7. $WalaConf{'ShowSearchlinks'} = 0;
  8. print handle(@ARGV);
  9. DESCRIPTION
  10. Display started life as a simple script to concatenate fragments of
  11. handwritten HTML by date. It has since haphazardly accumulated several
  12. of the usual weblog features (comments, lightweight markup, feed
  13. generation, embedded Perl, poetry tools, ill-advised dependencies), but
  14. the basic idea hasn't changed much.
  15. The module will work with FastCGI, via CGI::Fast, if called from the
  16. appropriate wrapper script.
  17. Entries are stored in a simple directory tree under
  18. $DISPLAY_CONF{ROOT_DIR}.
  19. Like:
  20. archives/2001/1/1
  21. archives/2001/1/1/sub_entry
  22. An entry may be either a plain text file, or a directory containing
  23. several such files + whatever else you'd like to store. If it's a
  24. directory, the file called "index" will be treated as the text of the
  25. entry, and all other lower case filenames without extensions will be
  26. treated as sub-entries or documents within that entry, and displayed
  27. accordingly.
  28. Directories may be nested to an arbitrary depth, though I don't promise
  29. that this won't break on you.
  30. A PNG or JPEG file with a name like
  31. 2001/1/1.icon.png
  32. 2001/1/1/index.icon.png
  33. 2001/1/1/whatever.icon.png
  34. will be treated as an icon for the appropriate entry file.
  35. MARKUP
  36. Entries may consist of hand-written HTML (to be passed along without
  37. further interpretation), a supported form of lightweight markup, or some
  38. combination thereof. Actually, an entry may consist of any darn thing
  39. you please, as long as Perl will agree that it is text, but presumably
  40. you're going to be feeding this to a browser.
  41. Special markup is indicated by a variety of XML-style container tags.
  42. Embedded Perl - evaluated and replaced by whatever value you return
  43. (evaluated in a scalar context):
  44. <perl>my $dog = "Ralph."; return $dog;</perl>
  45. This code is evaluated before any other processing is done, so you can
  46. return any other markup understood by the script and have it handled
  47. appropriately.
  48. Interpolated variables - actually keys to %TEMPLATE, for the moment:
  49. <perl>$TEMPLATE{dog} = "Ralph"; return '';</perl>
  50. <p>My dog is named ${dog}.</p>
  51. Embedded code and variables are mostly intended for use in header and
  52. footer files, where it's handy to drop in titles or conditionalize
  53. aspects of a layout. You want to be careful with this sort of thing -
  54. it's useful in small doses, but it's also a maintainability nightmare
  55. waiting to happen. (WordPress, I am looking at you.)
  56. Several forms of lightweight markup:
  57. <wala>Wala::Markup, via Wala.pm - very basic wiki syntax</wala>
  58. <textile>Dean Allen's Textile, via Brad Choate's
  59. Text::Textile.</textile>
  60. <freeverse>An easy way to
  61. get properly broken lines
  62. -- en and em dashes ---
  63. for poetry and such.</freeverse>
  64. And a couple of shortcuts:
  65. <image>filename.ext
  66. alt text, if any</image>
  67. <list>
  68. one list item
  69. another list item
  70. </list>
  71. As it stands, freeverse, image, and list are not particularly robust.
  72. SUBROUTINES
  73. For no bigger than this thing is, it gets a little convoluted.
  74. handle
  75. Handle a given request, either in the form of a CGI query object or
  76. a date/entry string.
  77. output
  78. Returns appropriate output for a given option.
  79. expand_query
  80. Expands a CGI query (for example, one passed in from CGI::Fast) to
  81. an appropriate list of parameters.
  82. expand_option
  83. Expands/converts 'all' and 'new' to appropriate values.
  84. recent_month
  85. Tries to find the most recent month in the archive.
  86. If a year file is text, returns that instead.
  87. month_before
  88. Return the month before the given month in the archive.
  89. Very naive; there has got to be a smarter way.
  90. dir_list
  91. Return a $sort_order sorted list of files matching regex $pattern in
  92. a directory.
  93. Calls $sort_order, which can be one of:
  94. alpha - alphabetical
  95. reverse_alpha - alphabetical, reversed
  96. high_to_low - numeric, high to low
  97. low_to_high - numeric, low to high
  98. year_print
  99. List out the updates for a year.
  100. month_print
  101. Prints the entries in a given month (nnnn/nn).
  102. entry_print
  103. Prints the contents of a given entry. Calls datestamp, dir_list, and
  104. icon_markup. Recursively calls itself.
  105. icon_markup
  106. Check if an icon exists for a given entry if so, return markup to
  107. include it. Icons are PNG or JPEG image files following a specific
  108. naming convention:
  109. index.icon.[png|jp(e)g] for directories
  110. [filename].icon.[png|jp(e)g] for flat text files
  111. Calls image_size, uses filename to determine type.
  112. datestamp
  113. Returns a nice html datestamp for a given entry, including a
  114. wikilink for discussion and suchlike.
  115. fragment_slurp
  116. Read a text fragment, call line_parse to take care of funky markup
  117. and interpreting embedded code, and then return it as a string.
  118. Takes one parameter, the name of the file, and returns '' if it's
  119. not an extant text file.
  120. This might be the place to implement an in-memory cache for FastCGI
  121. or mod_perl environments. The trick is that the line_parse() results
  122. for certain files shouldn't be cached because they contain embedded
  123. code.
  124. eval_perl
  125. Evaluate embedded Perl in a string, replacing blocks enclosed with
  126. <perl> tags with whatever they return (well, evaluated in a scalar
  127. context). Modifies a string in-place, so be careful.
  128. Also handles simple ${variables}, replacing them (for now) from
  129. %DISPLAY_CONF values.
  130. month_name
  131. Turn numeric dates into English.
  132. feed_print
  133. Return an Atom feed of entries for a month. Defaults to the most
  134. recent month in the archive.
  135. Called from handle(), requires XML::Atom::SimpleFeed.
  136. SEE ALSO
  137. walawiki.org, Blosxom, rassmalog, Text::Textile, XML::Atom::SimpleFeed,
  138. Image::Size, CGI::Fast.
  139. AUTHOR
  140. Copyright 2001-2007 Brennen Bearnes
  141. Image sizing code (in image_size) derived from wwwis, by Alex Knowles
  142. and Andrew Tong.
  143. display.pl is free software; you can redistribute it and/or modify
  144. it under the terms of the GNU General Public License as published by
  145. the Free Software Foundation; either version 2 of the License, or
  146. (at your option) any later version.
  147. This program is distributed in the hope that it will be useful,
  148. but WITHOUT ANY WARRANTY; without even the implied warranty of
  149. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  150. GNU General Public License for more details.