fork download
  1. require "yaml"
  2.  
  3. YAML_FRONT_MATTER_REGEXP = /\A(---\s*\n.*?\n?)^((---|\.\.\.)\s*$\n?)/m
  4.  
  5. def update_data(data)
  6. data.merge("A" => 2)
  7. end
  8.  
  9. if $stdin.read =~ YAML_FRONT_MATTER_REGEXP
  10. data, content = YAML.load($1), Regexp.last_match.post_match
  11. data = update_data(data)
  12. YAML.dump(data, $stdout)
  13. $stdout.puts("---", content)
  14. end
Success #stdin #stdout 0.1s 11472KB
stdin
---
A: 1
---
# Title
Words. More words. This is the words part of the file.
stdout
---
A: 2
---
# Title
Words. More words. This is the words part of the file.