remote-publish (from ~/emacs/etc/common/common.el)

;;; Remote publishing
(defun remote-publish (orig dest)
  "Use rsync to transfer published files to a remote destination."

  (start-process
   "emacs-wiki-srync" "*emacs-wiki-rsync*" "rsync" "--archive" "--delete"
   "--rsh=ssh"
   (file-name-as-directory
    (expand-file-name orig))

   dest))

~/emacs/etc/common/emacswiki.el

;;;; emacs-wiki configuration for jemarch

(require 'emacs-wiki)
(require 'emacs-wiki-project)
(require 'emacs-wiki-menu)
(require 'table)
(require 'update-remote)

;;; General lisp snippets

(defun jem-insert-file (filename)
  "Insert the contents of a file on publishing."
  (if (and emacs-wiki-publishing-p
           (file-readable-p filename))
      (ignore (insert-file-contents filename))
    (concat "ERROR! '" filename "' not found!")))

(defun jem-ew-publish-wiki-source (pagetitle)
  "Publishes the wiki source of a page, called from the header"
  (when pagetitle
    (copy-file (concat "~/web/homepage/" pagetitle)
               (concat emacs-wiki-publishing-directory "/src/" pagetitle ".txt")
               t)))


;;; Tags for syntax-highlighting with emacs-wiki

;; Example-usage:
;; .emacs:
;;   ;; add my custom tags
;;   (jem-syntax-highlight-tag "cppexample" c++-mode)
;;   (jem-syntax-highlight-tag "htmlexample" html-mode)
;;   (jem-syntax-highlight-tag "example" lisp-mode)
;;   (jem-syntax-highlight-tag "cexample" c-mode)

;; In a wiki-page
;;  <cppexample>
;;    code--here
;;  </cppexample>

(require 'htmlize)

(defun jem-ew-fontified-example-tag (beg end highlight-p mode)
  (if highlight-p
      (progn
        (emacs-wiki-multiline-maybe beg end)
        (goto-char end))
    (let ((content (buffer-substring beg end))
          (replacement ""))
      ;; we've saved the content - now delete it.
      (delete-region beg end)
      (save-excursion
        (with-temp-buffer
          (insert content)
          ;; strip beginning newlines!
          (goto-char (point-min))
          (while (looking-at "^$")
            (forward-line))
          (delete-region (point-min) (point))
          ;; set mode
          (funcall mode)
          ;; Turn on font-locking, otherwise htmlize won't be much good
          (font-lock-fontify-buffer)
          ;; send buffer to htmlize-buffer
          (save-excursion
            (set-buffer (htmlize-buffer))
            ;; pickup and insert
            (goto-char (point-min))
            (search-forward "<pre>\n")
            (let ((beginreg (point)))
              (search-forward "</pre>")
              (backward-char 6)
              (setq replacement (buffer-substring beginreg (point)))
              (kill-buffer (current-buffer))))))
      (let ((current-begin (point)))
        (insert "<pre class=\"sourcecode\">\n")
        (insert replacement)
        (insert "</pre>\n")
        (add-text-properties current-begin (point) '(rear-nonsticky (read-only)
                                                                    read-only t))))))

(defun jem-ew-syntax-highlight-tag (tagname mode)
  (let ((symbolname (concat "jem-ew-autogenerated-highlight-tag-" (symbol-name mode))))
    ;; Create the function for this exact symbol
    (fset (intern symbolname)
          `(lambda (beg end highlight-p)
             (jem-ew-fontified-example-tag beg end highlight-p (quote ,mode))))
    ;; Associate it with it's tag
    (add-to-list 'emacs-wiki-markup-tags
                 `(,tagname t nil t ,(intern symbolname)) t)))


;;; Boxes on HTML

(defvar jem-ew-queued-boxes nil
  "A list of boxes to create.")

(defun jem-ew-markup (string)
  "Markup string using EmacsWiki markup, and return the results."
  (let ((project emacs-wiki-current-project))
    ;; make sure the markup is done in the right project, despite being in a temp buffer
    (with-temp-buffer
      (let* ((emacs-wiki-current-project project)
             (emacs-wiki-publishing-header "<--!STARTHERE!-->")
             (emacs-wiki-publishing-footer "<--!ENDHERE!-->"))
        (insert string)
        (goto-char (point-min))
        (emacs-wiki-replace-markup "BOX!")
        ;; find the locations
        (let ((beg (point-min))
              (end (point-max)))
          (goto-char beg)
          (search-forward emacs-wiki-publishing-header)
          ;; emacs-wiki.el will *most* likely have inserted <p> here now.
          (setq beg (point))
          (search-forward emacs-wiki-publishing-footer)
          ;; and right before this, will be a </p>
          (setq end (- (point) (length emacs-wiki-publishing-footer)))
          ;; return the results -- but we really should handle those
          ;; <p>'s somehow.. remove them! as well as newlines!
          (replace-regexp-in-string "%23" "#"
                                    (replace-regexp-in-string "\\(</?p>\\|\n\\)" ""
                                                              (buffer-substring beg end))))))))

(defun jem-ew-create-box (beg end &optional highlightp)
  "Create a box."
  ;; Add the region to the list of stuff.
  (unless highlightp
    (add-to-list 'jem-ew-queued-boxes (buffer-substring beg end) t)
    (delete-region beg end)))

(defun jem-ew-make-boxes ()
  "Insert DIV-tags for all boxes on the page."
  (let ((result "")
        (content-div-start "<div class=\"menucontent\">\n")
        ;; a few newlines ensures we get a clean & closed list
        (content-div-end "\n\n</div>\n"))
    (while jem-ew-queued-boxes
      (let ((items (split-string (car jem-ew-queued-boxes) "\n")))
        (let ((contents "")
              (content-div-inserted nil))
          (while items
            (let ((item (erc-trim-string (car items))))
              (when (not (string= item ""))
                (save-match-data
                  (cond
                   ((string-match "^{{\\(.*\\)}}$" item)
                    ;; subheader
                    (setq contents (concat contents
                                           ;; make sure to include \n\n
                                           ;; to close <ul>'s
                                           "\n\n<div class=\"menusubheader\">"
                                           (match-string 1 item)
                                           "</div>\n")))
                   ((string-match "^{\\(.*\\)}$" item)
                    ;; big-header -- close any content-tags if there are
                    ;; any.
                    (when content-div-inserted
                      (setq contents (concat contents content-div-end)))
                    (setq contents (concat contents
                                           "<div class=\"menuheader\">"
                                           (match-string 1 item)
                                           "</div>\n"
                                           content-div-start)
                          content-div-inserted t))
                   ((string-match "^\\[[0-9]+\\]" item)
                    ;; footnote! don't try to make this a
                    ;; list-item. append a linebreak however.
                    ;; make sure we have content!
                    (unless content-div-inserted
                      (setq contents (concat contents content-div-start)
                            content-div-inserted t))
                    (setq contents (concat contents item " <br/>\n")))
                   (t
                    ;; default to list-item.
                    ;; again, make sure we have content
                    (unless content-div-inserted
                      (setq contents (concat contents content-div-start)
                            content-div-inserted t))
                    (setq contents (concat contents " - " item "\n")))))))
            (setq items (cdr items)))
          ;; make sure to close up the contents-div
          (when content-div-inserted
            (setq contents (concat contents content-div-end)))
          (setq result (concat result
                               "<div class=\"rightpanel\">"
                               (jem-ew-markup contents) "\n"
                               "</div>\n"))))
      (setq jem-ew-queued-boxes (cdr jem-ew-queued-boxes)))
    result))

(add-to-list 'emacs-wiki-markup-tags
             '("box" t nil nil jem-ew-create-box))

;;; Project configuration

(jem-ew-syntax-highlight-tag "cppexample" 'c++-mode)
(jem-ew-syntax-highlight-tag "htmlexample" 'html-mode)
(jem-ew-syntax-highlight-tag "example" 'lisp-mode)
(jem-ew-syntax-highlight-tag "cexample" 'c-mode)


(setq emacs-wiki-directories '("~/web/homepage")
      emacs-wiki-rsync-destination "es.gnu.org:/home/jemarch/public_html/homepage"
      emacs-wiki-home-page  "WelcomePage"
      emacs-wiki-publishing-directory "~/www/own/homepage"
      emacs-wiki-style-sheet "<link rel=\"stylesheet\" type=\"text/css\" href=\"../styles/wiki_style.css\">"
      emacs-wiki-maintainer "NotFound"
      emacs-wiki-project-server-prefix "http://es.gnu.org/~jemarch/homepage/"
      emacs-wiki-publishing-transforms  '(("WelcomePage" . "index"))
      emacs-wiki-inline-images t
      emacs-wiki-publishing-header "<lisp>(jem-insert-file \"~/web/design/header_homepage.html\")</lisp>"
      emacs-wiki-publishing-footer "<lisp>(jem-insert-file \"~/web/design/footer_homepage.html\")</lisp>")


(setq emacs-wiki-project "homepage")
(setq emacs-wiki-default-project "homepage")


;;; Force publications

(defun jem-emacs-wiki-publish ()
  (interactive)
  "Publish all wikis"
  (emacs-wiki-publish 1)
  (publish-wiki))



;;; Remote publishing code

(defun publish-wiki ()
  "Publish the wiki onto `emacs-wiki-rsync-destination'"
  (interactive)
  (remote-publish emacs-wiki-publishing-directory
                  emacs-wiki-rsync-destination))

;;; Global keys

(global-set-key "\C-c\C-f" 'emacs-wiki-find-file)

;;; Local keys on emacs-wiki-mode
(define-key emacs-wiki-mode-map "\C-c\C-p" 'jem-emacs-wiki-publish)

;;; Accentize hook for publication

(add-hook 'emacs-wiki-after-markup-hook
          (lambda () (iso-iso2sgml (point-min) (point-max))))