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.

281 lines
9.5 KiB

17 years ago
17 years ago
17 years ago
16 years ago
17 years ago
17 years ago
16 years ago
17 years ago
16 years ago
17 years ago
16 years ago
17 years ago
16 years ago
17 years ago
16 years ago
17 years ago
16 years ago
17 years ago
16 years ago
17 years ago
16 years ago
17 years ago
16 years ago
17 years ago
16 years ago
17 years ago
16 years ago
17 years ago
16 years ago
17 years ago
16 years ago
17 years ago
16 years ago
16 years ago
16 years ago
17 years ago
16 years ago
17 years ago
17 years ago
17 years ago
16 years ago
17 years ago
16 years ago
17 years ago
16 years ago
17 years ago
16 years ago
17 years ago
17 years ago
17 years ago
17 years ago
17 years ago
17 years ago
16 years ago
17 years ago
17 years ago
16 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;
  6. my $d = Display->new(
  7. root_dir => 'archives',
  8. url_root => '/display.pl?',
  9. # etc.
  10. );
  11. print $d->handle(@ARGV);
  12. DESCRIPTION
  13. Display started life as a simple script to concatenate fragments of
  14. handwritten HTML by date. It has since haphazardly accumulated several
  15. of the usual weblog features (comments, lightweight markup, feed
  16. generation, embedded Perl, poetry tools, image galleries, and
  17. ill-advised dependencies), but the basic idea hasn't changed much.
  18. The module will work with FastCGI, if called from the appropriate
  19. wrapper script. If you use CGI::Fast, you can pass query objects
  20. directly to "handle()".
  21. By default, entries are stored in a simple directory tree under
  22. "root_dir".
  23. Like:
  24. archives/2001/1/1
  25. archives/2001/1/1/sub_entry
  26. It is possible (although not yet as flexible as it ought to be) to
  27. redefine the directory layout. More about this after a bit.
  28. An entry may be either a plain text file, or a directory containing
  29. several files. If it's a directory, a file named "index" will be treated
  30. as the text of the entry, and all other lower-case filenames without
  31. extensions will be treated as sub-entries or documents within that
  32. entry, and displayed accordingly. Links to certain other filetypes will
  33. be displayed as well.
  34. Directories may be nested to an arbitrary depth, although it's probably
  35. not a good idea to go very deep with the current display logic.
  36. A PNG or JPEG file with a name like
  37. 2001/1/1.icon.png
  38. 2001/1/1/index.icon.png
  39. 2001/1/1/whatever.icon.png
  40. 2001/1/1/whatever/index.icon.png
  41. will be treated as an icon for the appropriate entry file.
  42. MARKUP
  43. Entries may consist of hand-written HTML (to be passed along without
  44. further interpretation), a supported form of lightweight markup, or some
  45. combination thereof. Actually, an entry may consist of any darn thing
  46. you please, as long as Perl will agree that it is text, but presumably
  47. you're going to be feeding this to a browser.
  48. Special markup is indicated by a variety of HTML-like container tags.
  49. Embedded Perl - evaluated and replaced by whatever value you return
  50. (evaluated in a scalar context):
  51. <perl>my $dog = "Ralph."; return $dog;</perl>
  52. This code is evaluated before any other processing is done, so you can
  53. return any other markup understood by the script and have it handled
  54. appropriately.
  55. Interpolated variables - actually keys to the hash underlying the
  56. Display object, for the moment:
  57. <perl>$self->title("About Ralph, My Dog"); return '';</perl>
  58. <p>The title is <em>${title}</em>.</p>
  59. This will change.
  60. Embedded code and variables are intended for use in header and footer
  61. files, where it's handy to drop in titles or conditionalize aspects of a
  62. layout. You want to be careful with this sort of thing - it's useful in
  63. small doses, but it's also a maintainability nightmare waiting to
  64. happen. (WordPress, I am looking at you.)
  65. Several forms of lightweight markup:
  66. <wala>Wala::Markup, via Wala.pm - very basic wiki syntax</wala>
  67. <textile>Dean Allen's Textile, via Brad Choate's
  68. Text::Textile.</textile>
  69. <freeverse>An easy way to
  70. get properly broken lines
  71. plus -- en and em dashes ---
  72. for poetry and such.</freeverse>
  73. And a couple of shortcuts:
  74. <image>filename.ext
  75. alt text, if any</image>
  76. <list>
  77. one list item
  78. another list item
  79. </list>
  80. As it stands, freeverse, image, and list are not particularly robust.
  81. ARCHIVE LAYOUT
  82. default values
  83. entry_map(\%map)
  84. Takes a hashref which will dispatch entries matching various regexen
  85. to the appropriate output methods. The default looks something like
  86. this:
  87. nnnn/[nn/nn/]doc_name - a document within a day.
  88. nnnn/nn/nn - a specific day.
  89. nnnn/nn - a month.
  90. nnnn - a year.
  91. doc_name - a document in the root directory.
  92. You can re-map things to an arbitrary archive layout.
  93. Since the entry map is a hash, and handle() simply loops over its
  94. keys, there is no guaranteed precedence of patterns. Be extremely
  95. careful that no entry will match more than one pattern, or you will
  96. wind up with unexpected behavior. A good way to ensure that this
  97. does not happen is to use patterns like:
  98. qr(
  99. ^ # start of string
  100. [0-9/]{4}/ # year
  101. [0-9]{1,2}/ # month
  102. [0-9]{1,2] # day
  103. $ # end of string
  104. )x
  105. ...always marking the start and end of the string explicitly.
  106. METHODS
  107. For no bigger than this thing is, it gets a little convoluted.
  108. new()
  109. configure(param => 'value')
  110. Set specified parameters.
  111. walaconf(%options)
  112. Set parameters for Wala.pm.
  113. display($entry1, $entry2, ...)
  114. Return a string containing the given entries, which can be in the
  115. form of CGI query objects or date/entry strings. If no parameters
  116. are given, default to default_entry().
  117. display() expands aliases ("new" and "all") and CGI query objects as
  118. necessary, collects input from handle($entry), and wraps the whole
  119. thing in header and footer files.
  120. handle($entry)
  121. Return the text of an individual entry.
  122. expand_query
  123. Expands a CGI query object (for example, one passed in from
  124. CGI::Fast) to an appropriate list of parameters.
  125. expand_option
  126. Expands/converts 'all' and 'new' to appropriate values.
  127. recent_month
  128. Tries to find the most recent month in the archive.
  129. If a year file is text, returns that instead.
  130. month_before
  131. Return the month before the given month in the archive.
  132. Very naive; there has got to be a smarter way.
  133. dir_list($dir, $sort_order, $pattern)
  134. Return a $sort_order sorted list of files matching regex $pattern in
  135. a directory.
  136. Calls $sort_order, which can be one of:
  137. alpha - alphabetical
  138. reverse_alpha - alphabetical, reversed
  139. high_to_low - numeric, high to low
  140. low_to_high - numeric, low to high
  141. year($year)
  142. List out the updates for a year.
  143. month($month)
  144. Prints the entries in a given month (nnnn/nn).
  145. entry($entry)
  146. Returns the contents of a given entry. Calls dir_list and
  147. icon_markup. Recursively calls itself.
  148. entry_wrapped
  149. Wraps entry() in entry_markup.
  150. entry_stamped
  151. Wraps entry() + a datestamp in entry_markup()
  152. icon_markup
  153. Check if an icon exists for a given entry if so, return markup to
  154. include it. Icons are PNG or JPEG image files following a specific
  155. naming convention:
  156. index.icon.[png|jp(e)g] for directories
  157. [filename].icon.[png|jp(e)g] for flat text files
  158. Calls image_size, uses filename to determine type.
  159. datestamp
  160. Returns a nice html datestamp for a given entry, including a
  161. wikilink for discussion and suchlike.
  162. fragment_slurp
  163. Read a text fragment, call line_parse to take care of funky markup
  164. and interpreting embedded code, and then return it as a string.
  165. Takes one parameter, the name of the file, and returns '' if it's
  166. not an extant text file.
  167. This might be the place to implement an in-memory cache for FastCGI
  168. or mod_perl environments. The trick is that the line_parse() results
  169. for certain files shouldn't be cached because they contain embedded
  170. code.
  171. eval_perl
  172. Evaluate embedded Perl in a string, replacing blocks enclosed with
  173. <perl> tags with whatever they return (well, evaluated in a scalar
  174. context). Modifies a string in-place, so be careful.
  175. Also handles simple ${variables}, replacing them from the keys to
  176. $self.
  177. month_name
  178. Turn numeric dates into English.
  179. root_locations($file)
  180. * Given a file/entry, return the appropriate concatenations with
  181. root_dir and url_root.
  182. local_path
  183. Return an absolute path for a given file. Called by root_locations.
  184. Arguably this is stupid and inefficient.
  185. feed_print
  186. Return an Atom feed of entries for a month. Defaults to the most
  187. recent month in the archive.
  188. Called from handle(), requires XML::Atom::SimpleFeed.
  189. SEE ALSO
  190. walawiki.org, Blosxom, rassmalog, Text::Textile, XML::Atom::SimpleFeed,
  191. Image::Size, CGI::Fast.
  192. AUTHOR
  193. Copyright 2001-2007 Brennen Bearnes
  194. Image sizing code (in image_size) derived from wwwis, by Alex Knowles
  195. and Andrew Tong.
  196. display.pl is free software; you can redistribute it and/or modify
  197. it under the terms of the GNU General Public License as published by
  198. the Free Software Foundation; either version 2 of the License, or
  199. (at your option) any later version.
  200. This program is distributed in the hope that it will be useful,
  201. but WITHOUT ANY WARRANTY; without even the implied warranty of
  202. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  203. GNU General Public License for more details.