I’m trying to publish webpage using org-mode. Two questions:
- Is there a way to “sync” the org-mode files in the
base-directoryand the html files in thepublishing-directory? Specifically, if I delete an org file in thebase-directory, can I getorg-publish-htmlto delete the corresponding file in the html directory also? -
If I have pages within subdirectories, how can I specify a single
.cssfile 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
- css/
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 ~
There is no straightforward way of doing this.
Org-modedoesn’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-functionproperty in yourorg-publish-project-alist. You could use this hook to write a function that compares the *.org files in yourbase-dirand 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-functioncall a shell script that removes the necessary files. If you are doing something fancy with the:include,:exclude, or:base-extensionproperties, you’ll likely want yourcompletion-functionto grab the pertinent information from theplistand then pass them to your shell script. This org-mode page has an examplecompletion-functionthat shows how to get property values for theorg-publish-project-alist. You would then need to pass them to your shell script.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:
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-functionproperty oforg-publish-project-alistto define a function that will automatically change the style file for each file. Again, this is probably best done by having the Lisppreparation-functioncall a shell script to parse the files. I could imagine doing this with the Unixsedprogram to find a regular expression denoted something likehref="@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.