如何指定 org-publish 的项目目录

新手求助

我在学习使用 orgmode 生成项目文档,由于分散在多个文件中,所以使用 org-publish 来统一生成文件,并发布到指定目录中。我使用了如下代码:

(setq docs-base (concat (projectile-project-root) "docs/"))
(setq org-publish-project-alist
  '(("org-notes"
      :base-directory ,docs-base
      :base-extension "org"
      :publishing-directory ,(concat docs-base "output")
      :html-head "<link rel=\"stylesheet\" href=\"css/org.css\"/>"
      :html-head-include-default-style nil
      :with-date nil
      :time-stamp-file nil
      :publishing-function org-html-publish-to-html
      )
     ("org-static"
       :base-directory ,(concat (docs-base "assets/"))
       :base-extension "css\\|js\\|png\\|jpg\\|gif\\|pdf\\|mp3\\|ogg\\|swf\\|txt\\|asc"
       :publishing-directory ,(concat docs-base "output/assets")
       :recursive t
       :publishing-function org-publish-attachment
       )
     ("org" :components
       ("org-notes" "org-static"))))
(org-publish-all)

由于要指定项目目录,我使用了 (projectile-project-root) 来指定,然后 concat 上文档所在的相对目录,保存在变量 docs-base 中。写法我是参考的官方文档,官方推荐的博文和网上的资料,分别是

奇怪的是,我的配置是报错: org-publish-get-base-files: Wrong type argument: stringp, (, docs-base) 我仔细比较了我和官方文档里的写法,是他的几个参数都是使用了常量string配置的所有路径,我使用常量string配置路径以后( :base-directory ) ,代码可以正常运行,但是换成变量就依旧报错。

然而更奇怪的是我参考的第三偏博文中,使用的也是变量,同样使用 “,” 运算符取出的变量值。我也是 elisp 新手,无法理解其中的问题。故来请教。

debug信息:

Debugger entered--Lisp error: (wrong-type-argument stringp (\, docs-base))
  file-name-as-directory((\, docs-base))
  org-publish-get-base-files(("org-notes" :base-directory (\, docs-base) :base-extension "org" :publishing-directory (\, (concat docs-base "output")) :html-head "<link rel=\"stylesheet\" href=\"css/org.css\"/>" :html-head-include-default-style nil :with-date nil :time-stamp-file nil :publishing-function org-html-publish-to-html))
  org-publish-projects((("org-notes" :base-directory (\, docs-base) :base-extension "org" :publishing-directory (\, (concat docs-base "output")) :html-head "<link rel=\"stylesheet\" href=\"css/org.css\"/>" :html-head-include-default-style nil :with-date nil :time-stamp-file nil :publishing-function org-html-publish-to-html) ("org-static" :base-directory (\, (concat (docs-base "assets/"))) :base-extension "css\\|js\\|png\\|jpg\\|gif\\|pdf\\|mp3\\|ogg\\|swf\\|txt\\|asc" :publishing-directory (\, (concat docs-base "output/assets")) :recursive t :publishing-function org-publish-attachment) ("org" :components ("org-notes" "org-static"))))
  org-publish-all()
  eval-buffer()  ; Reading at buffer position 831
  funcall-interactively(eval-buffer)
  call-interactively(eval-buffer nil nil)
  command-execute(eval-buffer)
  • 我的 orgmode 版本:Org mode version 9.2.5 (9.2.5-1-gff6508-elpaplus @ c:/Users/gsj98/.emacs.d/elpa/develop/org-plus-contrib-20190812/)
  • 系统 windows 10 64bit
  • emacs 版本:26.2
  • 使用配置:spacemacs 0.300

感谢各位高手

, 只能在 ` 中使用,你用的是'

(setq org-publish-project-alist
      (backquote (("org-notes"
                   :base-directory ,docs-base
                   :base-extension "org"
                   :publishing-directory ,(concat docs-base "output")
                   :html-head "<link rel=\"stylesheet\" href=\"css/org.css\"/>"
                   :html-head-include-default-style nil
                   :with-date nil
                   :time-stamp-file nil
                   :publishing-function org-html-publish-to-html
                   )
                  ("org-static"
                   :base-directory ,(concat (docs-base "assets/"))
                   :base-extension "css\\|js\\|png\\|jpg\\|gif\\|pdf\\|mp3\\|ogg\\|swf\\|txt\\|asc"
                   :publishing-directory ,(concat docs-base "output/assets")
                   :recursive t
                   :publishing-function org-publish-attachment
                   )
                  ("org" :components
                         ("org-notes" "org-static")))))
2 个赞

可以参考: (defvar org-export-directory (concat ab9986-first-dir “~/blog/”))

(defun org-export-output-file-name–set-directory (orig-fn extension &optional subtreep pub-dir) (setq pub-dir (or pub-dir org-export-directory)) (funcall orig-fn extension subtreep pub-dir)) (advice-add 'org-export-output-file-name :around 'org-export-output-file-name–set-directory)

1 个赞

好使!非常感谢

免费的解决方案点一下

为什么我报另外一种错呢?大神帮我看看
Debugger entered–Lisp error: (void-function projectile-project-root) (projectile-project-root)

projectile-project-root是插件projectile的函数

1 个赞

get了,感谢

大神,请教一下:比如我写了一个index.org,然后写了其他的other.org,然后我在index.org有一处链接到other.org里,等生成了html文件之后,能从index.html能链接到other.html。这里应该怎么写呢

暂时不用解答了,已经自行解决了,不过还是非常感谢