Código em Emacs Lisp para manutenção destas páginas

Seguem algumas funções para a manutenção destas páginas, são a base para um package de blog para o Emacs Muse.

(defun muse-pretty-index-as-string (&optional as-list exclude-private exclude-current)
  "Generate an index of all Muse pages.
If AS-LIST is non-nil, insert a dash and spaces before each item.
If EXCLUDE-PRIVATE is non-nil, exclude files that have private
permissions.
If EXCLUDE-CURRENT is non-nil, exclude the current file from the
output."
  (let ((files (sort (copy-alist (muse-project-file-alist))
                     (function
                      (lambda (l r)
                        (string-lessp (car l) (car r)))))))
    (when (and exclude-current (muse-page-name))
      (setq files (delete (assoc (muse-page-name) files) files)))
    (with-current-buffer (get-buffer-create "*Muse index page*")
      (run-hooks 'muse-project-file-alist-hook)
                      (erase-buffer)
                      (while files
                        (unless (and exclude-private
                     (muse-project-private-p (cdar files)))
          (insert (if as-list " - " "") "[[" (caar files)"]["
                  (muse-extract-file-directive (cdar files) "title") "]]\n"))
        (setq files (cdr files)))
      (buffer-string))))


(defun muse-index-sort-by-date ()
  "Display an index of all known Muse pages."
  (interactive)
  (message "Generating Muse index by date...")
  (let ((project (muse-project)))
    (with-current-buffer (muse-generate-index-sort-by-date)
      (goto-char (point-min))
      (muse-mode)
      (setq muse-current-project project)
      (pop-to-buffer (current-buffer))))
  (message "Generating Muse index by date...done"))


(defun muse-generate-index-sort-by-date (&optional as-list exclude-private)
  "Generate an index of all Muse pages."
  (let ((index (muse-index-as-string-sort-by-date as-list exclude-private)))
    (with-current-buffer (get-buffer-create "*Muse Index sort by date*")
      (erase-buffer)
      (insert index)
      (current-buffer))))

(defun muse-index-as-string-sort-by-date (&optional as-list exclude-private exclude-current)
  "Generate an index of all Muse pages.
If AS-LIST is non-nil, insert a dash and spaces before each item.
If EXCLUDE-PRIVATE is non-nil, exclude files that have private permissions.
If EXCLUDE-CURRENT is non-nil, exclude the current file from the output."
  (let ((files (sort (mapcar
                      (lambda (pair)
                        (list
                         (car pair)
                         (cdr pair)
                         (nth 5 (file-attributes (cdr pair)))))
                      (muse-project-file-alist))
                     (function
                     (lambda (l r)
                       (not (muse-time-less-p
                             (nth 2 l)(nth 2 r))))))))
    (when (and exclude-current (muse-page-name))
      (setq files (delete (assoc (muse-page-name) files) files)))
    (with-temp-buffer
      (while files
        (unless (and exclude-private
                     (muse-project-private-p (cdar files)))
          (insert (if as-list as-list "") "[[" (caar files) "]"
                  "["(muse-extract-file-directive (caar files) "title")"]]\n"))
        (setq files (cdr files)))
      (buffer-string))))

(defun muse-extract-file-directive (file directive)
  "Extracts DIRECTIVE content from the source of Muse FILE."
  (with-temp-buffer
    (muse-insert-file-contents file)
    (muse-mode)
    (goto-char (point-min))
    (setq pos (search-forward (concat "#" directive) nil t))
    (if pos
        (let ((beg (+ 1 pos))
              (end (muse-line-end-position)))
          (buffer-substring-no-properties beg  end)) " ")
    ))

(defun muse-index-as-string-sort-by-date-desc (&optional as-list exclude-private exclude-current)
    (let ((files (sort (mapcar (lambda (pair)
                              (list
                               (car pair)
                               (cdr pair)
                               (nth 5 (file-attributes (cdr pair)))))
                            (muse-project-file-alist))
                    (function
                     (lambda (l r)
                       (not (muse-time-less-p
                             (nth 2 l)(nth 2 r))))))))
    (when (and exclude-current (muse-page-name))
      (setq files (delete (assoc (muse-page-name) files) files)))
    (with-temp-buffer
      (while files
        (unless (and exclude-private
                     (muse-project-private-p (cdar files)))
          (insert (if as-list " - " "") "[[" (caar files) "]"
                  "["(muse-extract-file-directive (caar files) "title")"]]: "
                  (muse-extract-file-directive (caar files) "desc")"\n"))
        (setq files (cdr files)))
      (buffer-string))))

(defun muse-index-as-string-sort-by-date-xml (&optional exclude-private exclude-current)
  (let ((files (sort (mapcar (lambda (pair)
                              (list
                               (car pair)
                               (cdr pair)
                               (nth 5 (file-attributes (cdr pair)))))
                            (muse-project-file-alist))
                    (function
                     (lambda (l r)
                       (not (muse-time-less-p
                             (nth 2 l)(nth 2 r))))))))
    (when (and exclude-current (muse-page-name))
      (setq files (delete (assoc (muse-page-name) files) files)))
    (with-temp-buffer
      (insert "<rss version='2.0'>\n")
      (insert "<channel>\n")
      (insert "<lastBuildDate>"(format-time-string "%a, %d %b %Y %T" (nth 5 (file-attributes "index"))) " GMT</lastBuildDate>\n")
      (insert "<title>" (muse-extract-file-directive "index" "title")"</title>\n")
      (insert "<description>" (muse-extract-file-directive "index" "desc")"</description>\n")
      (insert "<link>http://www.diale.org</link>\n")
      (insert "<managingEditor>"(muse-extract-file-directive "index" "author")"</managingEditor>\n")
      (insert "<generator>muse.el</generator>\n")
      (while files
        (unless (and exclude-private
                     (muse-project-private-p (cdar files)))
          (insert "<item>\n")
          (insert "<guid>"(concat "http://www.diale.org/" (caar files) ".html") "</guid>\n")
          (insert "<link>"(concat "http://www.diale.org/" (caar files) ".html") "</link>\n")
          (insert "<pubDate>"(format-time-string "%a, %d %b %Y %T" (nth 5 (file-attributes (caar files))))" GMT</pubDate>\n")
          (insert "<title>"(muse-extract-file-directive (caar files) "title"))
          (insert "</title>\n")
          (insert "<description>"(muse-extract-file-directive (caar files) "desc")"</description>\n")
          (insert "</item>\n"))
        (setq files (cdr files)))
      (insert "</channel>\n</rss>")
      (buffer-string))))


(defun muse-by-date-xml ()
  "Display RSS for all known Muse pages."
  (interactive)
  (message "Generating RSS...")
  (with-temp-buffer
    (goto-char (point-min))
    (insert (muse-index-as-string-sort-by-date-xml "index"))
    (let ((backup-inhibited t))
      (write-file
       (concat "~/public_html/" muse-by-date-rss-filename)))
    (message "Generating Wiki RSS...done")))

(defun muse-extract-1st-paragraph (file)
  (with-temp-buffer
    (muse-insert-file-contents file)
    (goto-char (point-min))
    (forward-paragraph)
    (setq beg (point))
    (forward-paragraph)
    (setq end (point))
    (buffer-substring-no-properties beg end)))

(defun muse-extract-all (file)
  (with-temp-buffer
    (muse-insert-file-contents file)
    (goto-char (point-min))
    (forward-paragraph)
    (let ((beg (point))
          (end (point-max)))
      (buffer-substring-no-properties beg  end))))

(defun muse-index-as-string-sort-by-date-all (&optional as-list exclude-private exclude-current)
    (let ((files (sort (mapcar (lambda (pair)
                              (list
                               (car pair)
                               (cdr pair)
                               (nth 5 (file-attributes (cdr pair)))))
                            (muse-project-file-alist))
                    (function
                     (lambda (l r)
                       (not (muse-time-less-p
                             (nth 2 l)(nth 2 r))))))))
    (when (and exclude-current (muse-page-name))
      (setq files (delete (assoc (muse-page-name) files) files)))
    (with-temp-buffer
      (while files
        (unless (and exclude-private
                     (muse-project-private-p (cdar files)))
          (insert "<literal><h2><a href='./"(concat (caar files) ".html")
                  "' title='Link permanente para esta entrada'>"
                  "<img src='dailyLinkIcon.png' border='0'></a> "
                  (muse-extract-file-directive (caar files) "title")"</h2></literal>\n"
                  "<literal><div class='lastmod'><p
    align='right'>"(format-time-string "%Y/%m/%d-%T"
(nth 5 (file-attributes (caar files))))"</p></div></literal>\n"
                  (muse-extract-all (caar files))"\n" "----" "\n"))
        (setq files (cdr files)))
      (buffer-string))))


