From 41b1a847284d870b6a592d12dfff289fc7e7da2d Mon Sep 17 00:00:00 2001 From: Paul Duncan Date: Sat, 16 Oct 2021 21:57:17 -0400 Subject: add bin/gen-projects.rb and data/projects.yaml --- bin/gen-projects.rb | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 bin/gen-projects.rb (limited to 'bin') 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: "%s" +slug: "%s" +active: %s +repo: "%s" +text: "%s" +--- +%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 } -- cgit v1.2.3