diff options
author | Paul Duncan <pabs@pablotron.org> | 2021-10-16 21:57:17 -0400 |
---|---|---|
committer | Paul Duncan <pabs@pablotron.org> | 2021-10-16 21:57:17 -0400 |
commit | 41b1a847284d870b6a592d12dfff289fc7e7da2d (patch) | |
tree | 50de5678e801275ffc9824b9c9515af30b725288 /bin | |
parent | 43423bbd2a5a5fd6ab8556cdbd44cfea2d9b5983 (diff) | |
download | pablotron.org-41b1a847284d870b6a592d12dfff289fc7e7da2d.tar.bz2 pablotron.org-41b1a847284d870b6a592d12dfff289fc7e7da2d.zip |
add bin/gen-projects.rb and data/projects.yaml
Diffstat (limited to 'bin')
-rw-r--r-- | bin/gen-projects.rb | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/bin/gen-projects.rb b/bin/gen-projects.rb new file mode 100644 index 0000000..ef4c547 --- /dev/null +++ b/bin/gen-projects.rb @@ -0,0 +1,51 @@ +#!/usr/bin/env ruby +# frozen_string_literal: true + +# +# gen-projects.rb: generate front matter from list of projects in +# data/projects.yaml. +# +# Note: running this will blindly overwrite the contents of +# content/projects/$PROJECT.md! +# + +# load libraries +require 'yaml' + +# build absolute paths to source projects.yaml and absolute path to +# content/projects directory +YAML_PATH = File.join(__dir__, '..', 'data', 'projects.yaml') +PROJECTS_DIR = File.join(__dir__, '..', 'content', 'projects') + +PROJECT_TMPL = ' +--- +title: "%<name>s" +slug: "%<slug>s" +active: %<active>s +repo: "%<repo>s" +text: "%<text>s" +--- +%<text>s +'.strip + +# +# write front matter for project to projects directory +# +def write_project(row) + # build absolute path to destination file + path = File.expand_path(File.join(PROJECTS_DIR, row['slug'])) + '.md' + + # generate and write body + File.write(path, PROJECT_TMPL % { + name: row['name'], + slug: row['slug'], + active: !row['old'], + repo: row['repo'], + text: row['text'], + }) +end + +# write projects in green threads, then join threads +YAML.load(File.read(YAML_PATH)).map do |row| + Thread.new(row) { |row| write_project(row) } +end.each { |th| th.join } |