mirror of
https://gitlab.com/ansol/web-ansol.org.git
synced 2024-11-27 00:07:43 +00:00
Workaround for ruby <3
This commit is contained in:
parent
d597878342
commit
a59f80ddca
@ -3,13 +3,22 @@
|
|||||||
require 'yaml'
|
require 'yaml'
|
||||||
require 'date'
|
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
|
class YAMLFrontMatter
|
||||||
PATTERN = /\A(---\r?\n(.*?)\n?^---\s*$\n?)/m.freeze
|
PATTERN = /\A(---\r?\n(.*?)\n?^---\s*$\n?)/m.freeze
|
||||||
|
|
||||||
class << self
|
class << self
|
||||||
def extract(content)
|
def extract(content)
|
||||||
if content =~ PATTERN
|
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
|
else
|
||||||
[{}, content]
|
[{}, content]
|
||||||
end
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user