emacsorphanage / org-page

[INACTIVE] A static site generator based on Emacs and org mode.
674 stars 99 forks source link

Use function `op/get-template-dir' to get template direcory #122

Closed tumashu closed 9 years ago

tumashu commented 9 years ago

This change let the below code work properly

    (let ((op/theme 'loveorg)
          (op/theme-root-directory "/path/to/source-dir"))
      (op/do-publication t nil nil t))
sillykelvin commented 9 years ago

What is the op/new-post-1 function used for?

tumashu commented 9 years ago

`op/new-post’ is not suit for in elisp, so I add function op/new-post-1 which can used for customize post command.

sillykelvin commented 9 years ago

Could you please give an example? Seems that the op/new-post-1 function is just the second half of the original op/new-post.

tumashu commented 9 years ago

第二个commit主要解决这个问题:

原来代码中,加载org-page的时候 op/theme-root-directory' 和 op/theme' 两个变量决定op/template-directory' 变量的取值,org-page 导出时使用变量 op/template-directory

在不明确设置op/template-directory的时候,下面代码是不能按照预期设定主题为 loveorg的。。。。

   (let ((op/theme 'loveorg)
          (op/theme-root-directory "/path/to/source-dir"))
      (op/do-publication t nil nil t))

我的更改是: 使用函数 op/get-template-dir 来实时计算模板路径。 这样就不存在上述问题了。

tumashu commented 9 years ago

op/do-publication-1' 是一个内部函数,用于用户自定义发布命令。op/do-publication‘ 不适合elisp编程。

tumashu commented 9 years ago

这是我的应用例子:

(require 'org-page)

(defmacro eh-website-with-config (&rest body)
  `(let* ((repo-dir (file-name-directory (locate-library "eh-website")))
          (op/repository-directory repo-dir)
          (op/theme-root-directory
           (file-name-as-directory (concat repo-dir "themes")))
          (op/theme 'worg)
          (op/site-main-title "Tumashu 的个人小站")
          (op/repository-org-branch "source")
          (op/repository-html-branch "master")
          (op/personal-github-link "https://github.com/tumashu/tumashu.github.com")
          (op/site-domain "http://tumashu.github.com/")
          (op/category-ignore-list '("themes" "assets"))
          (op/personal-duoshuo-shortname "tumashu-website"))
     (when op/repository-directory
       ,@body)))

(defun eh-website-publish (&optional test force-all
                                     base-git-commit
                                     auto-commit auto-push)
  (interactive
   (let* ((test (y-or-n-p "Test publish? "))
          (f (y-or-n-p "Publish all org files? "))
          (b (unless f (read-string "Base git commit: " "HEAD~1")))
          (a (when (not test)
               (y-or-n-p "Auto commit to repo? ")))
          (u (when (and a (not test))
               (y-or-n-p "Auto push to remote repo? "))))
     (list test f b a u)))
  (eh-website-with-config
   (if test
       (let* ((localhost "http://localhost/")
              (directory "/var/www/")
              (op/site-domain localhost))
         (op/do-publication-1 force-all
                              base-git-commit directory
                              auto-commit auto-push)
         (browse-url-of-file localhost))
     (op/do-publication-1 force-all base-git-commit t
                          auto-commit auto-push))))

(defun eh-website-new-post (&optional category filename)
  (interactive
   (let* ((c (read-string "Category: " "blog"))
          (f (read-string "filename: " "new-post.org")))
     (list c f)))
  (when (string= category "")
    (setq category "blog"))
  (when (string= filename "")
    (setq filename "new-post.org"))
  (unless (string-suffix-p ".org" filename)
    (setq filename (concat filename ".org")))
  (eh-website-with-config
   (op/new-post-1 category filename)))
sillykelvin commented 9 years ago

在不明确设置op/template-directory的时候,下面代码是不能按照预期设定主题为 loveorg的。。。。

(let ((op/theme 'loveorg)
       (op/theme-root-directory "/path/to/source-dir"))
   (op/do-publication t nil nil t))

In op/do-publication, op/prepare-theme is called, and in op/prepare-theme, op/update-theme is called, and it will set the variable op/template-directory. So I am a little confused that it will not work for you...

tumashu commented 9 years ago

我不知道为什么要使用全局变量 `op/template-directory' 作为一个数据交换的变量, 潜意识里,我感觉这样做有问题,我们完全可以用函数来代替,就像 op/get-theme-dir 那样,

个人感觉用 op/get-template-dir 更好一点,如果不太喜欢这种方式,那么这个commit就不要合并了,

但 op/new-post-1 和 op/do-publication-1 建议合并,用op/new-post 和 op/do-publication 自定义命令不太好用。

sillykelvin commented 9 years ago

Your opinion about op/template-directory is right, I reviewed the code, we should not use a variable for that, as it will be set every time when op/do-publication is called, so it is not possible for user to customize this variable. I am going to merge this commit.

for op/new-post-1, when you say op/new-post is not proper for elisp programming, maybe you mean that there is interactive call in it:

(call-interactively 'op/insert-options-template)

it will prompt you for post's title, etc. However, I reviewed you change, there is still interactive call in op/new-post-1, wouldn't it still not work?

tumashu commented 9 years ago

op/insert-options-template 也应该稍微调整一下,因为我发现,从minbuffer里输入信息完全没有另一种方式快捷,及:插入一个默认模版然后再编辑。也许在elisp中,op/new-post-1应该直接插入一个默认模版。。。

sillykelvin commented 9 years ago

After some research, I find there is a function called-interactively-p, we can use it to determine if a function is called in ELisp or is called interactively, so I removed op/do-publication-1 and op/new-post-1, and enhanced op/new-post with called-interactively-p to support the invocation of it in ELisp with a default blog template inserted.