The solution to my alternative issue (I used pandoc, more below) may apply to your's as well.
I was looking for a CGI-based approach to render org files in the browser, thus implicitly publishing them on the fly.
This would allow me to work with the org files without having to actively publish them.
In the past, I took a lot of notes using ReStructured Text and later AsciiDoc. I had implemented a solution for each of the formats, but ended up with this handy Perl-based script that would do the conversion on the fly. AsciiDoc, MarkDown and ReStructured Text are covered, but org gave me a headache as I simply could not render the result of org-html-export-as-html
.
When invoking
emacs <source.org> --batch --kill -l ~/.emacs -f org-html-export-to-html
on the terminal, a file source.html
is generated, but when I put the command in my CGI:
emacs <source.org> --batch --kill -l ~/.emacs -f org-html-export-to-html && cat source.html
it did not come up. This wasn't anyway what I wanted, as an HTML file would have been generated.
I did not find a way of making Emacs redirect the result of org-html-export-as-html
to stdout in batch mode. All in all, the whole thing seemed too complicated, until I looked for an alternative way of converting org to html: https://pandoc.org/.
Now I have a single sgml.pl that will convert all these formats on the fly to HTML and thus can be used as a CGI for viewing them on the browser.
This is circumventing Emacs and should therefore perhaps not belong to this forum. I apologise.
Let me know if you're interested in the code.
Best,
Denis
Ok, since I have been asked (I hope this helps):
The below CGI works for both Apache2 and Nginx.
Just to recap,
In Apache2, a handler is defined:
<IfModule mod_actions.c>`
Action convert-sgml /cgi/sgml.pl`
AddHandler convert-sgml .adoc .md .org .rst .txt`
...
</IfModule>
In Nginx:
location ~ \.(adoc|md|org|rst|txt)$ {`
fastcgi_param PATH_TRANSLATED $document_root$document_uri;`
rewrite ^(.+\.)(adoc|md|org|rst|txt)$ /cgi-bin/sgml.pl?$document_root$document_uri last;`
...
}
The actual CGI code (pandoc does not convert into AsciiDoc, hence using asciidoctor):
#! /usr/bin/perl
# Obtain the server software from the signature (Apache/nginx),
# in order to determine which environment variable will have
# the name of the file to be converted.
$ENV{'SERVER_SOFTWARE'}=~/^([A-Za-z]+)/;
my $serverName=$&;
my %httpd=(
'Apache','PATH_TRANSLATED'
,'nginx','QUERY_STRING'
);
my $input=$ENV{$httpd{$serverName}};
my $ext=$input;
# Determine the file type (asciidoc/markdown/org/restructured text)
# and choose the corresponding converter
my %sgml=(
'asciidoc','\.(adoc|txt)'
,'markdown','\.md'
,'org','\.org'
,'rst','\.rst'
);
my %processor=(
'asciidoc',"/opt/local/bin/asciidoctor -a last-update-label! -o - '%s'"
,'markdown',"/usr/local/bin/pandoc '%s'"
,'org',"/usr/local/bin/pandoc '%s'"
,'rst',"/usr/local/bin/pandoc '%s'"
);
my $cmd;
foreach my $key (keys %sgml) {
if ($input =~ /$sgml{$key}/) {
$cmd=sprintf("$processor{$key}",$input);
last;
}
}
use CGI ':all';
use utf8;
use open ':encoding(utf8)';
binmode(STDOUT, ":utf8");
print header;
#print "<pre>\ninput=".$input."\noutput=".$output."\next=".$ext."\ncmd=".$cmd."\n</pre>\n";
system("$cmd");
M-x eww-browse-with-external-browser
(key binding&
) when needed.