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:
41 ;; <div class="entry">
42 ;; <div class="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 class="entry-body">
49 ;; <div class="entry-head">
50 ;; <div class="entry-date">
51 ;; <span class="date">March 17, 2004</span>
53 ;; <div class="entry-title">
54 ;; <h2>Title of entry</h2>
57 ;; <div class="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[^>\n]*>" 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
112 "<div class=\"entry\">
113 <a name=\"%anchor%\" style=\"text-decoration: none\"> </a>
114 <div class=\"entry-body\">
115 <div class=\"entry-head\">
116 <div class=\"entry-date\">
117 <span class=\"date\">%date%</span>
119 <div class=\"entry-title\">
123 <div class=\"entry-text\">
124 <div class=\"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-link-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 This may be text or a filename."
203 :group
'muse-journal
)
205 (defcustom muse-journal-rdf-footer
207 "Footer used for publishing RDF (RSS 1.0) files.
208 This may be text or a filename."
210 :group
'muse-journal
)
212 (defcustom muse-journal-rdf-date-format
214 "Date format to use for RDF entries."
216 :group
'muse-journal
)
218 (defcustom muse-journal-rdf-entry-template
219 " <item rdf:about=\"%link%#%anchor%\">
220 <title>%title%</title>
224 <link>%link%#%anchor%</link>
225 <dc:date>%date%</dc:date>
226 <dc:creator>%maintainer%</dc:creator>
228 "Template used to publish individual journal entries as RDF."
230 :group
'muse-journal
)
232 (defcustom muse-journal-rdf-summarize-entries t
233 "If non-nil, include only summaries in the RDF file, not the full data."
235 :group
'muse-journal
)
237 (defcustom muse-journal-rss-extension
".xml"
238 "Default file extension for publishing RSS 2.0 files."
240 :group
'muse-journal
)
242 (defcustom muse-journal-rss-base-url
""
243 "The base URL of the website referenced by the RSS file."
245 :group
'muse-journal
)
247 (defcustom muse-journal-rss-header
248 "<\?xml version=\"1.0\" encoding=\"<lisp>
249 (muse-html-encoding)</lisp>\"?>
250 <rss version=\"2.0\">
252 <title><lisp>(muse-publishing-directive \"title\")</lisp></title>
253 <link><lisp>(concat (muse-style-element :base-url)
254 (concat (muse-page-name)
255 muse-html-extension))</lisp></link>
256 <description><lisp>(muse-publishing-directive \"desc\")</lisp></description>
257 <language>en-us</language>
258 <generator>Emacs Muse</generator>"
259 "Header used for publishing RSS 2.0 files. This may be text or a filename."
261 :group
'muse-journal
)
263 (defcustom muse-journal-rss-footer
266 "Footer used for publishing RSS 2.0 files. This may be text or a filename."
268 :group
'muse-journal
)
270 (defcustom muse-journal-rss-date-format
271 "%a, %d %b %Y %H:%M:%S %Z"
272 "Date format to use for RSS 2.0 entries."
274 :group
'muse-journal
)
276 (defcustom muse-journal-rss-entry-template
278 <title>%title%</title>
279 <link>%link%#%anchor%</link>
280 <description>%desc%</description>
281 <author><lisp>(muse-publishing-directive \"author\")</lisp></author>
282 <pubDate>%date%</pubDate>
283 <guid>%link%#%anchor%</guid>
286 "Template used to publish individual journal entries as RSS 2.0."
288 :group
'muse-journal
)
290 (defcustom muse-journal-rss-enclosure-types-alist
291 '(("mp3" .
"audio/mpeg"))
292 "File types that are accepted as RSS enclosures.
293 This is an alist that maps file extension to content type.
294 Useful for podcasting."
295 :type
'(alist :key-type string
:value-type string
)
296 :group
'muse-journal
)
298 (defcustom muse-journal-rss-summarize-entries nil
299 "If non-nil, include only summaries in the RSS file, not the full data.
300 Many RSS subscribers find this annoying."
302 :group
'muse-journal
)
304 (defcustom muse-journal-rss-markup-regexps
305 '((10000 muse-explicit-link-regexp
0 "\\2"))
306 "List of markup rules for publishing a Muse journal page to RSS 2.0.
307 For more information on the structure of this list, see
308 `muse-publish-markup-regexps'."
309 :type
'(repeat (choice
310 (list :tag
"Markup rule"
312 (choice regexp symbol
)
314 (choice string function symbol
))
316 :group
'muse-journal
)
318 (defcustom muse-journal-rss-markup-functions
322 "An alist of style types to custom functions for that kind of text.
323 For more on the structure of this list, see
324 `muse-publish-markup-functions'."
325 :type
'(alist :key-type symbol
:value-type function
)
326 :group
'muse-journal
)
328 (defun muse-journal-anchorize-title (title)
330 (if (string-match "(" title
)
331 (setq title
(substring title
0 (match-beginning 0))))
332 (if (string-match "<[^>]+>" title
)
333 (setq title
(replace-match "" nil nil title
)))
334 (downcase (muse-replace-regexp-in-string "[^a-zA-Z0-9_]" "" title
))))
336 (defun muse-journal-sort-entries (&optional direction
)
342 (if (re-search-forward "^\\* [0-9]+" nil t
)
343 (goto-char (match-beginning 0))
344 (goto-char (point-max)))))
347 (if (re-search-forward "^\\* [0-9]+" nil t
)
348 (goto-char (1- (match-beginning 0)))
349 (goto-char (point-max)))))
357 (defun muse-journal-html-munge-buffer ()
358 (goto-char (point-min))
359 (let ((heading-regexp muse-journal-html-heading-regexp
)
360 (inhibit-read-only t
))
361 (while (re-search-forward heading-regexp nil t
)
362 (let* ((date (match-string 1))
364 (title (match-string 2))
367 (delete-region (match-beginning 0) (match-end 0))
370 (while (string-match "\\(^<[^>]+>\\|<[^>]+>$\\)" clean-title
)
371 (setq clean-title
(replace-match "" nil nil clean-title
)))))
375 (concat "\\`\\([1-9][0-9][0-9][0-9]\\)[./]?"
376 "\\([0-1][0-9]\\)[./]?\\([0-3][0-9]\\)") date
))
380 (string-to-number (match-string 3 date
))
381 (string-to-number (match-string 2 date
))
382 (string-to-number (match-string 1 date
))
384 date
(concat (format-time-string
385 muse-journal-date-format datestamp
)
386 (substring date
(match-end 0))))))
389 (point) (if (re-search-forward
390 (concat "\\(^<hr>$\\|"
391 heading-regexp
"\\)") nil t
)
394 (goto-char (point-max))
395 (while (and (not (bobp))
396 (eq ?\
(char-syntax (char-before))))
398 (goto-char (point-min))
399 (while (and (not (eobp))
400 (eq ?\
(char-syntax (char-after))))
403 (when (search-forward "<qotd>" nil t
)
404 (let ((tag-beg (match-beginning 0))
406 (re-search-forward "</qotd>\n*")
407 (setq qotd
(buffer-substring-no-properties
408 beg
(match-beginning 0)))
409 (delete-region tag-beg
(match-end 0)))))
410 (setq text
(buffer-string))
411 (delete-region (point-min) (point-max))
412 (let ((entry muse-journal-html-entry-template
))
413 (muse-insert-markup entry
)
414 (goto-char (point-min))
415 (while (search-forward "%date%" nil t
)
416 (replace-match (or date
"") nil t
))
417 (goto-char (point-min))
418 (while (search-forward "%title%" nil t
)
419 (replace-match (or title
" ") nil t
))
420 (goto-char (point-min))
421 (while (search-forward "%anchor%" nil t
)
422 (replace-match (muse-journal-anchorize-title
423 (or clean-title orig-date
))
425 (goto-char (point-min))
426 (while (search-forward "%qotd%" nil t
)
427 (replace-match (or qotd
"") nil t
))
428 (goto-char (point-min))
429 (while (search-forward "%text%" nil t
)
430 (replace-match text nil t
))
432 (goto-char (point-min))
433 (when (search-forward "<div class=\"entry-qotd\">" nil t
)
434 (let ((beg (match-beginning 0)))
435 (re-search-forward "</div>\n*" nil t
)
436 (delete-region beg
(point)))))))))))
438 (defun muse-journal-latex-munge-buffer ()
439 (goto-char (point-min))
440 (let ((heading-regexp
441 (concat "^" (regexp-quote (muse-markup-text 'section
))
442 muse-journal-heading-regexp
443 (regexp-quote (muse-markup-text 'section-end
)) "$"))
444 (inhibit-read-only t
))
445 (when (re-search-forward heading-regexp nil t
)
446 (goto-char (match-beginning 0))
450 (if (re-search-forward heading-regexp nil t
)
451 (goto-char (match-beginning 0))
452 (goto-char (point-max)))))
455 (if (re-search-forward heading-regexp nil t
)
456 (goto-char (1- (match-beginning 0)))
457 (goto-char (point-max)))))
464 (while (re-search-forward heading-regexp nil t
)
465 (let ((date (match-string 1))
466 (title (match-string 2))
467 ;; FIXME: Nothing is done with qotd
472 (concat "\\([1-9][0-9][0-9][0-9]\\)[./]?"
473 "\\([0-1][0-9]\\)[./]?\\([0-3][0-9]\\)") date
))
474 (setq date
(encode-time
476 (string-to-number (match-string 3 date
))
477 (string-to-number (match-string 2 date
))
478 (string-to-number (match-string 1 date
))
480 date
(format-time-string
481 muse-journal-date-format date
))))
483 (narrow-to-region (match-beginning 0) (match-end 0))
484 (delete-region (point-min) (point-max))
485 (muse-insert-markup muse-journal-latex-section
)
486 (goto-char (point-min))
487 (while (search-forward "%title%" nil t
)
488 (replace-match (or title
"Untitled") nil t
))
489 (goto-char (point-min))
490 (while (search-forward "%date%" nil t
)
491 (replace-match (or date
"") nil t
))))))
492 (goto-char (point-min))
493 (let ((subheading-regexp
494 (concat "^" (regexp-quote (muse-markup-text 'subsection
))
496 (regexp-quote (muse-markup-text 'subsection-end
)) "$"))
497 (inhibit-read-only t
))
498 (while (re-search-forward subheading-regexp nil t
)
499 (let ((title (match-string 1)))
501 (narrow-to-region (match-beginning 0) (match-end 0))
502 (delete-region (point-min) (point-max))
503 (muse-insert-markup muse-journal-latex-subsection
)
504 (goto-char (point-min))
505 (while (search-forward "%title%" nil t
)
506 (replace-match title nil t
)))))))
508 (defun muse-journal-latex-qotd-tag (beg end
)
510 (muse-insert-markup (muse-markup-text 'begin-quote
))
512 (muse-insert-markup (muse-markup-text 'end-quote
)))
514 (defun muse-journal-rss-munge-buffer ()
515 (goto-char (point-min))
516 (let ((heading-regexp (concat "^\\* " muse-journal-heading-regexp
"$"))
517 (inhibit-read-only t
))
518 (while (re-search-forward heading-regexp nil t
)
519 (let* ((date (match-string 1))
521 (title (match-string 2))
522 ;; FIXME: Nothing is done with qotd
526 (if (string-match muse-explicit-link-regexp title
)
527 (setq enclosure
(match-string 1 title
)
528 title
(match-string 2 title
)))))
532 (concat "\\([1-9][0-9][0-9][0-9]\\)[./]?"
533 "\\([0-1][0-9]\\)[./]?\\([0-3][0-9]\\)") date
))
534 (setq date
(encode-time 0 0 0
535 (string-to-number (match-string 3 date
))
536 (string-to-number (match-string 2 date
))
537 (string-to-number (match-string 1 date
))
539 date
(format-time-string
540 (muse-style-element :date-format
) date
))))
544 (if (re-search-forward heading-regexp nil t
)
546 (if (re-search-forward "^Footnotes:" nil t
)
549 (goto-char (point-min))
550 (delete-region (point) (muse-line-end-position))
551 (re-search-forward "</qotd>\n+" nil t
)
552 (while (and (char-after)
553 (eq ?\
(char-syntax (char-after))))
556 (if (muse-style-element :summarize
)
559 (setq desc
(concat (buffer-substring beg
(point)) "...")))
561 (muse-publish-markup-buffer "rss-entry" "html")
562 (goto-char (point-min))
563 (if (re-search-forward "Page published by Emacs Muse" nil t
)
564 (goto-char (muse-line-end-position))
565 (muse-display-warning
567 "Cannot find 'Page published by Emacs Muse begins here'.\n"
568 "You will probably need this text in your header."))
569 (goto-char (point-min)))
571 (if (re-search-forward "Page published by Emacs Muse" nil t
)
572 (goto-char (muse-line-beginning-position))
573 (muse-display-warning
575 "Cannot find 'Page published by Emacs Muse ends here'.\n"
576 "You will probably need this text in your footer."))
577 (goto-char (point-max)))
578 (setq desc
(concat "<![CDATA[" (buffer-substring beg
(point))
580 (delete-region (point-min) (point-max))
581 (let ((entry (muse-style-element :entry-template
)))
582 (muse-insert-markup entry
)
583 (goto-char (point-min))
584 (while (search-forward "%date%" nil t
)
585 (replace-match (or date
"") nil t
))
586 (goto-char (point-min))
587 (while (search-forward "%title%" nil t
)
588 (replace-match (or title
"Untitled") nil t
))
589 (goto-char (point-min))
590 (while (search-forward "%desc%" nil t
)
591 (replace-match desc nil t
))
592 (goto-char (point-min))
593 (while (search-forward "%enclosure%" nil t
)
599 "<enclosure url=\"%s\" %stype=\"%s\"/>"
600 (if (string-match "//" enclosure
)
602 (concat (muse-style-element :base-url
)
605 (expand-file-name enclosure
606 (muse-style-element :path
))))
607 (if (file-readable-p file
)
608 (format "length=\"%d\" "
609 (nth 7 (file-attributes file
)))
611 (if (string-match "\\.\\([^.]+\\)$" enclosure
)
612 (let* ((ext (match-string 1 enclosure
))
615 ext muse-journal-rss-enclosure-types-alist
)))
618 "application/octet-stream"))))))
620 (goto-char (point-min))
621 (while (search-forward "%link%" nil t
)
623 (concat (muse-style-element :base-url
)
624 (concat (muse-page-name)
625 muse-html-extension
))
627 (goto-char (point-min))
628 (while (search-forward "%anchor%" nil t
)
630 (muse-journal-anchorize-title (or title orig-date
))
632 (goto-char (point-min))
633 (while (search-forward "%maintainer%" nil t
)
635 (or (muse-style-element :maintainer
)
636 (concat "webmaster@" (system-name)))
639 (delete-region (point) (point-max)))))
641 (unless (assoc "journal-html" muse-publishing-styles
)
642 (muse-derive-style "journal-html" "html"
643 :before-end
'muse-journal-html-munge-buffer
)
645 (muse-derive-style "journal-xhtml" "xhtml"
646 :before-end
'muse-journal-html-munge-buffer
)
648 (muse-derive-style "journal-latex" "latex"
649 :tags
'muse-journal-latex-markup-tags
650 :before-end
'muse-journal-latex-munge-buffer
)
652 (muse-derive-style "journal-pdf" "pdf"
653 :tags
'muse-journal-latex-markup-tags
654 :before-end
'muse-journal-latex-munge-buffer
)
656 (muse-derive-style "journal-book-latex" "book-latex"
658 :tags
'muse-journal-latex-markup-tags
659 :before-end
'muse-journal-latex-munge-buffer
)
661 (muse-derive-style "journal-book-pdf" "book-pdf"
663 :tags
'muse-journal-latex-markup-tags
664 :before-end
'muse-journal-latex-munge-buffer
)
666 (muse-define-style "journal-rdf"
667 :suffix
'muse-journal-rdf-extension
668 :regexps
'muse-journal-rss-markup-regexps
669 :functions
'muse-journal-rss-markup-functions
670 :before
'muse-journal-rss-munge-buffer
671 :header
'muse-journal-rdf-header
672 :footer
'muse-journal-rdf-footer
673 :date-format
'muse-journal-rdf-date-format
674 :entry-template
'muse-journal-rdf-entry-template
675 :base-url
'muse-journal-rdf-base-url
676 :summarize
'muse-journal-rdf-summarize-entries
)
678 (muse-define-style "journal-rss"
679 :suffix
'muse-journal-rss-extension
680 :regexps
'muse-journal-rss-markup-regexps
681 :functions
'muse-journal-rss-markup-functions
682 :before
'muse-journal-rss-munge-buffer
683 :header
'muse-journal-rss-header
684 :footer
'muse-journal-rss-footer
685 :date-format
'muse-journal-rss-date-format
686 :entry-template
'muse-journal-rss-entry-template
687 :base-url
'muse-journal-rss-base-url
688 :summarize
'muse-journal-rss-summarize-entries
))
690 (provide 'muse-journal
)
692 ;;; muse-journal.el ends here