From mboxrd@z Thu Jan 1 00:00:00 1970 From: John Kitchin Subject: Re: HTML/images zipped? Date: Fri, 26 Jun 2015 19:34:02 -0400 Message-ID: References: <6sw6c7bng2haym.fsf@pfdstudio.com> <871tgy1ugo.fsf@gmx.us> <87si9e6suh.fsf@alphaville.usersys.redhat.com> Mime-Version: 1.0 Content-Type: text/plain Content-Transfer-Encoding: quoted-printable Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:59736) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Z8d8M-00049K-DM for emacs-orgmode@gnu.org; Fri, 26 Jun 2015 19:34:11 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Z8d8J-00047E-7g for emacs-orgmode@gnu.org; Fri, 26 Jun 2015 19:34:10 -0400 Received: from mail-qg0-x22a.google.com ([2607:f8b0:400d:c04::22a]:35889) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Z8d8J-000478-1v for emacs-orgmode@gnu.org; Fri, 26 Jun 2015 19:34:07 -0400 Received: by qgal13 with SMTP id l13so40342577qga.3 for ; Fri, 26 Jun 2015 16:34:06 -0700 (PDT) In-reply-to: <87si9e6suh.fsf@alphaville.usersys.redhat.com> List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Sender: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org To: Nick Dokos Cc: emacs-orgmode@gnu.org hm... maybe it has been a while since I ran that ;) I pushed some changes that seem to have it working on a small test file. This code is somewhat on the border of a filter/custom export. There are probably links that will now work with it, I have not tested it super thoroughly. Notably, it does not preserve relative paths, but rather renames files and images and replaces the links in the org-file with the new names. It was too hard to figure out how to preserve the paths when I wrote this originally. Nick Dokos writes: > John Kitchin writes: > >> I did something like this for org-files: >> https://github.com/jkitchin/jmax/blob/master/ox-archive.el >> > > I tried this on some arbitrary org file (not containing any references) a= nd I got an error: > > Debugger entered--Lisp error: (wrong-type-argument stringp nil) > file-name-directory(nil) > (let* ((temporary-file-directory (file-name-directory (buffer-file-name= ))) (tempname (make-temp-file "extract-bib")) (contents (buffer-string)) (c= b (current-buffer)) basename texfile bibfile results) (find-file tempname) = (insert contents) (setq basename (file-name-sans-extension (file-name-nondi= rectory buffer-file-name)) texfile (concat tempname ".tex") bibfile (concat= tempname ".bib")) (save-excursion (goto-char (point-min)) (if (re-search-f= orward "^bibliography:" (point-max) (quote end)) nil (insert (format "\nbib= liography:%s" (mapconcat (quote identity) reftex-default-bibliography ","))= ))) (save-buffer) (org-latex-export-to-latex) (find-file texfile) (reftex-p= arse-all) (reftex-create-bibtex-file bibfile) (save-buffer) (setq results (= buffer-string)) (kill-buffer (concat basename ".bib")) (kill-buffer (concat= basename ".tex")) (kill-buffer basename) (delete-file bibfile) (delete-fil= e texfile) (delete-file tempname) (switch-to-buffer cb) (if (not (string=3D= "" results)) (progn (save-excursion (goto-char (point-max)) (insert "\n\n"= ) (org-insert-heading) (insert (format " Bibtex entries\n\n#+BEGIN_SRC text= :tangle %s\n%s\n#+END_SRC" (concat (file-name-sans-extension ...) ".bib") = results)))))) > org-ref-extract-bibtex-entries() > (let* ((org-file (buffer-name)) (org-file-abs-path (buffer-file-name)) = (base-name (file-name-sans-extension org-file)) (org-archive (if (string=3D= zip-base-name "") (concat base-name "-" (format-time-string "%Y-%m-%d" (cu= rrent-time))) zip-base-name)) (org-archive-zip (concat org-archive ".zip"))= link-list) (if (file-exists-p org-archive-zip) (progn (delete-file org-arc= hive-zip))) (if (file-exists-p org-archive) (progn (delete-directory org-ar= chive t))) (make-directory org-archive t) (setq link-list (let ((parsetree = (org-element-parse-buffer)) (counter 0)) (org-element-map parsetree (quote = link) (function (lambda (link) (let* (... ... ... ... ... ... ... ...) (mes= sage ...) (cond ... ... ...))))))) (message (format "\n\nlink-list: %s\n\n"= link-list)) (let ((counter 0)) (defalias (quote ox-mrkup-filter-link) (fun= ction (lambda (text back-end info) (message "handing link %s: %s\n" counter= text) (let ((link ...)) (message " %s replacement is %s\n" counter link) = (if (not ...) (progn ... ...) (setq output ...)) (setq counter (+ counter 1= )) output)))) (let ((org-export-filter-link-functions (quote (ox-mrkup-filt= er-link)))) (org-org-export-as-org))) (switch-to-buffer "*Org ORG Export*")= (insert (format "# archived from %s on %s\n" org-file-abs-path (format-tim= e-string "%Y-%m-%d" (current-time)))) (org-ref-extract-bibtex-entries) (wri= te-file (expand-file-name org-file org-archive)) (shell-command (concat "zi= p -v -r " org-archive-zip " *")) (rename-file org-archive-zip (concat "../"= org-archive ".zip")) (switch-to-buffer org-file) (delete-directory org-arc= hive t) org-archive-zip) > ox-archive-create-zip("foo") > ... > > I think there is a bug in ox-archive-create-zip: > > --8<---------------cut here---------------start------------->8--- > ... > (switch-to-buffer "*Org ORG Export*") > (insert (format "# archived from %s on %s\n" > org-file-abs-path > (format-time-string "%Y-%m-%d" (current-time)))) > > ;; add bibliography references if they exist. > (org-ref-extract-bibtex-entries) > ... > --8<---------------cut here---------------end--------------->8--- > > because the first thing that org-ref-extract-bibtex-entries does is > > --8<---------------cut here---------------start------------->8--- > (let* ((temporary-file-directory (file-name-directory (buffer-file-name= ))) > --8<---------------cut here---------------end--------------->8--- > > and (buffer-file-name) returns nil on the *Org ORG Export* buffer. > But since you obviously use this code successfully, I wonder why > you don't hit this. > > Thanks for any help, > Nick -- Professor John Kitchin Doherty Hall A207F Department of Chemical Engineering Carnegie Mellon University Pittsburgh, PA 15213 412-268-7803 @johnkitchin http://kitchingroup.cheme.cmu.edu