mirror of
https://gitlab.com/ansol/web-ansol.org.git
synced 2024-10-12 03:02:11 +00:00
Workaround for ruby <3
This commit is contained in:
parent
d597878342
commit
a59f80ddca
|
@ -3,13 +3,22 @@
|
|||
require 'yaml'
|
||||
require 'date'
|
||||
|
||||
def yaml_load(text)
|
||||
# not sure if 3.0.0 is the right threshold, but it works
|
||||
if (RUBY_VERSION.split(".").map(&:to_i) <=> [3,0,0]) < 0
|
||||
YAML.load(text)
|
||||
else
|
||||
YAML.load(text, permitted_classes: [Symbol, Date, Time])
|
||||
end
|
||||
end
|
||||
|
||||
class YAMLFrontMatter
|
||||
PATTERN = /\A(---\r?\n(.*?)\n?^---\s*$\n?)/m.freeze
|
||||
|
||||
class << self
|
||||
def extract(content)
|
||||
if content =~ PATTERN
|
||||
[YAML.load(Regexp.last_match(2), permitted_classes: [Symbol, Date, Time]), content.sub(Regexp.last_match(1), "")]
|
||||
[yaml_load(Regexp.last_match(2)), content.sub(Regexp.last_match(1), "")]
|
||||
else
|
||||
[{}, content]
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue
Block a user