ardumont / org2jekyll

Blogging with org-mode and jekyll without alien yaml headers.
GNU General Public License v2.0
71 stars 19 forks source link

org2jekyll 0.2.5 not producing full post #63

Closed robertpostill closed 4 years ago

robertpostill commented 4 years ago

bug?

Yes, I'm afraid so. It could also be me.

M-x org2jekyll-bug-report

System information:
- system-type: darwin
- locale-coding-system: utf-8-unix
- emacs-version: GNU Emacs 26.3 (build 1, x86_64-apple-darwin18.2.0, NS appkit-1671.20 Version 10.14.3 (Build 18D109))
 of 2019-09-02
- org version: 9.1.9
- org2jekyll version: 0.2.5
- org2jekyll path: /Users/robertpostill/software/emacs-config/.cask/26.3/elpa/org2jekyll-20200521.1656/org2jekyll.el"

Expected behaviour

When publishing a blog post I would expect that the blog post comes out an entire post. This has previously worked for me.

Actual behaviour

The HTML file appears in the _posts directory but is missing the front matter for Jekyll to process.

Also (I don't know if this is related) but org files appear with the date in them in my org dir. I will take that to a separate issue if that's not relevant to this issue. So here's the top of my org file:

#+STARTUP: showall
#+STARTUP: hidestars
#+OPTIONS: H:2 num:nil tags:t toc:nil timestamps:t
#+LAYOUT: post
#+AUTHOR: robertpostill
#+DATE: 2020-05-25 Mon 22:06
#+TITLE: Planning To Add Auth - Part 2 - Fixing the package
#+DESCRIPTION: The yak shave is now in full swing, can I fix the mongodb driver so the previous functionality works again?
#+TAGS: racket testing mongodb yak-shaving
#+CATEGORIES: racket authentication yak-shaving monogdb

* I've just joined, what happened?

Here's the top of the HTML file:


<div id="outline-container-org324fd50" class="outline-2">
<h2 id="org324fd50">I've just joined, what happened?</h2>
<div class="outline-text-2" id="text-org324fd50">

Steps to reproduce the behaviour

M-x org2jekyll-publish-posts

How can we try and reproduce? Relevant bit of my init.el

 '(org2jekyll-blog-author "robertpostill")
 '(org2jekyll-jekyll-directory (expand-file-name "~/software/robertpostill.github.io/"))
 '(org2jekyll-jekyll-drafts-dir "")
 '(org2jekyll-jekyll-posts-dir "_posts/")
 '(org2jekyll-source-directory
   (expand-file-name "~/software/robertpostill.github.io/org/"))

 '(org-publish-project-alist
   (\`
    (("default" :base-directory
      (\,
       (org2jekyll-input-directory))
      :base-extension "org" :publishing-directory
      (\,
       (org2jekyll-output-directory))
      :publishing-function org-html-publish-to-html :headline-levels 4 :section-numbers nil :with-toc nil :html-head "<link rel=\"stylesheet\" href=\"./css/style.css\" type=\"text/css\"/>" :html-preamble t :recursive t :make-index t :html-extension "html" :body-only t)
     ("post" :base-directory
      (\,
       (org2jekyll-input-directory))
      :base-extension "org" :publishing-directory
      (\,
       (org2jekyll-output-directory org2jekyll-jekyll-posts-dir))
      :publishing-function org-html-publish-to-html :headline-levels 4 :section-numbers nil :with-toc nil :html-head "<link rel=\"stylesheet\" href=\"./css/style.css\" type=\"text/css\"/>" :html-preamble t :recursive t :make-index t :html-extension "html" :body-only t)
     ("images" :base-directory
      (\,
       (org2jekyll-input-directory "img"))
      :base-extension "jpg\\|gif\\|png" :publishing-directory
      (\,
       (org2jekyll-output-directory "img"))
      :publishing-function org-publish-attachment :recursive t)
     ("js" :base-directory
      (\,
       (org2jekyll-input-directory "js"))
      :base-extension "js" :publishing-directory
      (\,
       (org2jekyll-output-directory "js"))
      :publishing-function org-publish-attachment :recursive t)
     ("css" :base-directory
      (\,
       (org2jekyll-input-directory "css"))
      :base-extension "css\\|el" :publishing-directory
      (\,
       (org2jekyll-output-directory "css"))
      :publishing-function org-publish-attachment :recursive t)
     ("web" :components
      ("images" "js" "css")))))
robertpostill commented 4 years ago

In case I don't otherwise say it. I love org2jekyll, thanks for doing this.

ardumont commented 4 years ago

Hello,

thanks for the thorough report and the vote of confidence ;)

I changed recently the way org2jekyll publish things so it actually is able to respect org-mode's options (toc, num, ...). For this, I added a hook to 'org-publish-after-publishing-hook, called org2jekyll-install-yaml-headers. That's the one in charge of writing the jekyll yaml headers (and drop temporary file).

That's expectedly set if you activate org2jekyll-mode M-x org2jekyll-mode [1]

From your report, I gather it's not called thus why you don't see the yaml in your html (and also the draft file with the jekyll date).

So first question, did you activate M-x orgjekyll-mode? I guess not since I failed to mention it in the upgrade section [1]

Second, can you please check what's the content of org-publish-after-publishing-hook? M-: org-publish-after-publishing-hook RET before and after activating org2jekyll (so you can check what I just told you ;)

[1] I realize now that I did mention the hook thing in the upgrade section of the README. I failed to mention the mode needs to be activated now.

tl; dr I choose to install the hook through a mode so it could be activated and deactivated. To avoid any conflict, when org2jekyll-mode is deactivated, the hook is uninstalled as well, so as to avoid other org minor modes clash (who might org publish stuff as well).

Cheers,

ardumont commented 4 years ago

To be clear, I intend to clarify the documentation about this later in the day (working right now ;) In the mean time, i'm still interested by your feedback.

Thanks in advance.

Cheers,

robertpostill commented 4 years ago

Thanks for the quick reply:smiley:. So I didn't have the minor mode enabled. I've adjusted my init.el to:

(require 'org) (require 'org2jekyll) (add-hook 'org-mode-hook 'turn-on-flyspell) (add-hook 'org-mode-hook #'org2jekyll-mode)

As suggested I can see that org-publish-after-publishing-hook now holds: (org2jekyll-install-yaml-headers) 👍

This appears to have fixed the issue when publishing a single post. So org2jekyll-publish works. However, I can still see the behaviour on org2jekyll-publish-posts. If I run that the org files are created with dates prepended and the _posts directory is untouched.

ardumont commented 4 years ago

awesome for the first part.

So org2jekyll-publish works. However, I can still see the behaviour on org2jekyll-publish-posts. If I run that the org files are created with dates prepended and the _posts directory is untouched.

less so here...

Yeah, i guess that's the same issue alright...

Although, that one is more tricky, the org2jekyll mode needs to be activated on each buffer org2jekyll works on... I need to reflect more on this...

Because at this point (in the publishing-process), org-mode is in charge... ... (few hours passed in between ;) ...

Letting this rest a bit, I'm wondering if the following would work:

(defun org2jekyll--publish-post-org-file-with-metadata (org-metadata org-file)
  "Publish as post with ORG-METADATA the ORG-FILE."
  (let* ((blog-project (assoc-default "layout" org-metadata))
         (file-date    (->  (assoc-default "date" org-metadata) org2jekyll--convert-timestamp-to-yyyy-dd-mm))
         (temp-file    (org2jekyll--compute-ready-jekyll-file-name file-date org-file)))
    (copy-file org-file temp-file 'overwrite 'keep-time 'preserve-ids 'preserve-perms)
    (with-temp-file temp-file
      (org2jekyll-mode)
      (org-publish-file temp-file
                        (assoc blog-project org-publish-project-alist)))))

Can you please try the following?

M-: paste-the-snippet-above-here RET And then try and publish posts again?

I'm testing on my side as well.

ardumont commented 4 years ago

I'm testing on my side as well.

From my tryouts, it seems to behave better that way but it's not entirely correct though. There remains dangling empty files YYYY-MM-DD-{post-filename}.org in the org2jekyll-source-directory...

That's annoying...

ardumont commented 4 years ago

With the following, i'm happy:

(defun org2jekyll--publish-post-org-file-with-metadata (org-metadata org-file)
  "Publish as post with ORG-METADATA the ORG-FILE."
  (let* ((blog-project (assoc-default "layout" org-metadata))
         (file-date    (->  (assoc-default "date" org-metadata) org2jekyll--convert-timestamp-to-yyyy-dd-mm))
         (temp-file    (org2jekyll--compute-ready-jekyll-file-name file-date org-file))
         (project      (assoc blog-project org-publish-project-alist)))
    (copy-file org-file temp-file 'overwrite 'keep-time 'preserve-ids 'preserve-perms)
    (org2jekyll-message "File: %s\nlayout: %s" temp-file blog-project)
    (org2jekyll-message "project: %s" project)
    (with-temp-file temp-file
      (org2jekyll-mode)
      (org-publish-file temp-file project))
    ;; the hook should have kicked-in already
    ;; if it remains dangling temporary file, just delete it
    (when (file-exists-p temp-file)
      (delete-file temp-file))))

Now comes the refactoring phase ;)

ardumont commented 4 years ago

And now, with this ^, I think the org2jekyll-mode is no longer required.

It can be nice to keep it for the bindings but it's no longer necessary for the publishing part.

Cheers,

ardumont commented 4 years ago

I have cut a new release 0.2.6 with the fix.

Cheers,

robertpostill commented 4 years ago

Thanks so much. I've tested it and it's published articles so I think this is ready to close. Thanks again for your help and responsiveness.

ardumont commented 4 years ago

Sure!

Thanks for raising the issue in the first place.

Now, I tend to publish one page/post at a time so I did not notice.

I have ceased the opportunity to improve on the reproducible steps (without having stuff conflated by my own configuration).

In the end, everybody wins so that's awesome ;)

Cheers,