36bbbb40b97442e807b851509ad4757e2690fbc8
[muse-el.git] / lisp / muse-blosxom.el
blob36bbbb40b97442e807b851509ad4757e2690fbc8
1 ;;; muse-blosxom.el --- publish a document tree for serving by (py)Blosxom
3 ;; Copyright (C) 2004, 2005, 2006, 2007, 2008 Free Software Foundation, Inc.
5 ;; Author: Michael Olson <mwolson@gnu.org>
6 ;; Date: Wed, 23 March 2005
8 ;; This file is part of Emacs Muse. It is not part of GNU Emacs.
10 ;; Emacs Muse is free software; you can redistribute it and/or modify
11 ;; it under the terms of the GNU General Public License as published
12 ;; by the Free Software Foundation; either version 3, or (at your
13 ;; option) any later version.
15 ;; Emacs Muse is distributed in the hope that it will be useful, but
16 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 ;; General Public License for more details.
20 ;; You should have received a copy of the GNU General Public License
21 ;; along with Emacs Muse; see the file COPYING. If not, write to the
22 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
23 ;; Boston, MA 02110-1301, USA.
25 ;;; Commentary:
27 ;; The Blosxom publishing style publishes a tree of categorised files
28 ;; to a mirrored tree of stories to be served by blosxom.cgi or
29 ;; pyblosxom.cgi.
31 ;; Serving entries with (py)blosxom
32 ;; --------------------------------
34 ;; Each Blosxom file must include `#date yyyy-mm-dd', or optionally
35 ;; the longer `#date yyyy-mm-dd-hh-mm', a title (using the `#title'
36 ;; directive) plus whatever normal content is desired.
38 ;; The date directive is not used directly by (py)blosxom or this
39 ;; program. You need to find two additional items to make use of this
40 ;; feature.
42 ;; 1. A script to gather date directives from the entire blog tree
43 ;; into a single file. The file must associate a blog entry with
44 ;; a date.
46 ;; 2. A plugin for (py)blosxom that reads this file.
48 ;; These 2 things are provided for pyblosxom in the contrib/pyblosxom
49 ;; subdirectory. `getstamps.py' provides the 1st service, while
50 ;; `hardcodedates.py' provides the second service. Eventually it is
51 ;; hoped that a blosxom plugin and script will be found/written.
53 ;; Alternately, the pyblosxom metadate plugin may be used. On the
54 ;; plus side, there is no need to run a script to gather the date. On
55 ;; the downside, each entry is read twice rather than once when the
56 ;; page is rendered. Set the value of muse-blosxom-use-metadate to
57 ;; non-nil to enable adding a #postdate directive to all published
58 ;; files. You can do this by:
60 ;; M-x customize-variable RET muse-blosxom-use-metadate RET
62 ;; With the metadate plugin installed in pyblosxom, the date set in
63 ;; this directive will be used instead of the file's modification
64 ;; time. The plugin is included with Muse at
65 ;; contrib/pyblosxom/metadate.py.
67 ;; Generating a Muse project entry
68 ;; -------------------------------
70 ;; Muse-blosxom has some helper functions to make specifying
71 ;; muse-blosxom projects a lot easier. An example follows.
73 ;; (setq muse-project-alist
74 ;; `(("blog"
75 ;; (,@(muse-project-alist-dirs "~/path/to/blog-entries")
76 ;; :default "index")
77 ;; ,@(muse-project-alist-styles "~/path/to/blog-entries"
78 ;; "~/public_html/blog"
79 ;; "blosxom-xhtml")
80 ;; )))
82 ;; Note that we need a backtick instead of a single quote on the
83 ;; second line of this example.
85 ;; Creating new blog entries
86 ;; -------------------------
88 ;; There is a function called `muse-blosxom-new-entry' that will
89 ;; automate the process of making a new blog entry. To make use of
90 ;; it, do the following.
92 ;; - Customize `muse-blosxom-base-directory' to the location that
93 ;; your blog entries are stored.
95 ;; - Assign the `muse-blosxom-new-entry' function to a key sequence.
96 ;; I use the following code to assign this function to `C-c p l'.
98 ;; (global-set-key "\C-cpl" 'muse-blosxom-new-entry)
100 ;; - You should create your directory structure ahead of time under
101 ;; your base directory. These directories, which correspond with
102 ;; category names, may be nested.
104 ;; - When you enter this key sequence, you will be prompted for the
105 ;; category of your entry and its title. Upon entering this
106 ;; information, a new file will be created that corresponds with
107 ;; the title, but in lowercase letters and having special
108 ;; characters converted to underscores. The title and date
109 ;; directives will be inserted automatically.
111 ;; Using tags
112 ;; ----------
114 ;; If you wish to keep all of your blog entries in one directory and
115 ;; use tags to classify your entries, set `muse-blosxom-use-tags' to
116 ;; non-nil.
118 ;; For this to work, you will need to be using the PyBlosxom plugin at
119 ;; http://pyblosxom.sourceforge.net/blog/registry/meta/Tags.
121 ;;; Contributors:
123 ;; Gary Vaughan (gary AT gnu DOT org) is the original author of
124 ;; `emacs-wiki-blosxom.el', which is the ancestor of this file.
126 ;; Brad Collins (brad AT chenla DOT org) ported this file to Muse.
128 ;; Björn Lindström (bkhl AT elektrubadur DOT se) made many valuable
129 ;; suggestions.
131 ;; Sasha Kovar (sasha AT arcocene DOT org) fixed
132 ;; muse-blosxom-new-entry when using tags and also implemented support
133 ;; for the #postdate directive.
135 ;;; Code:
137 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
139 ;; Muse Blosxom Publishing
141 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
143 (require 'muse-project)
144 (require 'muse-publish)
145 (require 'muse-html)
147 (defgroup muse-blosxom nil
148 "Options controlling the behavior of Muse Blosxom publishing.
149 See `muse-blosxom' for more information."
150 :group 'muse-publish)
152 (defcustom muse-blosxom-extension ".txt"
153 "Default file extension for publishing Blosxom files."
154 :type 'string
155 :group 'muse-blosxom)
157 (defcustom muse-blosxom-header
158 "<lisp>(concat (muse-publishing-directive \"title\") \"\\n\"
159 (when muse-blosxom-use-metadate
160 (let ((date (muse-publishing-directive \"date\")))
161 (when date (concat \"#postdate \"
162 (muse-blosxom-format-date date) \"\\n\"))))
163 (when muse-blosxom-use-tags
164 (let ((tags (muse-publishing-directive \"tags\")))
165 (when tags (concat \"#tags \" tags \"\\n\")))))</lisp>"
166 "Header used for publishing Blosxom files. This may be text or a filename."
167 :type 'string
168 :group 'muse-blosxom)
170 (defcustom muse-blosxom-footer ""
171 "Footer used for publishing Blosxom files. This may be text or a filename."
172 :type 'string
173 :group 'muse-blosxom)
175 (defcustom muse-blosxom-base-directory "~/Blog"
176 "Base directory of blog entries.
177 This is the top-level directory where your Muse blog entries may be found."
178 :type 'directory
179 :group 'muse-blosxom)
181 (defcustom muse-blosxom-use-tags nil
182 "Determine whether or not to enable use of the #tags directive.
184 If you wish to keep all of your blog entries in one directory and
185 use tags to classify your entries, set `muse-blosxom-use-tags' to
186 non-nil.
188 For this to work, you will need to be using the PyBlosxom plugin
189 at http://pyblosxom.sourceforge.net/blog/registry/meta/Tags."
190 :type 'boolean
191 :group 'muse-blosxom)
193 (defcustom muse-blosxom-use-metadate nil
194 "Determine whether or not to use the #postdate directive.
196 If non-nil, published entries include the original date (as specified
197 in the muse #date line) which can be read by the metadate PyBlosxom
198 plugin.
200 For this to work, you will need to be using the PyBlosxom plugin
201 at http://pyblosxom.sourceforge.net/blog/registry/date/metadate."
202 :type 'boolean
203 :group 'muse-blosxom)
205 ;; Maintain (published-file . date) alist, which will later be written
206 ;; to a timestamps file; not implemented yet.
208 (defvar muse-blosxom-page-date-alist nil)
210 (defun muse-blosxom-update-page-date-alist ()
211 "Add a date entry to `muse-blosxom-page-date-alist' for this page."
212 (when muse-publishing-current-file
213 ;; Make current file be relative to base directory
214 (let ((rel-file
215 (concat
216 (file-name-as-directory
217 (or (muse-publishing-directive "category")
218 (file-relative-name
219 (file-name-directory
220 (expand-file-name muse-publishing-current-file))
221 (file-truename muse-blosxom-base-directory))))
222 (file-name-nondirectory muse-publishing-current-file))))
223 ;; Strip the file extension
224 (when muse-ignored-extensions-regexp
225 (setq rel-file (save-match-data
226 (and (string-match muse-ignored-extensions-regexp
227 rel-file)
228 (replace-match "" t t rel-file)))))
229 ;; Add to page-date alist
230 (add-to-list
231 'muse-blosxom-page-date-alist
232 `(,rel-file . ,(muse-publishing-directive "date"))))))
234 ;; Enter a new blog entry
236 (defun muse-blosxom-title-to-file (title)
237 "Derive a file name from the given TITLE.
239 Feel free to overwrite this if you have a different concept of what
240 should be allowed in a filename."
241 (muse-replace-regexp-in-string (concat "[^-." muse-regexp-alnum "]")
242 "_" (downcase title)))
244 (defun muse-blosxom-format-date (date)
245 "Convert a date string to PyBlosxom metadate plugin format."
246 (apply #'format "%s-%s-%s %s:%s" (split-string date "-")))
248 ;;;###autoload
249 (defun muse-blosxom-new-entry (category title)
250 "Start a new blog entry with given CATEGORY.
251 The filename of the blog entry is derived from TITLE.
252 The page will be initialized with the current date and TITLE."
253 (interactive
254 (list
255 (if muse-blosxom-use-tags
256 (let ((tag "foo")
257 (tags nil))
258 (while (progn (setq tag (read-string "Tag (RET to continue): "))
259 (not (string= tag "")))
260 (add-to-list 'tags tag t))
261 tags)
262 (funcall muse-completing-read-function
263 "Category: "
264 (mapcar 'list (muse-project-recurse-directory
265 muse-blosxom-base-directory))))
266 (read-string "Title: ")))
267 (let ((file (muse-blosxom-title-to-file title)))
268 (muse-project-find-file
269 file "blosxom" nil
270 (if muse-blosxom-use-tags
271 (directory-file-name muse-blosxom-base-directory)
272 (concat (directory-file-name muse-blosxom-base-directory)
273 "/" category))))
274 (goto-char (point-min))
275 (insert "#date " (format-time-string "%Y-%m-%d-%H-%M")
276 "\n#title " title)
277 (if muse-blosxom-use-tags
278 (if (> (length category) 0)
279 (insert (concat "\n#tags " (mapconcat #'identity category ","))))
280 (unless (string= category "")
281 (insert (concat "\n#category " category))))
282 (insert "\n\n")
283 (forward-line 2))
285 ;;; Register the Muse Blosxom Publisher
287 (muse-derive-style "blosxom-html" "html"
288 :suffix 'muse-blosxom-extension
289 :link-suffix 'muse-html-extension
290 :header 'muse-blosxom-header
291 :footer 'muse-blosxom-footer
292 :after 'muse-blosxom-update-page-date-alist
293 :browser 'find-file)
295 (muse-derive-style "blosxom-xhtml" "xhtml"
296 :suffix 'muse-blosxom-extension
297 :link-suffix 'muse-xhtml-extension
298 :header 'muse-blosxom-header
299 :footer 'muse-blosxom-footer
300 :after 'muse-blosxom-update-page-date-alist
301 :browser 'find-file)
303 (provide 'muse-blosxom)
305 ;;; muse-blosxom.el ends here