repubmark/exe/repubmark

45 lines
1.2 KiB
Ruby
Executable file

#!/usr/bin/env ruby
# frozen_string_literal: true
lib = File.expand_path('../lib', __dir__).freeze
$LOAD_PATH.unshift lib unless $LOAD_PATH.include? lib
require 'bundler/setup'
require 'repubmark'
FORMATS = %w[word_count html gemtext].freeze
format = String(ARGV[0]).freeze
raise "Invalid format: #{format.inspect}" unless FORMATS.include? format
template = $stdin.read.freeze
config = Repubmark::Config.new(
base_url: 'https://causa-arcana.com',
css_class_annotation: 'nice-annotation',
css_class_blockquote_figure: 'nice-blockquote',
css_class_figure_self: 'nice-figure',
css_class_figure_wrap: 'd-flex justify-content-center',
css_class_figures_left: 'col-xl-6',
css_class_figures_right: 'col-xl-6',
css_class_figures_wrap: 'row',
css_class_iframe_wrap: 'ratio ratio-16x9',
current_path: '/xx/blog/xxxx/xx/xx/xxx.xxx',
relative_urls: false,
)
$article = Repubmark::Elems::Article.new config
context = BasicObject.new
def context.article = $article
context.instance_eval template, __FILE__, __LINE__
output =
case format
when 'word_count' then $article.word_count
when 'html' then $article.to_html
when 'gemtext' then $article.to_gemtext
end.to_s.strip
puts output unless output.empty?