site

Website's source files.
git clone git://git.ryanmj.xyz/site.git
Log | Files | Refs | LICENSE

commit 164c56b6356ec1873b8bf5db1bd6eeabaa4be8fa
parent a1a879a3c31e2ef93c26d8afdd260fef255ca95c
Author: Ryan Jeffrey <ryan@ryanmj.xyz>
Date:   Sun, 20 Feb 2022 00:09:22 -0800

New URL system, get post by url and directory

Diffstat:
Mapp/controllers/posts_controller.rb | 1-
Mconfig/application.rb | 17++++++++++-------
2 files changed, 10 insertions(+), 8 deletions(-)

diff --git a/app/controllers/posts_controller.rb b/app/controllers/posts_controller.rb @@ -1,4 +1,3 @@ - class PostsController < ApplicationController def index end diff --git a/config/application.rb b/config/application.rb @@ -31,9 +31,11 @@ def get_org_path(file_path) end def remove_org_from_db(file_path) - title = get_org_path file_path + dir_name = File.dirname(get_org_path file_path) + dir_name = dir_name == '.' ? '' : dir_name + url = CGI.escape(File.basename(file_path, '.*')) begin - post = Post.where(title: title).sole + post = Post.where(url: url).sole post.destroy rescue => error # Nothing to destroy @@ -41,21 +43,22 @@ def remove_org_from_db(file_path) end def add_org_to_db(file_path) - # TODO actually get the title of the document. # TODO get a description 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, '.*')) begin - post = Post.where(title: title).sole + post = Post.where(url: url).sole # Reset content and title. post.body = Orgmode::Parser.new(File.read(file_path)).to_html post.title = title # TODO add more rescues for different errors rescue => error # File does not exist, create it. - dir_name = File.dirname(get_org_path file_path) Post.new(title: title, description: '', - where: dir_name == '.' ? '' : dir_name, - url: File.basename(file_path, '.*'), + where: dir_name, + url: url, body: Orgmode::Parser.new(File.read(file_path)).to_html).save end end