(defcustom muse-online-target
  "http://www.diale.org/"
  "Base URL where the files are published."
  :type 'string
  :group 'muse-date)

(defcustom muse-by-date-rss-filename
  "diale.xml"
  "Name for the RSS file."
  :type 'string
  :group 'muse-date)



(defun my-muse-publish ()
  "Publishes pages and RSS."
  (interactive)
  (muse-publish-file "index" "site-html" "~/public_html/" t)
  (muse-project-publish "website")
  (muse-by-date-xml)
  (muse-sitemap))



(defun muse-sitemap (&optional exclude-private exclude-current)
  "Generates Muse sitemap file."
  (let ((files (muse-project-file-alist)))
    (when (and exclude-current (muse-page-name))
      (setq files (delete (assoc (muse-page-name) files) files)))
    (with-temp-buffer
      (insert "<?xml version='1.0' encoding='UTF-8'?>\n")
      (insert "<urlset xmlns='http://www.sitemaps.org/schemas/sitemap/0.9'>\n")
      (while files
        (unless (and exclude-private
                     (muse-project-private-p (cdar files)))
          (insert "<url>\n<loc>"(concat "http://www.diale.org/" (caar files) ".html") "</loc>\n")
          (insert "<lastmod>"(format-time-string "%a, %d %b %Y %T" (nth 5 (file-attributes (caar files))))" GMT</lastmod>\n")
          (insert "</url>\n"))
        (setq files (cdr files)))
      (insert "\n</urlset>")
      (buffer-string))))

(setq muse-sitemap-filename "diale.sitemap.xml")

(defun muse-sitemap ()
    (interactive)
  (message "Generating sitemap...")
  (with-temp-buffer
    (goto-char (point-min))
    (insert (muse-sitemap))
    (let ((backup-inhibited t))
      (write-file
       (concat "~/public_html/" muse-sitemap-filename)))
    (message "Generating sitemap...done")))

Created: NaN

Last updated: 16-02-2026 [16:02]


For attribution, please cite this page as:

Charters, T., "Emacs Muse": https://nexp.pt/muse-functions.html (16-02-2026 [16:02])


(cc-by-sa) Tiago Charters - tiagocharters@nexp.pt