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.

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