Skip to content

Commit

Permalink
Move data sets into a dedicated directory
Browse files Browse the repository at this point in the history
I want site and _site to be a similar shape. The leading-underscore YAML
files are not intended to have a 1:1 relationship with a generated file.

I think that's my major mental model. I want there to be a 1:1
relationship between a "source" in `site` and a "target" in `_site`.

We'll see.
  • Loading branch information
danott committed Jan 15, 2024
1 parent 3d60ab7 commit e989c97
Show file tree
Hide file tree
Showing 8 changed files with 31 additions and 22 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/download_pinboard_bookmarks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,6 @@ jobs:
run: |
git config --local user.email "action@github.com"
git config --local user.name "GitHub Action"
git add site/_pinboard_bookmarks.yml
git commit --only site/_pinboard_bookmarks.yml --message "Ran rake download_pinboard_bookmarks in a GitHub Action" || echo "Nothing to commit"
git add data/pinboard_bookmarks.yml
git commit --only data/pinboard_bookmarks.yml --message "Ran rake download_pinboard_bookmarks in a GitHub Action" || echo "Nothing to commit"
git push
File renamed without changes.
File renamed without changes.
10 changes: 9 additions & 1 deletion lib/build.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ def target_dir
"_site"
end

def data_dir
"data"
end

def dehydrated_sources
@dehydrated_sources ||= Source.gather(source_dir)
end
Expand All @@ -29,8 +33,12 @@ def hydrated_targets
@hydrated_targets ||= dehydrated_targets.map(&:hydrate) + [RssTarget.new]
end

def data_sets
DataSet.gather(data_dir)
end

def data
@data ||= BuildData.new(dehydrated_targets)
@data ||= BuildData.new(dehydrated_targets, data_sets)
end

def includables
Expand Down
8 changes: 5 additions & 3 deletions lib/build_data.rb
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
class BuildData
attr_reader :targets
attr_reader :data_sets
attr_reader :current_page

def initialize(targets, current_page = nil)
def initialize(targets, data_sets, current_page = nil)
@targets = targets
@data_sets = data_sets
@current_page = current_page
end

def for_current_page(next_current_page)
self.class.new(targets, next_current_page)
self.class.new(targets, data_sets, next_current_page)
end

def all
Expand Down Expand Up @@ -42,7 +44,7 @@ def assets
end

def sets
targets.select { |t| t.is_a?(DataSet) }.map { |t| [t.name, t.data] }.to_h
data_sets.map { |t| [t.name, t.data] }.to_h
end

def tags
Expand Down
27 changes: 14 additions & 13 deletions lib/data_set.rb
Original file line number Diff line number Diff line change
@@ -1,26 +1,27 @@
class DataSet
attr_reader :path

def self.gather(dir)
Dir
.glob("#{dir}/*")
.reject { |path| File.directory?(path) }
.map { |path| new(path) }
end

def initialize(path)
@path = path
end

def data
YAML.safe_load(
File.read(path),
permitted_classes: [Date, PinboardBookmark, Symbol]
)
@data ||=
YAML.safe_load(
File.read(path),
permitted_classes: [Date, PinboardBookmark, Symbol]
)
end

def name
path.delete_prefix(Build.source_dir).delete_prefix("/_").delete(".yml")
end

def hydrate
self
end

def write
self
extname = File.extname(path)
File.basename(path, extname)
end
end
2 changes: 1 addition & 1 deletion lib/pinboard_bookmark.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
PinboardBookmark =
Struct.new(:href, :title, :commentary, :date, :tags, keyword_init: true) do
PATH = "site/_pinboard_bookmarks.yml".freeze
PATH = "data/pinboard_bookmarks.yml".freeze

def self.pull
auth_token = ENV["DANOTT_DOT_WEBSITE_PINBOARD_AUTH_TOKEN"]
Expand Down
2 changes: 0 additions & 2 deletions lib/source.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@ def self.for(path)
MarkdownSource.new(path: path, content: MagicFile.read(path))
when ".css", ".jpg", ".js", ".png"
FileCopier.new(path)
when ".yml"
DataSet.new(path)
else
NoopSource.new(path)
end
Expand Down

0 comments on commit e989c97

Please sign in to comment.