site

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

commit a1a879a3c31e2ef93c26d8afdd260fef255ca95c
parent 64f756895b403795b0298cb60a0da87713830105
Author: Ryan Jeffrey <ryan@ryanmj.xyz>
Date:   Sat, 19 Feb 2022 23:33:14 -0800

Properly getting the title from the post

Diffstat:
Mconfig/application.rb | 19++++++++++++++++---
1 file changed, 16 insertions(+), 3 deletions(-)

diff --git a/config/application.rb b/config/application.rb @@ -12,15 +12,28 @@ def org_dir "#{Rails.root}/app/orgs" end +# Get the title of a org mode file. +def org_get_title(file_path) + title='' + File.readlines(file_path).each do |line| + if line.start_with?('#+TITLE:') + line['#+TITLE:'] = '' + title = line.strip + break + end + end + title +end + # Get the path to /app/org/f.org, chopping off anything before the org directory. def get_org_path(file_path) Pathname.new(file_path).relative_path_from(org_dir).to_s end def remove_org_from_db(file_path) - bsname = File.basename(file_path) + title = get_org_path file_path begin - post = Post.where(title: bsname).sole + post = Post.where(title: title).sole post.destroy rescue => error # Nothing to destroy @@ -30,7 +43,7 @@ end def add_org_to_db(file_path) # TODO actually get the title of the document. # TODO get a description - title = File.basename(file_path) + title = org_get_title file_path begin post = Post.where(title: title).sole # Reset content and title.