Make things in contrib directory installable.
[muse-el.git] / lisp / muse-blosxom.el
blob48b2ef034b6de36e3e60c69b17f982b45ba269f8
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 ;; Generating a Muse project entry
54 ;; -------------------------------
56 ;; Muse-blosxom has some helper functions to make specifying
57 ;; muse-blosxom projects a lot easier. An example follows.
59 ;; (setq muse-project-alist
60 ;; `(("blog"
61 ;; (,@(muse-project-alist-dirs "~/path/to/blog-entries")
62 ;; :default "index")
63 ;; ,@(muse-project-alist-styles "~/path/to/blog-entries"
64 ;; "~/public_html/blog"
65 ;; "blosxom-xhtml")
66 ;; )))
68 ;; Note that we need a backtick instead of a single quote on the
69 ;; second line of this example.
71 ;; Creating new blog entries
72 ;; -------------------------
74 ;; There is a function called `muse-blosxom-new-entry' that will
75 ;; automate the process of making a new blog entry. To make use of
76 ;; it, do the following.
78 ;; - Customize `muse-blosxom-base-directory' to the location that
79 ;; your blog entries are stored.
81 ;; - Assign the `muse-blosxom-new-entry' function to a key sequence.
82 ;; I use the following code to assign this function to `C-c p l'.
84 ;; (global-set-key "\C-cpl" 'muse-blosxom-new-entry)
86 ;; - You should create your directory structure ahead of time under
87 ;; your base directory. These directories, which correspond with
88 ;; category names, may be nested.
90 ;; - When you enter this key sequence, you will be prompted for the
91 ;; category of your entry and its title. Upon entering this
92 ;; information, a new file will be created that corresponds with
93 ;; the title, but in lowercase letters and having special
94 ;; characters converted to underscores. The title and date
95 ;; directives will be inserted automatically.
97 ;; Using tags
98 ;; ----------
100 ;; If you wish to keep all of your blog entries in one directory and
101 ;; use tags to classify your entries, set `muse-blosxom-use-tags' to
102 ;; non-nil.
104 ;; For this to work, you will need to be using the PyBlosxom plugin at
105 ;; http://pyblosxom.sourceforge.net/blog/registry/meta/Tags.
107 ;;; Contributors:
109 ;; Gary Vaughan (gary AT gnu DOT org) is the original author of
110 ;; `emacs-wiki-blosxom.el', which is the ancestor of this file.
112 ;; Brad Collins (brad AT chenla DOT org) ported this file to Muse.
114 ;; Björn Lindström (bkhl AT elektrubadur DOT se) made many valuable
115 ;; suggestions.
117 ;;; Code:
119 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
121 ;; Muse Blosxom Publishing
123 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
125 (require 'muse-project)
126 (require 'muse-publish)
127 (require 'muse-html)
129 (defgroup muse-blosxom nil
130 "Options controlling the behavior of Muse Blosxom publishing.
131 See `muse-blosxom' for more information."
132 :group 'muse-publish)
134 (defcustom muse-blosxom-extension ".txt"
135 "Default file extension for publishing Blosxom files."
136 :type 'string
137 :group 'muse-blosxom)
139 (defcustom muse-blosxom-header
140 "<lisp>(muse-publishing-directive \"title\")</lisp>
141 <lisp>(when muse-blosxom-use-tags
142 (let ((tags (muse-publishing-directive \"tags\")))
143 (when tags (concat \"#tags \" tags \"\\n\"))))</lisp>"
144 "Header used for publishing Blosxom files. This may be text or a filename."
145 :type 'string
146 :group 'muse-blosxom)
148 (defcustom muse-blosxom-footer ""
149 "Footer used for publishing Blosxom files. This may be text or a filename."
150 :type 'string
151 :group 'muse-blosxom)
153 (defcustom muse-blosxom-base-directory "~/Blog"
154 "Base directory of blog entries.
155 This is the top-level directory where your Muse blog entries may be found."
156 :type 'directory
157 :group 'muse-blosxom)
159 (defcustom muse-blosxom-use-tags nil
160 "Determine whether or not to enable use of the #tags directive.
162 If you wish to keep all of your blog entries in one directory and
163 use tags to classify your entries, set `muse-blosxom-use-tags' to
164 non-nil.
166 For this to work, you will need to be using the PyBlosxom plugin
167 at http://pyblosxom.sourceforge.net/blog/registry/meta/Tags."
168 :type 'boolean
169 :group 'muse-blosxom)
171 ;; Maintain (published-file . date) alist, which will later be written
172 ;; to a timestamps file; not implemented yet.
174 (defvar muse-blosxom-page-date-alist nil)
176 (defun muse-blosxom-update-page-date-alist ()
177 "Add a date entry to `muse-blosxom-page-date-alist' for this page."
178 ;; Make current file be relative to base directory
179 (let ((rel-file
180 (concat
181 (file-name-as-directory
182 (or (muse-publishing-directive "category")
183 (file-relative-name
184 (file-name-directory
185 (expand-file-name muse-publishing-current-file))
186 (file-truename muse-blosxom-base-directory))))
187 (file-name-nondirectory muse-publishing-current-file))))
188 ;; Strip the file extension
189 (when muse-ignored-extensions-regexp
190 (setq rel-file (save-match-data
191 (and (string-match muse-ignored-extensions-regexp
192 rel-file)
193 (replace-match "" t t rel-file)))))
194 ;; Add to page-date alist
195 (add-to-list
196 'muse-blosxom-page-date-alist
197 `(,rel-file . ,(muse-publishing-directive "date")))))
199 ;; Enter a new blog entry
201 (defun muse-blosxom-title-to-file (title)
202 "Derive a file name from the given TITLE.
204 Feel free to overwrite this if you have a different concept of what
205 should be allowed in a filename."
206 (muse-replace-regexp-in-string (concat "[^-." muse-regexp-alnum "]")
207 "_" (downcase title)))
209 ;;;###autoload
210 (defun muse-blosxom-new-entry (category title)
211 "Start a new blog entry with given CATEGORY.
212 The filename of the blog entry is derived from TITLE.
213 The page will be initialized with the current date and TITLE."
214 (interactive
215 (list
216 (if muse-blosxom-use-tags
217 (let ((tag "foo")
218 (tags nil))
219 (while (progn (setq tag (read-string "Tag (RET to continue): "))
220 (not (string= tag "")))
221 (add-to-list 'tags tag t))
222 tags)
223 (completing-read "Category: "
224 (mapcar 'list (muse-project-recurse-directory
225 muse-blosxom-base-directory))))
226 (read-string "Title: ")))
227 (let ((file (muse-blosxom-title-to-file title)))
228 (muse-project-find-file
229 file "blosxom" nil
230 (if muse-blosxom-use-tags
231 (directory-file-name muse-blosxom-base-directory)
232 (concat (directory-file-name muse-blosxom-base-directory)
233 "/" category))))
234 (goto-char (point-min))
235 (insert "#date " (format-time-string "%4Y-%2m-%2d-%2H-%2M")
236 (if muse-blosxom-use-tags
237 (concat "\n#tags " (mapconcat #'identity category ","))
238 (concat "\n#category " category))
239 "\n#title " title
240 "\n\n")
241 (forward-line 2))
243 ;; Register the Blosxom Publisher
245 (unless (assoc "blosxom-html" muse-publishing-styles)
246 (muse-derive-style "blosxom-html" "html"
247 :suffix 'muse-blosxom-extension
248 :link-suffix 'muse-html-extension
249 :header 'muse-blosxom-header
250 :footer 'muse-blosxom-footer
251 :after 'muse-blosxom-update-page-date-alist)
253 (muse-derive-style "blosxom-xhtml" "xhtml"
254 :suffix 'muse-blosxom-extension
255 :link-suffix 'muse-xhtml-extension
256 :header 'muse-blosxom-header
257 :footer 'muse-blosxom-footer
258 :after 'muse-blosxom-update-page-date-alist))
260 (provide 'muse-blosxom)
262 ;;; muse-blosxom.el ends here