Skip to content

Commit

Permalink
Add a changelog.xml feed
Browse files Browse the repository at this point in the history
I like authoring strong commits. Sharing my commits via RSS as a
changelog motivates me to keep up the good habits of writing strong
commits.

I like writing. I like process. I like writing about process. This silly
idea will give me a feedback loop.
  • Loading branch information
danott committed Jan 16, 2024
1 parent 78f752f commit a2e57c4
Show file tree
Hide file tree
Showing 6 changed files with 122 additions and 2 deletions.
2 changes: 2 additions & 0 deletions lib/feed_target.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
class FeedTarget
include Singleton

TARGET_PATH = Build.target_dir + "/feed.xml"
AUTHOR = "Dan Ott".freeze
TITLE = "Dan Ott's RSS Feed".freeze
Expand Down
77 changes: 77 additions & 0 deletions lib/git_commit_changelog_target.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
class GitCommitChangelogTarget
include Singleton

TARGET_PATH = Build.target_dir + "/changelog.xml"
AUTHOR = "Dan Ott".freeze
TITLE = "Dan Ott's Website Changelog"
URL = "https://danott.website"

def to_target
self
end

def hydrate
self
end

def render
RSS::Maker.make("2.0") do |maker|
maker.channel.author = AUTHOR
maker.channel.updated = commits.map(&:date).max.to_s
maker.channel.about = URL
maker.channel.title = TITLE
maker.channel.link = URL
maker.channel.description = TITLE

commits.each do |commit|
maker.items.new_item do |maker_item|
maker_item.description = commit.description
maker_item.link = commit.link
maker_item.title = commit.title
maker_item.updated = commit.updated
end
end
end
end

def write
File.write(TARGET_PATH, render)
self
end

def commits
GitCommitJson.generate.map do |commit|
CommitRssItem.new(
subject: commit.fetch("subject"),
body: commit.fetch("body"),
date: Time.parse(commit.fetch("date")),
hash: commit.fetch("hash")
)
end
end

CommitRssItem =
Struct.new(:subject, :body, :date, :hash, keyword_init: true) do
def title
subject
end

def description
options = {
auto_ids: false,
hard_wrap: false,
input: "GFM",
syntax_highlighter: "rouge"
}
Kramdown::Document.new(body, options).to_html.strip
end

def link
"https://github.com/danott/website/commit/" + hash
end

def updated
date.to_s
end
end
end
39 changes: 39 additions & 0 deletions lib/git_commit_json.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# Generate a minimal JSON structure from git commits.
#
# https://gist.github.com/varemenos/e95c2e098e657c7688fd#gistcomment-3542030
# This prior art was helpful.
#
# https://git-scm.com/docs/pretty-formats
# The git pretty formats docs will be helpful if more details are ever desired.
class GitCommitJson
def self.generate(limit = 1000)
desired_json_structure = {
"body" => "%b",
"date" => "%cI",
"hash" => "%H",
"subject" => "%s"
}.freeze

ordered_attribute_keys = desired_json_structure.keys
ordered_attribute_value_placeholders = desired_json_structure.values

attribute_separator =
"🤞 I pledge to never type this in a git commit, lest I break my rudimentary parser"
commit_separator =
"...Same goes for this, because of the aforementioned parser breaking risks 🙃"

git_format =
ordered_attribute_value_placeholders.join(attribute_separator) +
commit_separator
log = `git log -n #{limit} --format="#{git_format}"`

log
.strip
.chomp(commit_separator)
.split(commit_separator)
.map do |commit|
ordered_attribute_values = commit.strip.split(attribute_separator)
Hash[ordered_attribute_keys.zip(ordered_attribute_values)]
end
end
end
3 changes: 2 additions & 1 deletion lib/includable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ module Includable
<link rel="stylesheet" href="/stylesheets/pygments-default.css" media="(prefers-color-scheme: light)">
<link rel="stylesheet" href="/stylesheets/pygments-monokai.css" media="(prefers-color-scheme: dark)">
<link rel="alternate" type="application/rss+xml" href="/feed.xml" title="Dan Ott's RSS Feed">
<link rel="alternate" type="application/rss+xml" href="/feed.xml" title="Dan Ott's Website RSS Feed">
<link rel="alternate" type="application/rss+xml" href="/changelog.xml" title="Dan Ott's Website Changelog">
<script src="/javascripts/script.js"></script>
</include-in-header>
Expand Down
1 change: 1 addition & 0 deletions site/changelog.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
GitCommitChangelogTarget.instance
2 changes: 1 addition & 1 deletion site/feed.rb
Original file line number Diff line number Diff line change
@@ -1 +1 @@
FeedTarget.new
FeedTarget.instance

0 comments on commit a2e57c4

Please sign in to comment.