muse-protocols: Add woman:// handler
[muse-el.git] / lisp / muse-blosxom.el
blob34e821d03c6d9e18d66ce37e1520dd58ad819669
1 ;;; muse-blosxom.el --- publish a document tree for serving by (py)Blosxom
3 ;; Copyright (C) 2004, 2005, 2006 Free Software Foundation, Inc.
5 ;; Author: Michael Olson (mwolson AT gnu DOT 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 2, 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. Set the
54 ;; value of muse-blosxom-use-metadate to non-nil to enable adding a
55 ;; #postdate directive to all published files. You can do this by:
57 ;; M-x customize-variable RET muse-blosxom-use-metadate RET
59 ;; With the metadate plugin installed in pyblosxom, the date set in
60 ;; this directive will be used instead of the file's modification
61 ;; time. The plugin is available at:
62 ;; http://pyblosxom.sourceforge.net/blog/registry/date/metadate
64 ;; Generating a Muse project entry
65 ;; -------------------------------
67 ;; Muse-blosxom has some helper functions to make specifying
68 ;; muse-blosxom projects a lot easier. An example follows.
70 ;; (setq muse-project-alist
71 ;; `(("blog"
72 ;; (,@(muse-project-alist-dirs "~/path/to/blog-entries")
73 ;; :default "index")
74 ;; ,@(muse-project-alist-styles "~/path/to/blog-entries"
75 ;; "~/public_html/blog"
76 ;; "blosxom-xhtml")
77 ;; )))
79 ;; Note that we need a backtick instead of a single quote on the
80 ;; second line of this example.
82 ;; Creating new blog entries
83 ;; -------------------------
85 ;; There is a function called `muse-blosxom-new-entry' that will
86 ;; automate the process of making a new blog entry. To make use of
87 ;; it, do the following.
89 ;; - Customize `muse-blosxom-base-directory' to the location that
90 ;; your blog entries are stored.
92 ;; - Assign the `muse-blosxom-new-entry' function to a key sequence.
93 ;; I use the following code to assign this function to `C-c p l'.
95 ;; (global-set-key "\C-cpl" 'muse-blosxom-new-entry)
97 ;; - You should create your directory structure ahead of time under
98 ;; your base directory. These directories, which correspond with
99 ;; category names, may be nested.
101 ;; - When you enter this key sequence, you will be prompted for the
102 ;; category of your entry and its title. Upon entering this
103 ;; information, a new file will be created that corresponds with
104 ;; the title, but in lowercase letters and having special
105 ;; characters converted to underscores. The title and date
106 ;; directives will be inserted automatically.
108 ;; Using tags
109 ;; ----------
111 ;; If you wish to keep all of your blog entries in one directory and
112 ;; use tags to classify your entries, set `muse-blosxom-use-tags' to
113 ;; non-nil.
115 ;; For this to work, you will need to be using the PyBlosxom plugin at
116 ;; http://pyblosxom.sourceforge.net/blog/registry/meta/Tags.
118 ;;; Contributors:
120 ;; Gary Vaughan (gary AT gnu DOT org) is the original author of
121 ;; `emacs-wiki-blosxom.el', which is the ancestor of this file.
123 ;; Brad Collins (brad AT chenla DOT org) ported this file to Muse.
125 ;; Björn Lindström (bkhl AT elektrubadur DOT se) made many valuable
126 ;; suggestions.
128 ;; Sasha Kovar (sasha AT arcocene DOT org) fixed
129 ;; muse-blosxom-new-entry when using tags and also implemented support
130 ;; for the #postdate directive.
132 ;;; Code:
134 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
136 ;; Muse Blosxom Publishing
138 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
140 (require 'muse-project)
141 (require 'muse-publish)
142 (require 'muse-html)
144 (defgroup muse-blosxom nil
145 "Options controlling the behavior of Muse Blosxom publishing.
146 See `muse-blosxom' for more information."
147 :group 'muse-publish)
149 (defcustom muse-blosxom-extension ".txt"
150 "Default file extension for publishing Blosxom files."
151 :type 'string
152 :group 'muse-blosxom)
154 (defcustom muse-blosxom-header
155 "<lisp>(concat (muse-publishing-directive \"title\") \"\\n\"
156 (when muse-blosxom-use-metadate
157 (let ((date (muse-publishing-directive \"date\")))
158 (when date (concat \"#postdate \"
159 (muse-blosxom-format-date date) \"\\n\"))))
160 (when muse-blosxom-use-tags
161 (let ((tags (muse-publishing-directive \"tags\")))
162 (when tags (concat \"#tags \" tags \"\\n\")))))</lisp>"
163 "Header used for publishing Blosxom files. This may be text or a filename."
164 :type 'string
165 :group 'muse-blosxom)
167 (defcustom muse-blosxom-footer ""
168 "Footer used for publishing Blosxom files. This may be text or a filename."
169 :type 'string
170 :group 'muse-blosxom)
172 (defcustom muse-blosxom-base-directory "~/Blog"
173 "Base directory of blog entries.
174 This is the top-level directory where your Muse blog entries may be found."
175 :type 'directory
176 :group 'muse-blosxom)
178 (defcustom muse-blosxom-use-tags nil
179 "Determine whether or not to enable use of the #tags directive.
181 If you wish to keep all of your blog entries in one directory and
182 use tags to classify your entries, set `muse-blosxom-use-tags' to
183 non-nil.
185 For this to work, you will need to be using the PyBlosxom plugin
186 at http://pyblosxom.sourceforge.net/blog/registry/meta/Tags."
187 :type 'boolean
188 :group 'muse-blosxom)
190 (defcustom muse-blosxom-use-metadate nil
191 "Determine whether or not to use the #postdate directive.
193 If non-nil, published entries include the original date (as specified
194 in the muse #date line) which can be read by the metadate PyBlosxom
195 plugin.
197 For this to work, you will need to be using the PyBlosxom plugin
198 at http://pyblosxom.sourceforge.net/blog/registry/date/metadate."
199 :type 'boolean
200 :group 'muse-blosxom)
202 ;; Maintain (published-file . date) alist, which will later be written
203 ;; to a timestamps file; not implemented yet.
205 (defvar muse-blosxom-page-date-alist nil)
207 (defun muse-blosxom-update-page-date-alist ()
208 "Add a date entry to `muse-blosxom-page-date-alist' for this page."
209 ;; Make current file be relative to base directory
210 (let ((rel-file
211 (concat
212 (file-name-as-directory
213 (or (muse-publishing-directive "category")
214 (file-relative-name
215 (file-name-directory
216 (expand-file-name muse-publishing-current-file))
217 (file-truename muse-blosxom-base-directory))))
218 (file-name-nondirectory muse-publishing-current-file))))
219 ;; Strip the file extension
220 (when muse-ignored-extensions-regexp
221 (setq rel-file (save-match-data
222 (and (string-match muse-ignored-extensions-regexp
223 rel-file)
224 (replace-match "" t t rel-file)))))
225 ;; Add to page-date alist
226 (add-to-list
227 'muse-blosxom-page-date-alist
228 `(,rel-file . ,(muse-publishing-directive "date")))))
230 ;; Enter a new blog entry
232 (defun muse-blosxom-title-to-file (title)
233 "Derive a file name from the given TITLE.
235 Feel free to overwrite this if you have a different concept of what
236 should be allowed in a filename."
237 (muse-replace-regexp-in-string (concat "[^-." muse-regexp-alnum "]")
238 "_" (downcase title)))
240 (defun muse-blosxom-format-date (date)
241 "Convert a date string to PyBlosxom metadate plugin format."
242 (apply #'format "%s-%s-%s %s:%s" (split-string date "-")))
244 ;;;###autoload
245 (defun muse-blosxom-new-entry (category title)
246 "Start a new blog entry with given CATEGORY.
247 The filename of the blog entry is derived from TITLE.
248 The page will be initialized with the current date and TITLE."
249 (interactive
250 (list
251 (if muse-blosxom-use-tags
252 (let ((tag "foo")
253 (tags nil))
254 (while (progn (setq tag (read-string "Tag (RET to continue): "))
255 (not (string= tag "")))
256 (add-to-list 'tags tag t))
257 tags)
258 (completing-read "Category: "
259 (mapcar 'list (muse-project-recurse-directory
260 muse-blosxom-base-directory))))
261 (read-string "Title: ")))
262 (let ((file (muse-blosxom-title-to-file title)))
263 (muse-project-find-file
264 file "blosxom" nil
265 (if muse-blosxom-use-tags
266 (directory-file-name muse-blosxom-base-directory)
267 (concat (directory-file-name muse-blosxom-base-directory)
268 "/" category))))
269 (goto-char (point-min))
270 (insert "#date " (format-time-string "%Y-%m-%d-%H-%M")
271 "\n#title " title)
272 (if muse-blosxom-use-tags
273 (if (> (length category) 0)
274 (insert (concat "\n#tags " (mapconcat #'identity category ","))))
275 (unless (string= category "")
276 (insert (concat "\n#category " category))))
277 (insert "\n\n")
278 (forward-line 2))
280 ;;; Register the Muse Blosxom Publisher
282 (muse-derive-style "blosxom-html" "html"
283 :suffix 'muse-blosxom-extension
284 :link-suffix 'muse-html-extension
285 :header 'muse-blosxom-header
286 :footer 'muse-blosxom-footer
287 :after 'muse-blosxom-update-page-date-alist
288 :browser 'find-file)
290 (muse-derive-style "blosxom-xhtml" "xhtml"
291 :suffix 'muse-blosxom-extension
292 :link-suffix 'muse-xhtml-extension
293 :header 'muse-blosxom-header
294 :footer 'muse-blosxom-footer
295 :after 'muse-blosxom-update-page-date-alist
296 :browser 'find-file)
298 (provide 'muse-blosxom)
300 ;;; muse-blosxom.el ends here