Re: [O] Conditionally formatting org-html-postamble-format

2016-01-27 Thread Kaushal Modi
Thank you guys.

With your help, I came up with this solution and it works great! I tested
it with all 4 combinations (author=nil/non-nil and date=nil/non-nil).

# #+AUTHOR:
#+AUTHOR: Kaushal Modi
# #+DATE:
#+DATE: {{{time(%b %e %Y\, %a)}}}

;; Customize the HTML postamble
(defun modi/org-html-postamble-fn (info)
  "My custom postamble for org to HTML exports.
INFO is the property list of export options."
  (let ((author (car (plist-get info :author)))
(creator (plist-get info :creator))
(date (car (org-export-get-date info)))
(d1 ""))
(concat "Exported using "
d1 "class=\"creator\">" creator d2 ; emacs and org versions
(when author
  (concat " by " author))
(when date
  (concat " on " d1 "class=\"date\">" date d2))
".")))
(setq org-html-postamble #'modi/org-html-postamble-fn) ; default: 'auto


Re: [O] Conditionally formatting org-html-postamble-format

2016-01-27 Thread Kaushal Modi
Hi Robert,

Thanks for the reply.

> how about using a postamble function instead of html-postamble-format

Does it mean that I need to look into modifying the
org-html--build-pre/postamble function?

If so, I will start looking into it but it will take a while as it full of
elisp that I have never used (until today maybe): format-spec, plist-get
and a lot of assoc's and assq's :)

Kaushal


Re: [O] Conditionally formatting org-html-postamble-format

2016-01-27 Thread Robert H. Klein
Hi,

Kaushal Modi  wrote:

> Hi,
> 
> I have the org-html-postamble-format set to the below:
> 
> (setq org-html-postamble-format
>   `(("en"
>  ,(concat "Exported using "
>   ;; "%c" is replaced with
> `org-html-creator-string'
>   ;; Emacs  (Org mode )
>   " class=\"creator\">"  
>   "%c "
>   "by %a. — "
>   " class=\"date\">"  
>   "%d"
> 
> 
> It works great except for the cases where I have set a document
> author to nothing using
> 
> #+AUTHOR:
> 
> What would be the best way to set the postamble so that the "by %a"
> portion does not get printed if the %a value is "".
> 
> Right now, if the author is nil, the postamble gets exported as:
> 
> Exported using
> Emacs  25.0.50.1 (Org
>  mode 8.3.3)
>  by . —
> Jan 26 2016, Tue


how about using a postamble function instead of
html-postamble-format, something like

(let ((author (car (plist-get info :author
  (when (not (equal author ""))
"by " author ". "))
" - "

instead of "by %a. - "

and similar for the rest of the %-thingies.

Note, you'll probably have to inspect the plist, the (car ...) I'm
using in some project for getting the title.

Best regards
Robert



Re: [O] Conditionally formatting org-html-postamble-format

2016-01-27 Thread Nick Dokos
Kaushal Modi  writes:

> Hi Robert,
>
> Thanks for the reply.
>
>> how about using a postamble function instead of html-postamble-format
>
> Does it mean that I need to look into modifying the 
> org-html--build-pre/postamble function?
>

No, Robert is talking about the variable org-html-postamble,
which you can set to a function. No need to muck around with
the internals of org.

C-h v org-html-postamble says

,
| org-html-postamble is a variable defined in ‘ox-html.el’.
| Its value is auto
| 
| Documentation:
| Non-nil means insert a postamble in HTML export.
| 
| When set to ‘auto’, check against the
| ‘org-export-with-author/email/creator/date’ variables to set the
| content of the postamble.  When set to a string, use this string
| as the postamble.  When t, insert a string as defined by the
| formatting string in ‘org-html-postamble-format’.
| 
| When set to a function, apply this function and insert the
| returned string.  The function takes the property list of export
| options as its only argument.
| 
| Setting :html-postamble in publishing projects will take
| precedence over this variable.
`

Try

--8<---cut here---start->8---
(defun foo (info)
  "This is my postamble")

(setq org-html-postamble (function foo))
--8<---cut here---end--->8---

and complicate the function as necessary to produce what you want.
Of course, you can use an anonymous function too:

--8<---cut here---start->8---
(setq org-html-postamble (function (lambda (info)
 "This is my postamble")))
--8<---cut here---end--->8---

--
Nick




Re: [O] Conditionally formatting org-html-postamble-format

2016-01-27 Thread Robert H. Klein
Hi Kaushal,

> Thanks for the reply.
> 
> > how about using a postamble function instead of
> > html-postamble-format  
> 
> Does it mean that I need to look into modifying the
> org-html--build-pre/postamble function?
> 
> If so, I will start looking into it but it will take a while as it
> full of elisp that I have never used (until today maybe):
> format-spec, plist-get and a lot of assoc's and assq's :)

No, I have two functions, one for the preamble, one for the postamble,
both returning a string.  In the project alist I set :html-preamble
and :html-postamble to those functions (beware of typos):


  ;; pre- and postamble for html export
  (defun linux-e-preamble (info)
(with-temp-buffer
  (insert-file-contents "~/linuxdocs/html/preamble.html")
  (let ((title (car (plist-get info :title
(when title
  (if (stringp title)
  (let ((case-fold-search t)) ; case-insensitive
(goto-char (point-min))
(while (search-forward "" nil t)
  (replace-match title))
  (buffer-string)))

  (defun linux-e-postamble (info)
(with-temp-buffer
  (insert-file-contents "~/linuxdocs/html/postamble.html")
  (buffer-string)))

  ;; add linux to org-publish-poject-alist
  (add-to-list 'org-publish-project-alist
   '("linux-e-html"
 :base-directory "~/linuxdocs"
 :base-extension "org"
 :publishing-directory "~/public_html/linuxdocs"
 :publishing-function org-html-publish-to-html
 :html-head "" :html-head-include-default-style nil
 :html-head-include-scripts nil
 :html-preamble linux-e-preamble
 :html-postamble linux-e-postamble
 ))


Best regards
Robert



[O] Conditionally formatting org-html-postamble-format

2016-01-26 Thread Kaushal Modi
Hi,

I have the org-html-postamble-format set to the below:

(setq org-html-postamble-format
  `(("en"
 ,(concat "Exported using "
  ;; "%c" is replaced with
`org-html-creator-string'
  ;; Emacs  (Org mode )
  ""
  "%c "
  "by %a. — "
  ""
  "%d"


It works great except for the cases where I have set a document author to
nothing using

#+AUTHOR:

What would be the best way to set the postamble so that the "by %a" portion
does not get printed if the %a value is "".

Right now, if the author is nil, the postamble gets exported as:

Exported using
Emacs  25.0.50.1 (Org
 mode 8.3.3)
 by . —
Jan 26 2016, Tue