")))
(with-temp-file "~/data/danamlund.dk/org/index.html"
(insert (my-ls-html "~/data/danamlund.dk/org"))))
#+END_SRC
It's not pretty code but it does a simple enough job that it doesn't
need to be.
I first define the function which outputs a string, then I write that
string to a file using the builtin =with-temp-file= function.
** Setting up lftp
/lftp/ is just a simple ftp client I found that can mirror upload
sites. This feature is simple to decrease the time it takes to upload
a change in the website.
/lftp/ itself can be passed, as a parameter, a series of commands to
connect and start mirrroring the website. To execute this automatically
using emacs I use the =shell= and =comint-send-input= commands.
#+BEGIN_SRC elisp
(progn
(shell "lftp")
(insert (concat "lftp -c 'open danamlund.dk@danamlund.dk;"
"mirror -R -e ~/data/danamlund.dk_tmp /'"))
(comint-send-input))
#+END_SRC
This code asks for the password when executed. I could have included
the password as a part of the lftp parameter but then I wouldn't be
able to safely share my index.orgfile.
** Don't upload .svn directories
Ftp is really slow the more files and directories you have. Mirroring
saves some time, the client still need to look through all
directories. To speed up ftp mirroring I decided to remove .svn files.
Unfortunately /lftp/ doesn't seem to have a feature to ignore certain
files, so I fixed this with some shell commands instead. I basically
just copied the entire generated website to a temporary location and
then removed /.svn/ files using /find/ and /xargs/.
#+BEGIN_SRC elisp
(progn
(shell-command "rm -Rf ~/data/danamlund.dk_tmp")
(shell-command "cp -RLf ~/data/danamlund.dk ~/data/danamlund.dk_tmp")
(shell-command "find ~/data/danamlund.dk_tmp -name '.svn' | xargs rm -Rf"))
#+END_SRC
** Putting it all together
As can be seen in index.org I have combined these features into two
operations, one to generate the website and one to upload it. It is
usually a good idea to check the website before uploading it to the
public.
#+BEGIN_SRC elisp
(progn
(require 'org-publish)
(set-background-color "white")
(set-foreground-color "black")
(org-publish-projects
'(
("danamlund.dk-notes"
:base-directory "~/data/danamlund.dk/org"
:base-extension "org"
:publishing-directory "~/data/danamlund.dk"
:recursive t
:publishing-function org-publish-org-to-html
:headline-levels 4
:auto-preamble t
:headline-level 4
:section-numbers nil
:sub-superscript nil
:style ""
:author "Dan Amlund"
:email "danamlund@gmail.com"
)
("danamlund.dk-static"
:base-directory "~/data/danamlund.dk/org"
:base-extension "css\\|js\\|png\\|jpg\\|gif\\|pdf\\|mp3\\|ogg\\|swf\\|deb"
:publishing-directory "~/data/danamlund.dk"
:recursive t
:publishing-function org-publish-attachment
)))
(defun my-ls-html (dir &optional prefix)
"Return a string of html showing recursive directory listings."
(let ((out ""))
(dolist (f (directory-files dir))
(if (not (or (string= f ".") (string= f "..")
(string= "." (substring f 0 1))))
(let ((ff (concat prefix f)))
(if (file-directory-p (concat dir "/" f))
(setq out (format "%s
%s:%s
"
out f (my-ls-html
(concat dir "/" f)
(concat prefix f "/"))))
(setq out (format "%s