module Fronde::IndexOrgGenerator
Embeds methods responsible for generating an org file for a given
index.
Public Instance Methods
to_org(index_name = 'index', is_project: false)
click to toggle source
# File lib/fronde/index/org_generator.rb, line 7 def to_org(index_name = 'index', is_project: false) return project_home_page(index_name) if is_project return all_tags_index if index_name == 'index' [org_header(index_name), org_articles(@index[index_name])].join("\n") end
Also aliased as: to_s
write_org(index_name)
click to toggle source
# File lib/fronde/index/org_generator.rb, line 15 def write_org(index_name) return unless save? slug = Fronde::OrgFile.slug index_name FileUtils.mkdir 'tags' unless Dir.exist? 'tags' content = to_org index_name orgdest = "tags/#{slug}.org" IO.write(orgdest, content) end
Private Instance Methods
org_articles(articles_list)
click to toggle source
# File lib/fronde/index/org_generator.rb, line 79 def org_articles(articles_list) last_year = nil articles_list.map do |article| year_title = '' year = article.timekey.slice(0, 4) if year != last_year year_title = format("\n%<title>s\n", title: org_title(year)) last_year = year end year_title + org_entry(article) end end
org_entry(article)
click to toggle source
# File lib/fronde/index/org_generator.rb, line 92 def org_entry(article) line = "- *[[#{article.url}][#{article.title}]]*" if article.date art_date = article.datestring(:full, year: false) published = R18n.t.fronde.index.published_on art_date line += " / #{published}" end line += " \\\\\n #{article.excerpt}" if article.excerpt != '' line end
org_header(title = nil, is_tag: true)
click to toggle source
# File lib/fronde/index/org_generator.rb, line 66 def org_header(title = nil, is_tag: true) if is_tag title = @tags_names[title] elsif title.nil? || title == 'index' title = Fronde::Config.settings['title'] end <<~HEADER.strip #+title: #{title} #+author: #{Fronde::Config.settings['author']} #+language: #{Fronde::Config.settings['lang']} HEADER end
org_title(year, html_class = 'index-year')
click to toggle source
# File lib/fronde/index/org_generator.rb, line 103 def org_title(year, html_class = 'index-year') year = R18n.t.fronde.index.unsorted if year == '0000' <<~ENDPROP * #{year} :PROPERTIES: :HTML_CONTAINER_CLASS: #{html_class} :UNNUMBERED: notoc :END: ENDPROP end
project_home_page(project_name)
click to toggle source
# File lib/fronde/index/org_generator.rb, line 26 def project_home_page(project_name) content = [org_header(project_name, is_tag: false)] if @projects[project_name]&.any? content += org_articles(@projects[project_name]) end content.join("\n") end
tag_published_url(tag_name)
click to toggle source
# File lib/fronde/index/org_generator.rb, line 59 def tag_published_url(tag_name) domain = Fronde::Config.settings['domain'] title = @tags_names[tag_name] tag_link = "#{domain}/tags/#{tag_name}.html" "[[#{tag_link}][#{title}]]" end
write_all_blog_home(verbose)
click to toggle source
# File lib/fronde/index/org_generator.rb, line 34 def write_all_blog_home(verbose) Fronde::Config.sources.each do |project| next unless project['is_blog'] next unless Dir.exist?(project['path']) warn "Generated blog home for #{project['name']}" if verbose orgdest = format('%<root>s/index.org', root: project['path']) IO.write(orgdest, to_org(project['name'], is_project: true)) end end