3 # Nick's web site: Autogenerate timestamps for nanoc items.
5 # Copyright © 2020 Nick Bowler
7 # This program is free software: you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License as published by
9 # the Free Software Foundation, either version 3 of the License, or
10 # (at your option) any later version.
12 # This program is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
17 # You should have received a copy of the GNU General Public License
18 # along with this program. If not, see <https://www.gnu.org/licenses/>.
25 if content =~ /\A---(--)?\s*$/
26 parts = content.split(/^---(--)?[ \t]*\r?\n?/, 3)
32 meta = YAML.load(metadata)
34 updatestr = updatetime.round.strftime(timefmt)
37 if meta["published"] and meta["updated"].is_a?(Time)
38 s = meta["updated"].strftime(timefmt)
39 if metadata.sub!(/^updated:\s*#{s}\s*$/, "updated: " + updatestr)
42 elsif meta["published"] and !meta["updated"]
43 metadata += "updated: " + updatestr
45 elsif !meta["published"]
46 metadata += "published: " + updatestr
52 meta = YAML.load(metadata)
53 unless meta[autoset] == updatetime.round
54 raise "failed to auto-insert " + autoset