I just switched my whole workflow to Emacs. I run a personal blog and I want to run it…
- User
I just switched my whole workflow to Emacs. I run a personal blog and I want to run it through Orgmode for generation. How should I do it?
Assistant
Congratulations on switching to Emacs! Using Org mode for your personal blog is a great choice—it allows you to write in a structured, distraction-free environment while leveraging Emacs' powerful publishing capabilities. Here’s a step-by-step guide to setting up a blog with Org mode:
1. Basic Setup
First, ensure you have the latest Emacs and Org mode installed. You can install Org mode via
M-x package-install RET org RETif it's not already included.
2. Organize Your Blog Structure
Create a directory for your blog with the following structure:
~/my-blog/ ├── content/ # Org files for posts/pages ├── static/ # Images, CSS, JS ├── public/ # Generated HTML (output) └── publish.el # Publishing configuration
3. Configure Publishing (publish.el)
Add this to your
publish.el(orinit.el/config.el):(require 'ox-publish) (setq org-publish-project-alist '(("blog-content" :base-directory "~/my-blog/content/" :base-extension "org" :publishing-directory "~/my-blog/public/" :recursive t :publishing-function org-html-publish-to-html :headline-levels 4 :auto-preamble t :auto-sitemap t ; Generate index page :sitemap-title "Blog Archive" :sitemap-filename "index.org" ; Outputs to index.html :sitemap-sort-files anti-chronologically :html-head "<link rel='stylesheet' href='/css/style.css' />" :html-preamble "<div class='header'><h1>My Blog</h1></div>" :html-postamble "<div class='footer'><p>Made with Emacs + Org</p></div>") ("blog-static" :base-directory "~/my-blog/static/" :base-extension "css\\|js\\|png\\|jpg\\|gif\\|pdf\\|mp3\\|ogg\\|svg" :publishing-directory "~/my-blog/public/" :recursive t :publishing-function org-publish-attachment) ("blog" :components ("blog-content" "blog-static"))))Key Options:
auto-sitemap: Generates an index page listing all posts.html-head: Add custom CSS/JS.html-preamble/postamble: Add headers/footers.
4. Write Posts in Org Mode
Create
.orgfiles in~/my-blog/content/. Example:#+TITLE: My First Post #+DATE: 2024-05-20 #+TAGS: emacs, blogging * Introduction This is my first post published from Org mode!Frontmatter Options:
#+TITLE,#+DATE,#+TAGSare used for metadata.- Use
#+OPTIONS: toc:2to add a table of contents.
5. Publish Your Blog
Run
M-x org-publishand select theblogproject. Alternatively, add this topublish.el:(defun publish-blog () (interactive) (org-publish "blog" t))Now you can run
M-x publish-blogto regenerate all files.
6. Automate Publishing
To auto-publish on save, add this to
publish.el:(defun auto-publish-on-save () (when (string= (buffer-file-name) "~/my-blog/content/YOUR_POST.org") ; Adjust path (publish-blog))) (add-hook 'after-save-hook 'auto-publish-on-save)
7. Style Your Blog
- Add a CSS file in
~/my-blog/static/css/style.cssand link it in:html-head. - Use
#+HTML_HEAD: <link...>in individual posts for custom styling.
8. Advanced Options
- Themes: Use packages like
org-html-themesorox-hugo(for Hugo compatibility). - Comments: Add Disqus via
:html-postamble. - RSS Feed: Use
ox-rssto generate a feed.
9. Deploy
Sync the
~/my-blog/public/folder to your web server (e.g., via GitHub Pages, Netlify, or rsync).
Example Workflow
- Write a post in
content/post.org. - Run
M-x publish-blog. - Preview locally with
python3 -m http.serverin~/my-blog/public/. - Deploy to your host.
Alternatives
- For more complex needs, consider:
ox-hugo: Export to Hugo-compatible Markdown.org-static-blog: A dedicated package for blogs.
This setup keeps everything in Emacs while giving you full control over the output. Happy blogging!
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.