Merged from hodique@lifl.fr--2005 (patch 2-6), without the WikiWord change.
[muse-el.git] / muse-blosxom.el
blob95629d114f465793c21235499b7396f2ebc5d8c3
1 ;;; muse-blosxom.el --- Publish a document tree for serving by (py)Blosxom
3 ;; Copyright (C) 2004, 2005 Free Software Foundation, Inc.
5 ;; Date: Wed, 23 March 2005
6 ;; Author: Michael Olson (mwolson AT gnu DOT org)
7 ;; Maintainer: Michael Olson (mwolson AT gnu DOT org)
9 ;; This file is not part of GNU Emacs.
11 ;; This is free software; you can redistribute it and/or modify it under
12 ;; the terms of the GNU General Public License as published by the Free
13 ;; Software Foundation; either version 2, or (at your option) any later
14 ;; version.
16 ;; This is distributed in the hope that it will be useful, but WITHOUT
17 ;; ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18 ;; FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
19 ;; for more details.
21 ;; You should have received a copy of the GNU General Public License
22 ;; along with GNU Emacs; see the file COPYING. If not, write to the
23 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
24 ;; Boston, MA 02110-1301, USA.
26 ;;; Commentary:
28 ;; The Blosxom publishing style publishes a tree of categorised files
29 ;; to a mirrored tree of blosxom stories to be served by blosxom.cgi
30 ;; or pyblosxom.cgi.
32 ;; Serving entries with (py)blosxom
33 ;; --------------------------------
35 ;; Each Blosxom file must include `#date yyyy-mm-dd', or optionally
36 ;; the longer `#date yyyy-mm-dd-hh-mm', a title (using the `#title'
37 ;; directive) plus whatever normal content is desired.
39 ;; The date directive is not used directly by (py)blosxom or this
40 ;; program. You need to find two additional items to make use of this
41 ;; feature.
43 ;; 1. A script to gather date directives from the entire blog tree
44 ;; into a single file. The file must associate a blog entry with
45 ;; a date.
47 ;; 2. A plugin for (py)blosxom that reads this file.
49 ;; These 2 things are provided for pyblosxom in the contrib/pyblosxom
50 ;; subdirectory. `getstamps.py' provides the 1st service, while
51 ;; `hardcodedates.py' provides the second service. Eventually it is
52 ;; hoped that a blosxom plugin and script will be found/written.
54 ;; Creating new blog entries
55 ;; -------------------------
57 ;; There is a function called `muse-blosxom-new-entry' that will
58 ;; automate the process of making a new blog entry. To make use of
59 ;; it, do the following.
61 ;; - Customize `muse-blosxom-base-directory' to the location that
62 ;; your blog entries are stored.
64 ;; - Assign the `muse-blosxom-base-directory' function to a key
65 ;; sequence. I use the following code to assign this function to
66 ;; `C-c p l'.
68 ;; (global-set-key "\C-cpl" 'muse-blosxom-new-entry)
70 ;; - You should create your directory structure ahead of time under
71 ;; your base directory. These directories, which correspond with
72 ;; category names, may be nested.
74 ;; - When you enter this key sequence, you will be prompted for the
75 ;; category of your entry and its title. Upon entering this
76 ;; information, a new file will be created that corresponds with
77 ;; the title, but in lowercase letters and having special
78 ;; characters converted to underscores. The title and date
79 ;; directives will be inserted automatically.
81 ;;; Contributors:
83 ;; Gary Vaughan (gary AT gnu DOT org) is the original author of
84 ;; `emacs-wiki-blosxom.el', which is the ancestor of this file.
86 ;; Brad Collins (brad AT chenla DOT org) ported this file to Muse.
88 ;; Michael Olson (mwolson AT gnu DOT org) further adapted this file to
89 ;; Muse and continues to maintain it.
91 ;;; Code:
93 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
95 ;; Muse Blosxom Publishing
97 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
99 (require 'muse-project)
100 (require 'muse-publish)
101 (require 'muse-html)
103 (defgroup muse-blosxom nil
104 "Options controlling the behavior of Muse BLOSXOM publishing.
105 See `muse-blosxom' for more information."
106 :group 'muse-publish)
108 (defcustom muse-blosxom-extension ".txt"
109 "Default file extension for publishing BLOSXOM files."
110 :type 'string
111 :group 'muse-blosxom)
113 (defcustom muse-blosxom-header
114 "<lisp>(muse-publishing-directive \"title\")</lisp>\n"
115 "Header used for publishing BLOSXOM files."
116 :type '(choice string file)
117 :group 'muse-blosxom)
119 (defcustom muse-blosxom-footer ""
120 "Footer used for publishing BLOSXOM files."
121 :type '(choice string file)
122 :group 'muse-blosxom)
124 ;; Maintain (published-file . date) alist
126 (defvar muse-blosxom-page-date-alist nil)
128 ;; This isn't really used for anything, but it may be someday
129 (defun muse-blosxom-markup-date-directive ()
130 "Add a date entry to `muse-blosxom-page-date-alist' for this page."
131 (let ((date (match-string 1)))
132 (save-match-data
133 (add-to-list
134 'muse-blosxom-page-date-alist
135 `(,buffer-file-name . ,date))))
138 ;; Enter a new blog entry
140 (defcustom muse-blosxom-base-directory "~/Blog"
141 "Base directory of blog entries, used by `muse-blosxom-new-entry'."
142 :type 'directory
143 :group 'muse-blosxom)
145 (defun muse-blosxom-get-categories (&optional base)
146 "Retrieve all of the categories from a Blosxom project.
147 The base directory is specified by BASE, and defaults to
148 `muse-blosxom-base-directory'.
150 Directories starting with \".\" will be ignored."
151 (unless base (setq base muse-blosxom-base-directory))
152 (let (list dir)
153 (dolist (file (directory-files base t "^[^.]"))
154 (when (file-directory-p file) ; must be a directory
155 (setq dir (file-name-nondirectory file))
156 (push dir list)
157 (nconc list (mapcar #'(lambda (item)
158 (concat dir "/" item))
159 (muse-blosxom-get-categories file)))))
160 list))
162 (defun muse-blosxom-title-to-file (title)
163 "Derive a file name from the given TITLE.
165 Feel free to overwrite this if you have a different concept of what
166 should be allowed in a filename."
167 (replace-regexp-in-string (concat "[^-." muse-regexp-alnum "]")
168 "_" (downcase title)))
170 (defun muse-blosxom-new-entry (category title)
171 "Start a new blog entry with given CATEGORY.
172 The filename of the blog entry is derived from TITLE.
173 The page will be initialized with the current date and TITLE."
174 (interactive
175 (list
176 (completing-read "Category: " (muse-blosxom-get-categories))
177 (read-string "Title: ")))
178 (let ((file (muse-blosxom-title-to-file title)))
179 (muse-project-find-file
180 file "blosxom" nil
181 (concat (directory-file-name muse-blosxom-base-directory)
182 "/" category)))
183 (goto-char (point-min))
184 (insert "#date " (format-time-string "%4Y-%2m-%2d-%2H-%2M")
185 "\n#title " title
186 "\n\n")
187 (forward-line 2))
189 ;; Register the BLOSXOM Publisher
191 (unless (assoc "blosxom-html" muse-publishing-styles)
192 (muse-derive-style "blosxom-html" "html"
193 :suffix 'muse-blosxom-extension
194 :header 'muse-blosxom-header
195 :footer 'muse-blosxom-footer)
197 (muse-derive-style "blosxom-xhtml" "xhtml"
198 :suffix 'muse-blosxom-extension
199 :header 'muse-blosxom-header
200 :footer 'muse-blosxom-footer))
202 (provide 'muse-blosxom)
204 ;;; muse-blosxom.el ends here