Load config from file
This commit is contained in:
parent
8a6d2ca90e
commit
90dae92c30
7 changed files with 61 additions and 25 deletions
6
config/gemini.yml
Normal file
6
config/gemini.yml
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
---
|
||||||
|
format: gemtext
|
||||||
|
|
||||||
|
base_url: 'gemini://causa-arcana.com'
|
||||||
|
current_path: '/xx/blog/xxxx/xx/xx/xxxxx.xxx'
|
||||||
|
relative_urls: true
|
15
config/http.yml
Normal file
15
config/http.yml
Normal file
|
@ -0,0 +1,15 @@
|
||||||
|
---
|
||||||
|
format: html
|
||||||
|
|
||||||
|
base_url: 'https://causa-arcana.com'
|
||||||
|
current_path: '/xx/blog/xxxx/xx/xx/xxxxx.xxx'
|
||||||
|
relative_urls: true
|
||||||
|
|
||||||
|
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'
|
15
config/rss.yml
Normal file
15
config/rss.yml
Normal file
|
@ -0,0 +1,15 @@
|
||||||
|
---
|
||||||
|
format: html
|
||||||
|
|
||||||
|
base_url: 'https://causa-arcana.com'
|
||||||
|
current_path: '/xx/blog/xxxx/xx/xx/xxxxx.xxx'
|
||||||
|
relative_urls: false
|
||||||
|
|
||||||
|
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'
|
2
config/word_count.yml
Normal file
2
config/word_count.yml
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
---
|
||||||
|
format: word_count
|
|
@ -8,35 +8,16 @@ require 'bundler/setup'
|
||||||
|
|
||||||
require 'repubmark'
|
require 'repubmark'
|
||||||
|
|
||||||
format = String(ARGV[0]).to_sym
|
config = Repubmark::Config.load_file String ARGV[0]
|
||||||
unless Repubmark::FORMATS.include? format
|
|
||||||
raise "Invalid format: #{format.inspect}"
|
|
||||||
end
|
|
||||||
|
|
||||||
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
|
$article = Repubmark::Elems::Article.new config
|
||||||
|
|
||||||
|
template = $stdin.read.freeze
|
||||||
context = BasicObject.new
|
context = BasicObject.new
|
||||||
def context.article = $article
|
def context.article = $article
|
||||||
context.instance_eval template, __FILE__, __LINE__
|
context.instance_eval template, __FILE__, __LINE__
|
||||||
|
|
||||||
output =
|
output =
|
||||||
case format
|
case config.format
|
||||||
when :word_count then $article.word_count
|
when :word_count then $article.word_count
|
||||||
when :html then $article.to_html
|
when :html then $article.to_html
|
||||||
when :gemtext then $article.to_gemtext
|
when :gemtext then $article.to_gemtext
|
||||||
|
|
|
@ -5,6 +5,7 @@ require 'forwardable'
|
||||||
require 'open3'
|
require 'open3'
|
||||||
require 'pathname'
|
require 'pathname'
|
||||||
require 'uri'
|
require 'uri'
|
||||||
|
require 'yaml'
|
||||||
|
|
||||||
require_relative 'repubmark/config'
|
require_relative 'repubmark/config'
|
||||||
require_relative 'repubmark/highlight'
|
require_relative 'repubmark/highlight'
|
||||||
|
@ -56,5 +57,5 @@ require_relative 'repubmark/elems/text'
|
||||||
require_relative 'repubmark/elems/link'
|
require_relative 'repubmark/elems/link'
|
||||||
|
|
||||||
module Repubmark
|
module Repubmark
|
||||||
FORMATS = %i[gemtext html].freeze
|
FORMATS = %i[gemtext html word_count].freeze
|
||||||
end
|
end
|
||||||
|
|
|
@ -18,8 +18,15 @@ module Repubmark
|
||||||
relative_urls
|
relative_urls
|
||||||
].freeze
|
].freeze
|
||||||
|
|
||||||
def initialize(**kwargs)
|
attr_reader :format
|
||||||
raise unless (kwargs.keys.sort - OPTIONAL_KEYS).empty?
|
|
||||||
|
def self.load_file(filename)
|
||||||
|
new(**YAML.safe_load_file(filename).transform_keys(&:to_sym))
|
||||||
|
end
|
||||||
|
|
||||||
|
def initialize(format:, **kwargs)
|
||||||
|
self.format = format
|
||||||
|
raise unless (kwargs.keys - OPTIONAL_KEYS).empty?
|
||||||
|
|
||||||
@kwargs = kwargs.freeze
|
@kwargs = kwargs.freeze
|
||||||
end
|
end
|
||||||
|
@ -27,5 +34,14 @@ module Repubmark
|
||||||
def [](key)
|
def [](key)
|
||||||
OPTIONAL_KEYS.include?(key) ? @kwargs[key] : @kwargs.fetch(key)
|
OPTIONAL_KEYS.include?(key) ? @kwargs[key] : @kwargs.fetch(key)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
|
||||||
|
def format=(format)
|
||||||
|
format = format.to_sym if format.instance_of? String
|
||||||
|
raise 'Invalid format' unless FORMATS.include? format
|
||||||
|
|
||||||
|
@format = format
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue