Skip to content

Commit

Permalink
Fix upcased slug for author 18F
Browse files Browse the repository at this point in the history
  • Loading branch information
beechnut committed May 24, 2024
1 parent f8a9f78 commit f65b552
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 8 deletions.
20 changes: 12 additions & 8 deletions lib/author.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,20 +29,20 @@ def photo_tag(config: Jekyll.sites[0].config)
Photo.new(slug: slug, config: config).tag
end

def path(config: Jekyll.sites[0].config)
"#{config.fetch("baseurl")}/author/#{slug}"
end

def link_tag(config: Jekyll.sites[0].config)
if published?
"<a class='post-author' itemprop='name' href='#{path}'>#{full_name}</a>"
# @smell Too many dependencies being injected. This maybe wants to
# be a service object.
def link_tag(list: Post.author_slugs, config: Jekyll.sites[0].config)
if published?(list: list)
"<a class='post-author' itemprop='name' href='#{path(config: config)}'>#{full_name}</a>"
else
full_name
end
end

# Most slugs are fine as-is, but 18F needs to be downcased because
# of how it's specified in author frontmatter
def published?(list: Post.author_slugs)
list.include?(slug)
list.map(&:downcase).include?(slug.downcase)
end

def update_published!(list: Post.author_slugs)
Expand Down Expand Up @@ -82,6 +82,10 @@ def ensure_matching_slug(path)

private

def path(config: Jekyll.sites[0].config)
"#{config.fetch("baseurl")}/author/#{slug.downcase}"
end

def warn_about_unpublishing
warn "Author #{full_name} was formerly published, updating to un-published. This shouldn't be a normal occurrence."
end
Expand Down
17 changes: 17 additions & 0 deletions spec/lib/author_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -136,4 +136,21 @@ def author_file_path(slug)
end
end
end

describe "link_tag" do
before(:each) { Author.files_dir = files_dir }
let(:config) { {"baseurl" => "spec/support"} }
let(:post_authors) { ["19G"] }
let(:link_tag) {
author.link_tag(list: post_authors, config: config)
}

context "with special 18F case (upper-case F)" do
let(:author) { Author.find_by(slug: "19G") }
it "produces a downcased path in the tag" do
expect(link_tag).to match(/author\/19g/)
expect(link_tag).to_not match(/author\/19G/)
end
end
end
end

0 comments on commit f65b552

Please sign in to comment.