commit bd598d9d82bd390fe507bde40726a96d94476283
parent 0e4a1d08d028ddeb5a30a45365c9d74ff0857752
Author: Ryan Jeffrey <ryan@ryanmj.xyz>
Date: Mon, 24 Oct 2022 23:21:25 -0700
Use emacs to statically generate the site
Diffstat:
7 files changed, 104 insertions(+), 16 deletions(-)
diff --git a/Gemfile b/Gemfile
@@ -1,7 +1,7 @@
source "https://rubygems.org"
git_source(:github) { |repo| "https://github.com/#{repo}.git" }
-ruby "3.0.3"
+ruby ">= 3.0.3"
# Bundle edge Rails instead: gem "rails", github: "rails/rails", branch: "main"
gem "rails", "~> 7.0.2", ">= 7.0.2.2"
diff --git a/app/publish.el b/app/publish.el
@@ -0,0 +1,56 @@
+;;; package --- summary Blog post generator.
+
+;;; Copyright (C) Ryan Jeffrey 2022
+
+;;; Author: Ryan Jeffrey <ryan@ryanmj.xyz>
+;;; Created: 2021-02-12
+;;; Keywords: website org
+;;; Version: 0.1
+;;; Package-Requires: ((emacs "27.1"))
+;;; URL: https://gitlab.com/Mallock/site
+
+;;; License:
+
+;; This file is part of Ryan's Homepage.
+;;
+;; Ryan's Homepage is free software: you can redistribute it and/or modify
+;; it under the terms of the GNU General Public License as published by
+;; the Free Software Foundation, either version 3 of the License, or
+;; (at your option) any later version.
+;;
+;; Ryan's Homepage is distributed in the hope that it will be useful,
+;; but WITHOUT ANY WARRANTY; without even the implied warranty of
+;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+;; GNU General Public License for more details.
+;;
+;; You should have received a copy of the GNU General Public License
+;; along with Ryan's Homepage. If not, see <http://www.gnu.org/licenses/>.
+
+
+;;; Commentary:
+
+;; This script uses org-mode to export posts for my site.
+
+;;; Code:
+
+(require 'ox-publish)
+(require 'ox-html)
+
+;; Define the publishing project
+(setq org-publish-project-alist
+ (list
+ (list "org-site:blog"
+ :base-directory "./"
+ :publishing-directory "./"
+ :publishing-function 'org-html-publish-to-html
+ :with-creator t ;; Include Emacs and Org versions in footer
+ :with-toc 2 ;; Include a table of contents with a depth of 2
+ :section-numbers t ;; Don't include section numbers
+ :exclude ".*" ;; Exclude all files
+ :with-latex t ;; Enable latex for maths
+ :body-only t ;; Only publish the body of the HTML file
+ :include (list (nth 0 argv)) ;; Except the ones we want to compile
+ )))
+
+;; Generate the site output
+(org-publish-all t)
diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb
@@ -13,7 +13,27 @@
<%= stylesheet_link_tag "application", "data-turbo-track": "reload" %>
<meta name="author" content="Ryan Jeffrey" />
- <link rel="shortcut icon" type="image/x-icon" href="favicon32x32.ico">
+ <script type="text/x-mathjax-config">
+ MathJax.Hub.Config({
+ displayAlign: "center",
+ displayIndent: "0em",
+
+ "HTML-CSS": { scale: 100,
+ linebreaks: { automatic: "false" },
+ webFont: "TeX"
+ },
+ SVG: {scale: 100,
+ linebreaks: { automatic: "false" },
+ font: "TeX"},
+ NativeMML: {scale: 100},
+ TeX: { equationNumbers: {autoNumber: "AMS"},
+ MultLineWidth: "85%",
+ TagSide: "right",
+ TagIndent: ".8em"
+ }
+ });
+ </script>
+ <script src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.0/MathJax.js?config=TeX-AMS_HTML"></script> <link rel="shortcut icon" type="image/x-icon" href="favicon32x32.ico">
</head>
<body>
<nav>
diff --git a/app/views/posts/index.html.erb b/app/views/posts/index.html.erb
@@ -31,10 +31,9 @@
</div>
<div class="ewin">
<h3>Some cool peeps to check out.</h3>
-
<ul>
<li><a href="https://kylemcd.xyz">My Friend Kyle's Blog</a></li>
<li>Xah Lee's Blog (G©©g£€ it, I will not link to it becasue no https)</li>
<li><a href="https://lukesmith.xyz">Luke Smith</a></li>
- </ul>
+ </ul>
</div>
diff --git a/app/views/posts/show.html.erb b/app/views/posts/show.html.erb
@@ -1,3 +1,3 @@
<div class="ewin">
- <%= @post.body.html_safe %>
+ <%= File.read(Rails.root.join('app', 'orgs', @post.where, @post.body)).html_safe %>
</div>
diff --git a/config/application.rb b/config/application.rb
@@ -41,6 +41,11 @@ def remove_org_from_db(file_path)
post.destroy if post
end
+def compile_org_file(file_path_org)
+ # Generate the HTML file.
+ system("emacs -q --script #{Rails.root.join('app', 'publish.el')} #{file_path_org}")
+end
+
def update_org_db(file_path)
# Check to see if we're actually getting an org file.
return if File.extname(file_path) != '.org'
@@ -49,16 +54,18 @@ def update_org_db(file_path)
title = org_get_title file_path
dir_name = File.dirname(get_org_path file_path)
dir_name = dir_name == '.' ? '' : dir_name
- url = CGI.escape(File.basename(file_path, '.*'))
+ output_file_path = File.basename(file_path, '.org')
+ url = CGI.escape(output_file_path)
# Get the post.
post = Post.find_by(url: url, where: dir_name)
return if not post
# Reset content and title.
- puts "Setting the post"
- post.body = Orgmode::Parser.new(File.read(file_path)).to_html
+ puts "Setting post new body page"
+
+ compile_org_file file_path
post.title = title
post.save
- # TODO add more rescues for different errors
+ # TODO add more rescues for different errors
end
def add_org_to_db(file_path)
@@ -69,16 +76,22 @@ def add_org_to_db(file_path)
title = org_get_title file_path
dir_name = File.dirname(get_org_path file_path)
dir_name = dir_name == '.' ? '' : dir_name
- url = CGI.escape(File.basename(file_path, '.*'))
+
+ output_file_path = File.basename(file_path, '.org')
+ url = CGI.escape(output_file_path)
# Update org if it exists.
post = Post.find_by(url: url, where: dir_name)
return update_org_db(post) if post
- # TODO add more rescues for different errors
+ # TODO add more rescues for different errors
# File does not exist, create it.
+
+ compile_org_file file_path
+
+ # TODO description.
Post.new(title: title, description: '',
where: dir_name,
url: url,
- body: Orgmode::Parser.new(File.read(file_path)).to_html).save
+ body: output_file_path + '.html').save
end
module Site
diff --git a/db/schema.rb b/db/schema.rb
@@ -14,8 +14,8 @@ ActiveRecord::Schema[7.0].define(version: 2022_02_19_224343) do
create_table "active_storage_attachments", force: :cascade do |t|
t.string "name", null: false
t.string "record_type", null: false
- t.bigint "record_id", null: false
- t.bigint "blob_id", null: false
+ t.integer "record_id", null: false
+ t.integer "blob_id", null: false
t.datetime "created_at", null: false
t.index ["blob_id"], name: "index_active_storage_attachments_on_blob_id"
t.index ["record_type", "record_id", "name", "blob_id"], name: "index_active_storage_attachments_uniqueness", unique: true
@@ -34,13 +34,13 @@ ActiveRecord::Schema[7.0].define(version: 2022_02_19_224343) do
end
create_table "active_storage_variant_records", force: :cascade do |t|
- t.bigint "blob_id", null: false
+ t.integer "blob_id", null: false
t.string "variation_digest", null: false
t.index ["blob_id", "variation_digest"], name: "index_active_storage_variant_records_uniqueness", unique: true
end
create_table "posts", force: :cascade do |t|
- t.text "body"
+ t.string "body"
t.string "title"
t.string "description"
t.string "where"