Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

customizing `org-publish-project-alist`

I'm trying to publish webpage using org-mode. Two questions:

  1. Is there a way to "sync" the org-mode files in the base-directory and the html files in the publishing-directory? Specifically, if I delete an org file in the base-directory, can I get org-publish-html to delete the corresponding file in the html directory also?
  2. If I have pages within subdirectories, how can I specify a single .css file in the root directory to be used for the style sheet? For instance, my directory structure is as follows:

    public_html/

    • css/
      • mystyle.css
    • index.html
    • subdir/
      • index.html

With the following specifications in org-publish-project-alist (this is just a subset) --

:publishing-directory "public_html"
:style "<link rel=\"stylesheet\" href=\"css/mystyle.css\" type=\"text/css\"/>"

mystyle.css is used by public_html/index.html but not by public_html/subdir/index.html. Is there a simple remedy to this (I want the style sheet to be used by both/all files in subdirectories)?

Thanks much ~

like image 959
hatmatrix Avatar asked Mar 07 '11 00:03

hatmatrix


1 Answers

  1. There is no straightforward way of doing this. Org-mode doesn't know (or care) about the location to which it is publishing - it just sends things there and makes sure the correct directory structure exists. There is a hook in the publishing process that gets called after the files have been pushed to their published location. This is controlled by setting the :completion-function property in your org-publish-project-alist. You could use this hook to write a function that compares the *.org files in your base-dir and subdirectories to the accompanying *.html published files, and remove those *.html files that don't have an accompanying *.org file.

    I suspect this will be most easily accomplished by making your Lisp completion-function call a shell script that removes the necessary files. If you are doing something fancy with the :include, :exclude, or :base-extension properties, you'll likely want your completion-function to grab the pertinent information from the plist and then pass them to your shell script. This org-mode page has an example completion-function that shows how to get property values for the org-publish-project-alist. You would then need to pass them to your shell script.

  2. There are several ways to do this. Perhaps the simplest is to just override the default style sheet in each file with a line such as:

    #+STYLE: <link rel="stylesheet" type="text/css" href="../stylesheet.css" />

    for your first level of subdirectory files, and keep adding ../ as you get deeper in the directory structure.

    Another possibility is generate generic template files for each level within the directory tree. This org-mode page gives a nice example of how to set this up.

    Lastly, another option is to use the :preparation-function property of org-publish-project-alist to define a function that will automatically change the style file for each file. Again, this is probably best done by having the Lisp preparation-function call a shell script to parse the files. I could imagine doing this with the Unix sed program to find a regular expression denoted something like href="@MYLOC@/stylesheet.css" /> and substitute the stuff between @'s with the appropriate level within the directory tree. This seems like overkill, given the other options.

like image 87
cm2 Avatar answered Sep 19 '22 13:09

cm2