bastibe / org-static-blog

A static site generator using org-mode
BSD 3-Clause "New" or "Revised" License
341 stars 74 forks source link

Why everything get's re rendered? #126

Open azegas opened 10 months ago

azegas commented 10 months ago

Hello!

Thank you for this great package, it has helped me to build my blog!


About the issue I am having:

We can see that only "hello" was added to the .org file:

image

When I execute my shell script named build.sh that runs this command:

emacs -Q --script build-site.el

build-site.el content:

;; ~/.emacs.d/elpa path.
(require 'package)
(setq package-user-dir (expand-file-name "./.packages"))
(setq package-archives '(("melpa" . "https://melpa.org/packages/")
             ("elpa" . "https://elpa.gnu.org/packages/")))

;; Initialize the package system
(package-initialize)
(unless package-archive-contents
  (package-refresh-contents))

(message "Package refresh complete!")

;; Install dependencies inside the ./packages directory
;; should install ONLY org-static-blog
(package-install 'org-static-blog)
(message "Package installation complete!")

;; stop making ~ files
(setq make-backup-files nil)

;; directories and urls
(setq org-static-blog-publish-title "yes.github.io")
(setq org-static-blog-publish-url "https://yes.github.io/private/html")
(setq org-static-blog-publish-directory "~/GIT/yes/html")
(setq org-static-blog-posts-directory "~/GIT/yes/org")
(setq org-static-blog-drafts-directory "~/GIT/yes/drafts")
(setq org-static-blog-index-length 5)
(setq org-static-blog-preview-date-first-p nil)
(setq org-static-blog-use-preview t)
(setq org-static-blog-enable-tags t)
(setq org-static-blog-no-post-tag "NONPOST")
(setq org-static-blog-enable-deprecation-warning nil)
;; (setq org-export-with-toc nil)            ;can add in individual file with #+OPTIONS: toc:1/nil
;; (setq org-export-with-section-numbers nil) ;can add in individual file with
;; #+OPTIONS: num:nil
(setq org-static-blog-page-header
"<meta name=\"author\" content=\"yes\">
<meta name=\"referrer\" content=\"no-referrer\">
<meta name=\"viewport\" content=\"initial-scale=1,width=device-width,minimum-scale=1\">
<link rel=\"stylesheet\" href=\"../static/style.css\"/>
<link rel=\"icon\" href=\"../static/ag.ico\">
<script src=\"../static/lightbox.js\"></script>
<script src=\"static/auto-render.min.js\"></script>")

(setq org-static-blog-page-preamble "<br>preamble here yo</br>")
(setq org-static-blog-page-postamble "<br>postamble in de house</br>")

(org-static-blog-publish t)

(message "Build complete!")

The html files are being generated, all good, BUT for some reason EVERYTHING get's rebuild. In my case all 41 files. Only the id tags change.. I don't really understand why. Is it intentional? I don't really like that it changes the "file modified" data, not sure if it translates to the date shown in the blog itself? Also all these git commits each time I make a change will make it unworkable to version control.

image

azegas commented 10 months ago

I see this in the readme.org:

image

But even if the html files already exist, they are being re rendered.

bastibe commented 10 months ago

Only the changed org-file should be re-exported. Regrettably, this does change all the ids in the HTML file, as they seem to be randomly generated by org-mode on every export. (If anyone knows a way of preventing that, I'd be most interested!) Existing HTML files should not be changed, however.

You can check out my own config to see if there are any notable differences between yours and mine. You could also try to configure your org-static-blog with absolute directory paths instead of relative ones. I've run into no ends of problems with that sort of thing, so that's perhaps worth a try.

azegas commented 10 months ago

"Only the changed org-file should be re-exported." "Existing HTML files should not be changed, however."

I tried making a little experiment. Today is Dec 18th. I have launched emacs with "emacs -q" not to load any additional configuration.

image

As we can see in the image I have 3 org files in /home/nixos/GIT/org-static-blog/org directory

I have just generated them all, so we can see the html file creation time is Dec 18th, 06:23:

I will go and modify one org file called "crontab__code_linux.org", which was last modified on Dec 11th.

image

Now I will regenerate the html files wiht my build command:

image

We can see that 6:44 I have changed the org file, then 06:45 I have regenerated the the html files and instead of only regenerating "crontab__code_linux.html", ALL html files got regenerated

image

So in the "Archive" page or in the post page, the date that we will see will not be from

But it wil always be the date of when the file was generated. Which will always be the date when you make a change to ANY of your .org file.

I wish there was a way to use these in org-static-blog export:

image

image

So I would clearly see the date that I specify in org file, the a clear date when the file was created and when the file was modified.

In org-static-blog it seems that I only can see the date modifed, which changes with each change in any of the org file it seems.

azegas commented 10 months ago

Placed the above for reference, what I will try now is:

will let you know how it goes

azegas commented 10 months ago

Okay so seems like having org-static-blog configuration in a separate file like I have(build-site.el) and then running it with build.sh script (like I described in my initial message) to generate the html files is responsible for this strange behavior where everything gets re-rendered.

IF I place my org-static-blog configuration(build-site.el) content into my emacs config, together with the rest of the packages - the behavior is proper, ONLY the modified .org files get re-rendered.

So basically this way of having multiple org-static-blog configs for different blogs does not really work(by the way, got this idea here - https://systemcrafters.net/publishing-websites-with-org-mode/building-the-site/ ).

bastibe commented 10 months ago

Thank you for your deep analysis!

Org-static-blog decides who gets re-rendered in the function org-static-blog-needs-publishing-p, which simply checks file modification dates of pub-filename and post-filename. I bet it trips up with the pub-filename generation, probably due to some unresolved path thing. Emacs and path normalization is often an issue.

But I have no idea how that could be related to having the config in a different place.

Regarding dates, the #+date (and #+title) field is extracted from the post with a simple regex search. It would be simple to additionally extract some other fields. It's not quite so simple to include them in your templates, however, as the formatting is currently implemented with the builtin format-time-string, which uses a single date.