emacs-orgmode
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[O] HTML/images zipped projects


From: Robert Klein
Subject: [O] HTML/images zipped projects
Date: Tue, 07 Jul 2015 20:25:11 +0200 (CEST)

Hello,

I looked further into this and now have a way to create archives of
projects.  I provide two functions for use in projects preparation and
completion functions (for a project of component projects the former
is to be used in the first projects preparation function and the
latter in the last projects completion function. (See below)

For single file export (cf. the ox-htmlzip example I sent earlier) I
have some ideas, but haven't implemented them yet (Vaidheeswaran C's
comment about epub being close to zip hit a nerve, so I'll take a shot
at extending it to an epub exporter..


Best regards
Robert


**  Archiving Projects
When archiving project you face some issues not present when archiving a
single export.

A export project you want to archive often may be a project composed of
two or more subprojects, e.g. one to publish to HTML, one to PDF and one
to copy the PDF files as well as css files and images created outside of
org to the `publishing-directory'.

As all those files end up in the `publishing-directory' the way
presented here happens before the first project in the components list
is published (clean-up, preparation) and after the last project (removal
of old archive, creation of new one).

To get a multi-project project archive, you call
rk/ox-publish--create-archive-prepare from the preparation-function of
the first project in `:components' project and
rk/ox-publish--create-archive-complete from the completion-function of
the last project.

#+begin_src emacs-lisp
  (defun rk/ox-publish--create-archive-prepare (&optional
                                                delete-pubdir
                                                delete-timestamps
                                                project-list)
    "Prepares the creation of an archive of publishing projects.

  To get a archive cleaned up of old files not longer part of the
  project set DELETE-PUBDIR to `t'.

  To be sure everything gets published anew, set DELETE-TIMESTAMPS
  to `t' and provide ad s PROJECT-LIST a list of projects
  publishing the material for the archive."
    (let ((pubdir (plist-get project-plist :publishing-directory)))
      (when (and delete-timestamps project-list)
        (mapc (function (lambda (project)
                          (let ((cache-file
                                 (concat "~/.org-timestamps/"
                                         project ".cache")))
                            (when (file-exists-p cache-file)    
                              (delete-file cache-file)))))
              project-list))
      (when delete-pubdir
        ;; try to only shoot yourself in the foot, not in the head
        (if (not (equal (file-truename "~/") 
                        (file-truename pubdir)))
            (when (file-exists-p pubdir)
              (delete-directory pubdir t))))))

  (defun rk/ox-publish--create-archive-complete (&optional archive
                                                           archiver-program
                                                           archiver-options)
    "Creates archive ARCHIVE from published project(s).

  If ARCHIVE is nil, the ARCHIVE name will be the name of the
  publishing-directory plus `.zip'.  The archive is stored in the
  same directory the publishing directory is in.

  The default archive format is zip.

  A optional ARCHIVER-COMMAND (and ARCHIVER-OPTIONS) has to follow
  the syntax

      ARCHIVER-COMMAND ARCHIVER-OPTIONS archive-file files/dirs

  Examples for some archive formats:

    | format  | ARHCIVER-COMMAND | ARCHIVER-OPTIONS | needs programs |
    |---------+------------------+------------------+----------------+
    | zip     | zip              | -r               | zip            |
    | tar.gz  | tar              | -zcvf            | tar, gzip      |
    | tar.bz2 | tar              | -jcvf            | tar, bzip2     |
    | tar.xz  | tar              | -Jcvf            | tar, xz        |
    | tar.Z   | tar              | -Zcvf            | tar, compress  |
    | 7z      | 7z               | a                | 7z             |"
    (let* ((pubdir  (plist-get project-plist :publishing-directory))
           (zip-program (or archiver-program "zip"))
           (zip-options (if archiver-program archiver-options "-r"))
           (zip-file (or archive
                         (concat pubdir ".zip")))
           (default-directory (file-truename (concat pubdir "/../")))
           (zip-command (concat zip-program " "
                                zip-options " "
                                zip-file " "
                                (file-name-nondirectory pubdir) " ")))
      (when (file-exists-p zip-file)
        (delete-file zip-file))
      (message "Archiving: %s\n" zip-command)
      (shell-command zip-command)))
#+end_src



reply via email to

[Prev in Thread] Current Thread [Next in Thread]