自定义“org-publish-project-alist”

发布于 2024-10-20 11:45:17 字数 857 浏览 3 评论 0原文

我正在尝试使用组织模式发布网页。两个问题:

  1. 有没有办法“同步”base-directory 中的 org-mode 文件和 publishing-directory 中的 html 文件?具体来说,如果我删除了base-directory中的org文件,我可以让org-publish-html也删除html目录中的相应文件吗?
  2. 如果子目录中有页面,如何指定根目录中的单个 .css 文件用于样式表?比如我的目录结构如下:

    public_html/

    • CSS/
      • mystyle.css
    • index.html
    • 子目录/
      • index.html

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:

  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 ~

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

泪冰清 2024-10-27 11:45:17
  1. 没有直接的方法可以做到这一点。 Org-mode 不知道(或关心)它要发布到的位置 - 它只是将内容发送到那里并确保存在正确的目录结构。发布过程中有一个钩子,在文件被推送到其发布位置后会调用该钩子。这是通过在 org-publish-project-alist 中设置 :completion-function 属性来控制的。您可以使用此挂钩编写一个函数,将 base-dir 和子目录中的 *.org 文件与随附的 *.html 进行比较已发布的文件,并删除那些没有附带 *.org 文件的 *.html 文件。

    我怀疑,通过让你的 Lisp completion-function 调用一个删除必要文件的 shell 脚本,可以最轻松地实现这一点。如果您正在使用 :include:exclude:base-extension 属性做一些奇特的事情,您可能需要您的 completion-functionplist 中获取相关信息,然后将它们传递给您的 shell 脚本。 此组织模式页面有一个示例 < code>completion-function 显示如何获取 org-publish-project-alist 的属性值。然后您需要将它们传递给您的 shell 脚本。

  2. 有多种方法可以做到这一点。也许最简单的方法是使用以下行覆盖每个文件中的默认样式表:

    <块引用>

    #+STYLE:

    对于第一级子目录文件,随着您深入目录结构,不断添加 ../

    另一种可能性是为目录树中的每个级别生成通用模板文件。 此组织模式页面提供了很好地说明了如何进行设置。

    最后,另一种选择是使用 org-publish-project-alist:preparation-function 属性来定义一个函数,该函数将自动更改样式文件每个文件。同样,最好的方法可能是让 Lisp 准备函数调用 shell 脚本来解析文件。我可以想象使用 Unix sed 程序来找到一个表示类似 href="@MYLOC@/stylesheet.css" /> 的正则表达式并替换这些内容位于 @ 与目录树中适当级别之间。考虑到其他选项,这似乎有点矫枉过正。

  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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文