org publish section-numbers 的优先级问题

我最近刚开始尝试使用 org publish,今天发现如下问题。

配置上:org-publish-project-alist 依次包括 A B C 三个项目,A 的 components 包含 B 和 C,B 中没有设置 section-numbers (默认值为 t)为 nil,C 中设置为 nil。[1]

具体情况:

  1. 如果 publish 项目 A,则会生成 section number,无论 components 中的顺序,也无论 org-publish-project-alist 中 B C 的顺序;
  2. 如果 publish 项目 C,则不会生成 section number;
  3. 如果在项目 B 中也加入 sectioin-numbers: nil,则不会生成 section number。

因为情况 1 的存在,所以我猜测是不是需要各个 components 中的 section-numbers 都设置成 nil 才可以(各个项目之间取逻辑或).

[1] 实际项目中 B 是 index,C 是 posts,我没能成功把 / 目录下的 index.org/posts 目录下的 post.org 放在同一个 project 里,如果可以,也望各位大佬指教。

可以贴一下 org publish 的配置以及描述一下目录结构?

component 执行是有顺序的

例如 (A B C) 就会顺序执行 ABC,每一个步骤里都指定了处理什么文件,怎么处理,输出什么文件。

也许你某一步处理了某些文件,默认有 section number,然后另一个步骤又处理了一次这些文件,但是移除了?

看上去没什么 private info 我就直接贴过来了,不太会 elisp 其实,算是到处抄自己瞎改,可能很丑,如果愿意,直接指出来就好,我也好学习。

(setq org-publish-project-alist
      `(("org-website"
	 :components ("org-website-index" "org-website-posts" "org-website-res"))
	("org-website-index"
	 :base-directory ,mt/org-website-dir
	 :base-extension "org"
	 :publishing-directory ,mt/org-website-publish-dir
      	 :publishing-function org-html-publish-to-html
	 :recursive t
	 :htmlized-source t ;; this enables htmlize, which means that I can use css for code!
	 :index-filename "index.org"
	 
	 :with-author t
	 :with-creator nil
	 :with-date t
	 :with-toc nil
	 :with-tags nil

	 :section-numbers nil
	 
	 :html-doctype "html5"
	 :html-link-home "/" ;;
	 :html-head nil ;; cleans up anything that would have been in there.
	 :html-head-extra ,mt/extra-head
	 :html-preamble mt/header
	 :html-postamble mt/footer
	 :html-head-include-default-style nil
         :html-head-include-scripts nil
         :html-viewport nil
	 :html-home/up-format "" ;; remove the home/up link
	 )
	("org-website-posts"
	 :base-directory ,(concat mt/org-website-dir "posts")
	 :base-extension "org"
	 :publishing-directory ,(concat mt/org-website-publish-dir "posts")
      	 :publishing-function org-html-publish-to-html
	 :recursive t
	 :htmlized-source t ;; this enables htmlize, which means that I can use css for code!
	 
	 :with-author t
	 :with-creator nil
	 :with-date t
	 :with-tags nil

	 :section-numbers nil
	 :with-toc nil

	 :html-doctype "html5"
	 :html-link-home "/" ;;
	 :html-head nil ;; cleans up anything that would have been in there.
	 :html-head-extra ,mt/extra-head
	 :html-preamble mt/header
	 :html-postamble mt/footer
	 :html-head-include-default-style nil
         :html-head-include-scripts nil
         :html-viewport nil
	 :html-home/up-format "" ;; remove the home/up link
	 
	 ;; ;; sitemap
	 ;; :auto-sitemap t
	 ;; :sitemap-filename "index.org"
	 ;; :sitemap-title "MirageTurtle's Tree House"
	 ;; :sitemap-sort-files anti-chronologically
	 ;; :sitemap-file-entry-format "%d %t"
	 ;; :sitemap-date-format "%Y-%m-%d"
	 ;; :sitemap-style list
	 )
	;;; static files
	("org-website-res"
         :base-directory ,mt/org-website-static-dir
         :base-extension ".*"
         :publishing-directory ,(concat mt/org-website-publish-dir "/res")
         :publishing-function org-publish-attachment)))

执行这个 project 的话 : ("org-website" :components ("org-website-index" "org-website-posts" "org-website-res")) ,会先执行 org-website-index,再执行 org-website-posts 最后是 org-website-res。

("org-website-index"
	 :base-directory ,mt/org-website-dir
	 :base-extension "org"
	 :publishing-directory ,mt/org-website-publish-dir
      	 :publishing-function org-html-publish-to-html
	 :recursive t
	 :htmlized-source t ;; this enables htmlize, which means that I can use css for code!
	 :index-filename "index.org"
....
	 :section-numbers nil

org-website-index 中, base-directory 是你的整个 website 目录,recursive 是 t,处理的是 org 文件,所以会对 base-directory 下所有的 org 文件都做一次处理,都不生成 section-numbers。

("org-website-posts"
	 :base-directory ,(concat mt/org-website-dir "posts")
	 :base-extension "org"
	 :publishing-directory ,(concat mt/org-website-publish-dir "posts")
      	 :publishing-function org-html-publish-to-html
	 :recursive t
	 :htmlized-source t ;; this enables htmlize, which means that I can use css for code!
	 
	 :with-author t
	 :with-creator nil
	 :with-date t
	 :with-tags nil

	 :section-numbers nil

org-website-posts 中 ,(concat mt/org-website-dir “posts”) 下的所有 post 文件,也是不生成 section-numbers。

不太清楚你的需求是什么,是希望 posts 下的生成 section-numebrs,index 下的 org 文件不生成吗?

如果是希望 index 中不生成,或许可以设置 org-website-index 的 recursive 为 nil,只处理 mt/org-website-dir 一级目录下的文件?

感谢回复!

我期望的其实是都不生成,所以现在设置的都不生成,把 index 和 posts 分开是因为之前设置 recursive t 不知道为啥好像不工作(现在看来可能是当时测试的有些问题)。所以我打算看一下 recursive 的问题,没有问题的话两个合到一起就可以了。

1 个赞