From f1c56e126998de4ae9850b249230b7b4470580ba Mon Sep 17 00:00:00 2001 From: "Michael W. Olson" Date: Fri, 24 Aug 2007 22:22:55 -0400 Subject: [PATCH] Include metadate plugin for PyBlosxom with Muse * contrib/pyblosxom/metadate.py: New file that implements the PyBlosxom metadate plugin. Since this can no longer be found at the original author's website, I have included it with Muse. * lisp/muse-blosxom.el: Update location of metadate plugin in header. * texi/muse.texi (Blosxom Requirements): Organize information by subheading and subsubheading, and document how to use the metadate plugin. --- ChangeLog | 11 +++++ contrib/pyblosxom/metadate.py | 98 +++++++++++++++++++++++++++++++++++++++++++ lisp/muse-blosxom.el | 13 +++--- texi/muse.texi | 39 ++++++++++++++++- 4 files changed, 154 insertions(+), 7 deletions(-) create mode 100644 contrib/pyblosxom/metadate.py diff --git a/ChangeLog b/ChangeLog index 18b501a..11a8d26 100644 --- a/ChangeLog +++ b/ChangeLog @@ -15,9 +15,20 @@ * contrib/pyblosxom/make-blog: Change license text to be "This file may be used, distributed, and modified without restriction." + * contrib/pyblosxom/metadate.py: New file that implements the + PyBlosxom metadate plugin. Since this can no longer be found at + the original author's website, I have included it with Muse. + + * lisp/muse-blosxom.el: Update location of metadate plugin in + header. + * lisp/muse-wiki.el (muse-wiki-project-file-regexp): Fix typo in docstring. + * texi/muse.texi (Blosxom Requirements): Organize information by + subheading and subsubheading, and document how to use the metadate + plugin. + 2007-08-23 Michael Olson * lisp/muse-html.el (muse-html-insert-contents): Escape heading diff --git a/contrib/pyblosxom/metadate.py b/contrib/pyblosxom/metadate.py new file mode 100644 index 0000000..a2a85d0 --- /dev/null +++ b/contrib/pyblosxom/metadate.py @@ -0,0 +1,98 @@ +""" +Purpose: + + If an entry contains a #postdate metatag, metadate.py makes + pyblosxom use that as the entry's date instead of the file's mtime. + +To use: + + Place this file in your pyblosxom plugins directory. + + If you have previously assigned a value to py['load_plugins'] in + your config.py file, add this module to that list. + + Tag an entry with a metadata line like so: + #postdate YYYY-MM-DD HH-MM + +Developer Info: + + There really isn't a clean way to implement this (as far as I can + tell). The cb_filestat callback isn't passed the entry, and none of + the other callbacks are passed the mtime, and we really need them + both to do this properly. + + The ugly--but functional--solution to this problem is to go into the + file and dig the metadata out directly. That is what I have done + here. + + Since the entries are now being opened twice each, this could result + in decently-sized (relatively speaking) performance hit. Consider + yourself warned. + +License: + + Permission is hereby granted, free of charge, to any person + obtaining a copy of this software and associated documentation files + (the"Software"), to deal in the Software without restriction, + including without limitation the rights to use, copy, modify, merge, + publish, distribute, sublicense, and/or sell copies of the Software, + and to permit persons to whom the Software is furnished to do so, + subject to the following conditions: + + The above copyright notice and this permission notice shall be + included in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + SOFTWARE. + +Copyright 2005 Cameron Desautels +""" + +import os, re, time + +__author__ = 'Cameron Desautels ' +__version__ = 'metadate.py, v 0.1' +__description__ = 'Implements overriding of mtime with #postdate metadata.' + +DATEFORMAT = re.compile('([0-9]{4})-([0-1][0-9])-([0-3][0-9]) ([0-2][0-9]):([0-5][0-9])') + +def cb_filestat(args): + stattuple = args['mtime'] + + try: + story = open(args['filename']).readlines() + except IOError: + raise IOError + + if story: + story.pop(0) #throw away the title + + while story: + metamatch = re.match(r'#(\w+)\s+(.*)', story[0]) + if metamatch: + if metamatch.groups()[0] == 'postdate': + datematch = DATEFORMAT.match(metamatch.groups()[1].strip()) + if datematch: + # year, month, day, hour, minute + mtime = time.mktime((int(datematch.groups()[0]),int(datematch.groups()[1]), \ + int(datematch.groups()[2]),int(datematch.groups()[3]), \ + int(datematch.groups()[4]),0,0,0,-1)) + + args['mtime'] = tuple(list(stattuple[:8]) + [mtime] + list(stattuple[9:])) + + # whether the postdate line was correct or malformed, we found it, so quit + break + else: + # that wasn't the right metadata line, so chuck it and keep going + story.pop(0) + else: + # quit when all metadata has been examined + break + + return args diff --git a/lisp/muse-blosxom.el b/lisp/muse-blosxom.el index 28c99f4..c0feb6f 100644 --- a/lisp/muse-blosxom.el +++ b/lisp/muse-blosxom.el @@ -50,16 +50,19 @@ ;; `hardcodedates.py' provides the second service. Eventually it is ;; hoped that a blosxom plugin and script will be found/written. ;; -;; Alternately, the pyblosxom metadate plugin may be used. Set the -;; value of muse-blosxom-use-metadate to non-nil to enable adding a -;; #postdate directive to all published files. You can do this by: +;; Alternately, the pyblosxom metadate plugin may be used. On the +;; plus side, there is no need to run a script to gather the date. On +;; the downside, each entry is read twice rather than once when the +;; page is rendered. Set the value of muse-blosxom-use-metadate to +;; non-nil to enable adding a #postdate directive to all published +;; files. You can do this by: ;; ;; M-x customize-variable RET muse-blosxom-use-metadate RET ;; ;; With the metadate plugin installed in pyblosxom, the date set in ;; this directive will be used instead of the file's modification -;; time. The plugin is available at: -;; http://pyblosxom.sourceforge.net/blog/registry/date/metadate +;; time. The plugin is included with Muse at +;; contrib/pyblosxom/metadate.py. ;; ;; Generating a Muse project entry ;; ------------------------------- diff --git a/texi/muse.texi b/texi/muse.texi index 8400fe1..8459d48 100644 --- a/texi/muse.texi +++ b/texi/muse.texi @@ -1900,6 +1900,25 @@ In other words, each blog entry corresponds with one file. You will need to have @command{pyblosxom.cgi} or @command{blosxom.cgi} installed on a machine that you have upload access to. +The major difficulty in both of these programs is specifying the date of +the entries. Both programs rely on the file modification time rather +than any data contained in the entries themselves. A plugin is needed +in order for these programs to be able to get the correct date. + +@subheading PyBlosxom + +There are two different ways of accomplishing this in pyblosxom. The +first way involves gathering the timestamps (as specified by the +@code{#date} directive) into one file and then sending that file along +with published entries to the webserver. + +The second will read each file at render time and parse the +@code{#postdate} directive. Muse will translate the @code{#date} +directive into @code{#postdate} at publish time, so you don't have to do +any extra work. + +@subsubheading Placing timestamps in one file + The following additional components are required in order to make the date of blog entries display as something sensible. @@ -1915,8 +1934,7 @@ A plugin for (py)blosxom that reads this file. These 2 things are provided for @command{pyblosxom.cgi} in the @file{contrib/pyblosxom} subdirectory. @file{getstamps.py} provides the former service, while @file{hardcodedates.py} provides the latter -service. Eventually it is hoped that a @command{blosxom.cgi} plugin and -script will be found/written. +service. Here is a sample listing from my @file{timestamps} file, which maps each file to a date. This can really be in any format, as long as your @@ -1933,6 +1951,23 @@ The script @file{contrib/pyblosxom/make-blog} demonstrates how to call directory to where your Muse files are, execute @file{getstamps.py}, and then move the generated timestamps file to your publishing directory. +@subsubheading Getting timestamp from entry while rendering + +Alternately, the pyblosxom metadate plugin may be used. On the plus +side, there is no need to run a script to gather the date. On the +downside, each entry is read twice rather than once when the page is +rendered. Set the value of @code{muse-blosxom-use-metadate} to non-nil +to enable adding a @code{#postdate} directive to all published files. +You can do this by: + +@example +M-x customize-variable RET muse-blosxom-use-metadate RET +@end example + +With the metadate plugin installed in pyblosxom, the date set in this +directive will be used instead of the file's modification time. The +plugin is included with Muse at @file{contrib/pyblosxom/metadate.py}. + @node Blosxom Entries, Blosxom Options, Blosxom Requirements, Blosxom @comment node-name, next, previous, up @subsection Format of a Blosxom entry and automation -- 2.11.4.GIT