1 ;;; muse-journal.el --- Keep and publish a journal.
3 ;; Copyright (C) 2004, 2005 Free Software Foundation, Inc.
5 ;; This file is not part of GNU Emacs.
7 ;; This is free software; you can redistribute it and/or modify it under
8 ;; the terms of the GNU General Public License as published by the Free
9 ;; Software Foundation; either version 2, or (at your option) any later
12 ;; This is distributed in the hope that it will be useful, but WITHOUT
13 ;; ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 ;; FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
17 ;; You should have received a copy of the GNU General Public License
18 ;; along with GNU Emacs; see the file COPYING. If not, write to the
19 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
20 ;; Boston, MA 02110-1301, USA.
24 ;; The module facilitates the keeping and publication of a journal.
25 ;; When publishing to HTML, it assumes the form of a web log, or blog.
27 ;; The input format for each entry is as follows:
29 ;; * 20040317: Title of entry
31 ;; Text for the entry.
34 ;; "You know who you are. It comes down to a simple gut check: You
35 ;; either love what you do or you don't. Period." -- P. Bronson
38 ;; The "qotd", or Quote of the Day, is entirely optional. When
39 ;; generated to HTML, this entry is rendered as:
42 ;; <div id="entry-qotd">
43 ;; <h3>Quote of the Day:</h3>
44 ;; <p>"You know who you are. It comes down to a simple gut
45 ;; check: You either love what you do or you don't. Period."
48 ;; <div id="entry-body">
49 ;; <div id="entry-head">
50 ;; <div id="entry-date">
51 ;; <span class="date">March 17, 2004</span>
53 ;; <div id="entry-title">
54 ;; <h2>Title of entry</h2>
57 ;; <div id="entry-text">
58 ;; <p>Text for the entry.</p>
63 ;; The plurality of "div" tags makes it possible to display the
64 ;; entries in any form you wish, using a CSS style.
66 ;; Also, an .RDF file can be generated from your journal by publishing
67 ;; it with the "rdf" style. It uses the first two sentences of the
68 ;; first paragraph of each entry as its "description", and
69 ;; autogenerates tags for linking to the various entries.
75 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
77 ;; Muse Journal Publishing
79 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
81 (require 'muse-publish
)
86 (defgroup muse-journal nil
87 "Rules for transforming a journal into its final form."
90 (defcustom muse-journal-heading-regexp
91 "\\(?:\\([0-9]+\\)\\(?:: \\)?\\)?\\(.+?\\)?"
92 "A regexp that matches a journal heading.
93 Paren group 1 is the ISO date, group 2 is the optional category,
94 and group 3 is the optional heading for the entry."
98 (defcustom muse-journal-date-format
"%a, %e %b %Y"
99 "Date format to use for journal entries."
101 :group
'muse-journal
)
103 (defcustom muse-journal-html-heading-regexp
104 (concat "^<h2[^>]*>" muse-journal-heading-regexp
"</h2>$")
105 "A regexp that matches a journal heading from an HTML document.
106 Paren group 1 is the ISO date, group 2 is the optional category,
107 and group 3 is the optional heading for the entry."
109 :group
'muse-journal
)
111 (defcustom muse-journal-html-entry-template
113 <a name=\"%anchor%\" style=\"text-decoration: none\"> </a>
114 <div id=\"entry-body\">
115 <div id=\"entry-head\">
116 <div id=\"entry-date\">
117 <span class=\"date\">%date%</span>
119 <div id=\"entry-title\">
123 <div id=\"entry-text\">
124 <div id=\"entry-qotd\">
131 "Template used to publish individual journal entries as HTML."
133 :group
'muse-journal
)
135 (defcustom muse-journal-latex-section
136 "\\section*{%title% \\hfill {\\normalsize %date%}}
137 \\addcontentsline{toc}{chapter}{%title%}"
138 "Template used to publish a LaTeX section."
140 :group
'muse-journal
)
142 (defcustom muse-journal-latex-subsection
143 "\\subsection*{%title%}
144 \\addcontentsline{toc}{section}{%title%}"
145 "Template used to publish a LaTeX subsection."
147 :group
'muse-journal
)
149 (defcustom muse-journal-latex-markup-tags
150 '(("qotd" t nil muse-journal-latex-qotd-tag
))
151 "A list of tag specifications, for specially marking up LaTeX.
152 See `muse-publish-markup-tags' for more info."
153 :type
'(repeat (list (string :tag
"Markup tag")
154 (boolean :tag
"Expect closing tag" :value t
)
155 (boolean :tag
"Parse attributes" :value nil
)
157 :group
'muse-journal
)
159 ;; FIXME: This doesn't appear to be used.
160 (defun muse-journal-generate-pages ()
161 (let ((output-dir (muse-style-element :path
)))
162 (goto-char (point-min))
163 (while (re-search-forward muse-journal-heading-regexp nil t
)
164 (let* ((date (match-string 1))
165 (category (match-string 1))
166 (category-file (concat output-dir category
"/index.html"))
167 (heading (match-string 1)))
170 (defcustom muse-journal-rdf-extension
".rdf"
171 "Default file extension for publishing RDF (RSS 1.0) files."
173 :group
'muse-journal
)
175 (defcustom muse-journal-rdf-base-url
""
176 "The base URL of the website referenced by the RDF file."
178 :group
'muse-journal
)
180 (defcustom muse-journal-rdf-header
181 "<rdf:RDF xmlns:rdf=\"http://www.w3.org/1999/02/22-rdf-syntax-ns#\"
182 xmlns=\"http://purl.org/rss/1.0/\"
183 xmlns:dc=\"http://purl.org/dc/elements/1.1/\">
184 <channel rdf:about=\"<lisp>(concat (muse-style-element :base-url)
185 (muse-publish-output-name))</lisp>\">
186 <title><lisp>(muse-publishing-directive \"title\")</lisp></title>
187 <link><lisp>(concat (muse-style-element :base-url)
188 (concat (muse-page-name)
189 muse-html-extension))</lisp></link>
190 <description><lisp>(muse-publishing-directive \"desc\")</lisp></description>
193 <rdf:li resource=\"<lisp>
194 (concat (muse-style-element :base-url)
195 (concat (muse-page-name)
196 muse-html-extension))</lisp>\"/>
200 "Header used for publishing RDF (RSS 1.0) files."
201 :type
'(choice string file
)
202 :group
'muse-journal
)
204 (defcustom muse-journal-rdf-footer
206 "Footer used for publishing RDF (RSS 1.0) files."
207 :type
'(choice string file
)
208 :group
'muse-journal
)
210 (defcustom muse-journal-rdf-date-format
212 "Date format to use for RDF entries."
214 :group
'muse-journal
)
216 (defcustom muse-journal-rdf-entry-template
217 " <item rdf:about=\"%link%#%anchor%\">
218 <title>%title%</title>
222 <link>%link%#%anchor%</link>
223 <dc:date>%date%</dc:date>
224 <dc:creator>%maintainer%</dc:creator>
226 "Template used to publish individual journal entries as RDF."
228 :group
'muse-journal
)
230 (defcustom muse-journal-rdf-summarize-entries t
231 "If non-nil, include only summaries in the RDF file, not the full data."
233 :group
'muse-journal
)
235 (defcustom muse-journal-rss-extension
".xml"
236 "Default file extension for publishing RSS 2.0 files."
238 :group
'muse-journal
)
240 (defcustom muse-journal-rss-base-url
""
241 "The base URL of the website referenced by the RSS file."
243 :group
'muse-journal
)
245 (defcustom muse-journal-rss-header
246 "<\?xml version=\"1.0\" encoding=\"<lisp>
247 (muse-html-encoding)</lisp>\"?>
248 <rss version=\"2.0\">
250 <title><lisp>(muse-publishing-directive \"title\")</lisp></title>
251 <link><lisp>(concat (muse-style-element :base-url)
252 (concat (muse-page-name)
253 muse-html-extension))</lisp></link>
254 <description><lisp>(muse-publishing-directive \"desc\")</lisp></description>
255 <language>en-us</language>
256 <generator>Emacs Muse</generator>"
257 "Header used for publishing RSS 2.0 files."
258 :type
'(choice string file
)
259 :group
'muse-journal
)
261 (defcustom muse-journal-rss-footer
264 "Footer used for publishing RSS 2.0 files."
265 :type
'(choice string file
)
266 :group
'muse-journal
)
268 (defcustom muse-journal-rss-date-format
269 "%a, %d %b %Y %H:%M:%S %Z"
270 "Date format to use for RSS 2.0 entries."
272 :group
'muse-journal
)
274 (defcustom muse-journal-rss-entry-template
276 <title>%title%</title>
277 <link>%link%#%anchor%</link>
278 <description>%desc%</description>
279 <author><lisp>(muse-publishing-directive \"author\")</lisp></author>
280 <pubDate>%date%</pubDate>
281 <guid>%link%#%anchor%</guid>
284 "Template used to publish individual journal entries as RSS 2.0."
286 :group
'muse-journal
)
288 (defcustom muse-journal-rss-enclosure-types-alist
289 '(("mp3" .
"audio/mpeg"))
290 "File types that are accepted as RSS enclosures.
291 This is an alist that maps file extension to content type.
292 Useful for podcasting."
293 :type
'(alist :key-type string
:value-type string
)
294 :group
'muse-journal
)
296 (defcustom muse-journal-rss-summarize-entries nil
297 "If non-nil, include only summaries in the RSS file, not the full data.
298 Many RSS subscribers find this annoying."
300 :group
'muse-journal
)
302 (defcustom muse-journal-rss-markup-regexps
303 '((10000 muse-explicit-link-regexp
0 "\\2"))
304 "List of markup rules for publishing a Muse journal page to RSS 2.0.
305 For more information on the structure of this list, see
306 `muse-publish-markup-regexps'."
307 :type
'(repeat (choice
308 (list :tag
"Markup rule"
310 (choice regexp symbol
)
312 (choice string function symbol
))
314 :group
'muse-journal
)
316 (defcustom muse-journal-rss-markup-functions
320 "An alist of style types to custom functions for that kind of text.
321 For more on the structure of this list, see
322 `muse-publish-markup-functions'."
323 :type
'(alist :key-type symbol
:value-type function
)
324 :group
'muse-journal
)
326 (defun muse-journal-anchorize-title (title)
328 (if (string-match "(" title
)
329 (setq title
(substring title
0 (match-beginning 0))))
330 (if (string-match "<[^>]+>" title
)
331 (setq title
(replace-match "" nil nil title
)))
332 (downcase (muse-replace-regexp-in-string "[^a-zA-Z0-9_]" "" title
))))
334 (defun muse-journal-sort-entries (&optional direction
)
340 (if (re-search-forward "^\\* [0-9]+" nil t
)
341 (goto-char (match-beginning 0))
342 (goto-char (point-max)))))
345 (if (re-search-forward "^\\* [0-9]+" nil t
)
346 (goto-char (1- (match-beginning 0)))
347 (goto-char (point-max)))))
355 (defun muse-journal-html-munge-buffer ()
356 (goto-char (point-min))
357 (let ((heading-regexp muse-journal-html-heading-regexp
)
358 (inhibit-read-only t
))
359 (while (re-search-forward heading-regexp nil t
)
360 (let* ((date (match-string 1))
362 (title (match-string 2))
365 (delete-region (match-beginning 0) (match-end 0))
368 (while (string-match "\\(^<[^>]+>\\|<[^>]+>$\\)" clean-title
)
369 (setq clean-title
(replace-match "" nil nil clean-title
)))))
373 (concat "\\`\\([1-9][0-9][0-9][0-9]\\)[./]?"
374 "\\([0-1][0-9]\\)[./]?\\([0-3][0-9]\\)") date
))
378 (string-to-number (match-string 3 date
))
379 (string-to-number (match-string 2 date
))
380 (string-to-number (match-string 1 date
))
382 date
(concat (format-time-string
383 muse-journal-date-format datestamp
)
384 (substring date
(match-end 0))))))
387 (point) (if (re-search-forward
388 (concat "\\(^<hr>$\\|"
389 heading-regexp
"\\)") nil t
)
392 (goto-char (point-max))
393 (while (and (not (bobp))
394 (eq ?\
(char-syntax (char-before))))
396 (goto-char (point-min))
397 (while (and (not (eobp))
398 (eq ?\
(char-syntax (char-after))))
401 (when (search-forward "<qotd>" nil t
)
402 (let ((tag-beg (match-beginning 0))
404 (re-search-forward "</qotd>\n*")
405 (setq qotd
(buffer-substring-no-properties
406 beg
(match-beginning 0)))
407 (delete-region tag-beg
(match-end 0)))))
408 (setq text
(buffer-string))
409 (delete-region (point-min) (point-max))
410 (let ((entry muse-journal-html-entry-template
))
411 (while (string-match "%date%" entry
)
412 (setq entry
(replace-match (or date
"") nil t entry
)))
413 (while (string-match "%title%" entry
)
414 (setq entry
(replace-match (or title
" ") nil t entry
)))
415 (while (string-match "%anchor%" entry
)
416 (setq entry
(replace-match
417 (muse-journal-anchorize-title
418 (or clean-title orig-date
))
420 (while (string-match "%qotd%" entry
)
421 (setq entry
(replace-match (or qotd
"") nil t entry
)))
422 (while (string-match "%text%" entry
)
423 (setq entry
(replace-match text nil t entry
)))
426 (goto-char (point-min))
427 (search-forward "<div id=\"entry-qotd\">")
428 (let ((beg (match-beginning 0)))
429 (re-search-forward "</div>\n*")
430 (delete-region beg
(point))))))))))
432 (defun muse-journal-latex-munge-buffer ()
433 (goto-char (point-min))
434 (let ((heading-regexp
435 (concat "^" (regexp-quote (muse-markup-text 'section
))
436 muse-journal-heading-regexp
437 (regexp-quote (muse-markup-text 'section-end
)) "$"))
438 (inhibit-read-only t
))
439 (when (re-search-forward heading-regexp nil t
)
440 (goto-char (match-beginning 0))
444 (if (re-search-forward heading-regexp nil t
)
445 (goto-char (match-beginning 0))
446 (goto-char (point-max)))))
449 (if (re-search-forward heading-regexp nil t
)
450 (goto-char (1- (match-beginning 0)))
451 (goto-char (point-max)))))
458 (while (re-search-forward heading-regexp nil t
)
459 (let ((date (match-string 1))
460 (title (match-string 2))
461 ;; FIXME: Nothing is done with qotd
466 (concat "\\([1-9][0-9][0-9][0-9]\\)[./]?"
467 "\\([0-1][0-9]\\)[./]?\\([0-3][0-9]\\)") date
))
468 (setq date
(encode-time
470 (string-to-number (match-string 3 date
))
471 (string-to-number (match-string 2 date
))
472 (string-to-number (match-string 1 date
))
474 date
(format-time-string
475 muse-journal-date-format date
))))
477 (setq section muse-journal-latex-section
)
478 (while (string-match "%title%" section
)
479 (setq section
(replace-match (or title
"Untitled")
481 (while (string-match "%date%" section
)
482 (setq section
(replace-match (or date
"") nil t section
))))
483 (replace-match section nil t
))))
484 (goto-char (point-min))
485 (let ((subheading-regexp
486 (concat "^" (regexp-quote (muse-markup-text 'subsection
))
488 (regexp-quote (muse-markup-text 'subsection-end
)) "$"))
489 (inhibit-read-only t
))
490 (while (re-search-forward subheading-regexp nil t
)
491 (let ((subsection muse-journal-latex-subsection
))
493 (let ((title (match-string 1)))
494 (while (string-match "%title%" subsection
)
495 (setq subsection
(replace-match title nil t subsection
)))))
496 (replace-match subsection nil t
)))))
498 (defun muse-journal-latex-qotd-tag (beg end
)
500 (insert (muse-markup-text 'begin-quote
))
502 (insert (muse-markup-text 'end-quote
)))
504 (defun muse-journal-rss-munge-buffer ()
505 (goto-char (point-min))
506 (let ((heading-regexp (concat "^\\* " muse-journal-heading-regexp
"$"))
507 (inhibit-read-only t
))
508 (while (re-search-forward heading-regexp nil t
)
509 (let* ((date (match-string 1))
511 (title (match-string 2))
512 ;; FIXME: Nothing is done with qotd
516 (if (string-match muse-explicit-link-regexp title
)
517 (setq enclosure
(match-string 1 title
)
518 title
(match-string 2 title
)))))
522 (concat "\\([1-9][0-9][0-9][0-9]\\)[./]?"
523 "\\([0-1][0-9]\\)[./]?\\([0-3][0-9]\\)") date
))
524 (setq date
(encode-time 0 0 0
525 (string-to-number (match-string 3 date
))
526 (string-to-number (match-string 2 date
))
527 (string-to-number (match-string 1 date
))
529 date
(format-time-string
530 (muse-style-element :date-format
) date
))))
534 (if (re-search-forward heading-regexp nil t
)
536 (if (re-search-forward "^Footnotes:" nil t
)
539 (goto-char (point-min))
540 (delete-region (point) (muse-line-end-position))
541 (re-search-forward "</qotd>\n+" nil t
)
542 (while (and (char-after)
543 (eq ?\
(char-syntax (char-after))))
546 (if (muse-style-element :summarize
)
549 (setq desc
(concat (buffer-substring beg
(point)) "...")))
551 (muse-publish-markup-buffer "rss-entry" "html")
552 (goto-char (point-min))
553 (re-search-forward "Page published by Emacs Muse")
554 (goto-char (muse-line-end-position))
556 (re-search-forward "Page published by Emacs Muse")
557 (goto-char (muse-line-beginning-position))
558 (setq desc
(concat "<![CDATA[" (buffer-substring beg
(point))
560 (delete-region (point-min) (point-max))
561 (let ((entry (muse-style-element :entry-template
)))
562 (while (string-match "%date%" entry
)
563 (setq entry
(replace-match (or date
"") nil t entry
)))
564 (while (string-match "%title%" entry
)
565 (setq entry
(replace-match (or title
"Untitled") nil t entry
)))
566 (while (string-match "%desc%" entry
)
567 (setq entry
(replace-match desc nil t entry
)))
568 (while (string-match "%enclosure%" entry
)
576 "<enclosure url=\"%s\" %stype=\"%s\"/>"
577 (if (string-match "//" enclosure
)
579 (concat (muse-style-element :base-url
)
582 (expand-file-name enclosure
583 (muse-style-element :path
))))
584 (if (file-readable-p file
)
585 (format "length=\"%d\" "
586 (nth 7 (file-attributes file
)))
588 (if (string-match "\\.\\([^.]+\\)$" enclosure
)
589 (let* ((ext (match-string 1 enclosure
))
592 ext muse-journal-rss-enclosure-types-alist
)))
595 "application/octet-stream"))))))
597 (while (string-match "%link%" entry
)
598 (setq entry
(replace-match
599 (concat (muse-style-element :base-url
)
600 (concat (muse-page-name)
601 muse-html-extension
))
603 (while (string-match "%anchor%" entry
)
604 (setq entry
(replace-match
605 (muse-journal-anchorize-title (or title orig-date
))
607 (while (string-match "%maintainer%" entry
)
608 (setq entry
(replace-match
609 (or (muse-style-element :maintainer
)
610 (concat "webmaster@" (system-name)))
614 (delete-region (point) (point-max)))))
616 (unless (assoc "journal-html" muse-publishing-styles
)
617 (muse-derive-style "journal-html" "html"
618 :before-end
'muse-journal-html-munge-buffer
)
620 (muse-derive-style "journal-xhtml" "xhtml"
621 :before-end
'muse-journal-html-munge-buffer
)
623 (muse-derive-style "journal-latex" "latex"
624 :tags
'muse-journal-latex-markup-tags
625 :before-end
'muse-journal-latex-munge-buffer
)
627 (muse-derive-style "journal-pdf" "pdf"
628 :tags
'muse-journal-latex-markup-tags
629 :before-end
'muse-journal-latex-munge-buffer
)
631 (muse-derive-style "journal-book-latex" "book-latex"
633 :tags
'muse-journal-latex-markup-tags
634 :before-end
'muse-journal-latex-munge-buffer
)
636 (muse-derive-style "journal-book-pdf" "book-pdf"
638 :tags
'muse-journal-latex-markup-tags
639 :before-end
'muse-journal-latex-munge-buffer
)
641 (muse-define-style "journal-rdf"
642 :suffix
'muse-journal-rdf-extension
643 :regexps
'muse-journal-rss-markup-regexps
644 :functions
'muse-journal-rss-markup-functions
645 :before
'muse-journal-rss-munge-buffer
646 :header
'muse-journal-rdf-header
647 :footer
'muse-journal-rdf-footer
648 :date-format
'muse-journal-rdf-date-format
649 :entry-template
'muse-journal-rdf-entry-template
650 :base-url
'muse-journal-rdf-base-url
651 :summarize
'muse-journal-rdf-summarize-entries
)
653 (muse-define-style "journal-rss"
654 :suffix
'muse-journal-rss-extension
655 :regexps
'muse-journal-rss-markup-regexps
656 :functions
'muse-journal-rss-markup-functions
657 :before
'muse-journal-rss-munge-buffer
658 :header
'muse-journal-rss-header
659 :footer
'muse-journal-rss-footer
660 :date-format
'muse-journal-rss-date-format
661 :entry-template
'muse-journal-rss-entry-template
662 :base-url
'muse-journal-rss-base-url
663 :summarize
'muse-journal-rss-summarize-entries
))
665 (provide 'muse-journal
)
667 ;;; muse-journal.el ends here