自定义“org-publish-project-alist”
我正在尝试使用组织模式发布网页。两个问题:
- 有没有办法“同步”
base-directory
中的 org-mode 文件和publishing-directory
中的 html 文件?具体来说,如果我删除了base-directory
中的org文件,我可以让org-publish-html
也删除html目录中的相应文件吗? 如果子目录中有页面,如何指定根目录中的单个
.css
文件用于样式表?比如我的目录结构如下:public_html/
- CSS/
- mystyle.css
- index.html
- 子目录/
- index.html
- CSS/
在 org-publish-project-alist
中具有以下规范(这只是一个子集) -
:publishing-directory "public_html"
:style "<link rel=\"stylesheet\" href=\"css/mystyle.css\" type=\"text/css\"/>"
mystyle.css
由 使用>public_html/index.html
但不是 public_html/subdir/index.html
。有没有一个简单的补救措施(我希望子目录中的两个/所有文件都使用样式表)?
非常感谢~
I'm trying to publish webpage using org-mode. Two questions:
- Is there a way to "sync" the org-mode files in the
base-directory
and the html files in thepublishing-directory
? Specifically, if I delete an org file in thebase-directory
, can I getorg-publish-html
to delete the corresponding file in the html directory also? 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
- 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 ~
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
没有直接的方法可以做到这一点。 Org-mode 不知道(或关心)它要发布到的位置 - 它只是将内容发送到那里并确保存在正确的目录结构。发布过程中有一个钩子,在文件被推送到其发布位置后会调用该钩子。这是通过在
org-publish-project-alist
中设置:completion-function
属性来控制的。您可以使用此挂钩编写一个函数,将base-dir
和子目录中的 *.org 文件与随附的 *.html 进行比较已发布的文件,并删除那些没有附带 *.org 文件的 *.html 文件。我怀疑,通过让你的 Lisp
completion-function
调用一个删除必要文件的 shell 脚本,可以最轻松地实现这一点。如果您正在使用:include
、:exclude
或:base-extension
属性做一些奇特的事情,您可能需要您的completion-function
从plist
中获取相关信息,然后将它们传递给您的 shell 脚本。 此组织模式页面有一个示例 < code>completion-function 显示如何获取org-publish-project-alist
的属性值。然后您需要将它们传递给您的 shell 脚本。有多种方法可以做到这一点。也许最简单的方法是使用以下行覆盖每个文件中的默认样式表:
<块引用>
#+STYLE:
对于第一级子目录文件,随着您深入目录结构,不断添加
../
。另一种可能性是为目录树中的每个级别生成通用模板文件。 此组织模式页面提供了很好地说明了如何进行设置。
最后,另一种选择是使用
org-publish-project-alist
的:preparation-function
属性来定义一个函数,该函数将自动更改样式文件每个文件。同样,最好的方法可能是让 Lisp 准备函数调用 shell 脚本来解析文件。我可以想象使用 Unixsed
程序来找到一个表示类似href="@MYLOC@/stylesheet.css" />
的正则表达式并替换这些内容位于@
与目录树中适当级别之间。考虑到其他选项,这似乎有点矫枉过正。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 yourorg-publish-project-alist
. You could use this hook to write a function that compares the *.org files in yourbase-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 yourcompletion-function
to grab the pertinent information from theplist
and then pass them to your shell script. This org-mode page has an examplecompletion-function
that 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-function
property oforg-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 Lisppreparation-function
call a shell script to parse the files. I could imagine doing this with the Unixsed
program 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.