Skip to content

Commit

Permalink
Remove the need to enumerate icons in css
Browse files Browse the repository at this point in the history
  • Loading branch information
Earlopain committed Oct 8, 2023
1 parent b0070e7 commit 1e9ccb1
Show file tree
Hide file tree
Showing 57 changed files with 24 additions and 75 deletions.
4 changes: 3 additions & 1 deletion app/helpers/artist_url_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ def site_types_collection
end

def site_icon(artist_url)
icon = tag.span(class: artist_url.site.icon_class)
# NOTE: Would be neat to be able to use attr here but no browser supports this at the moment
icon_index = ArtistUrl.site_types[artist_url.site_type]
icon = tag.span(class: "site-icon", style: "--icon-index: #{icon_index};")
link_to tag.span(icon), gallery_url(artist_url), title: "#{artist_url.site.display_name} - #{artist_url.unescaped_url_identifier}"
end

Expand Down
5 changes: 4 additions & 1 deletion app/logical/icon_generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@ module IconGenerator
ICON_SIZE = 64

def run
files = Dir.glob("#{ICON_FOLDER}/*.png")
files = Dir.glob("#{ICON_FOLDER}/*.png").sort_by do |path|
index, = File.basename(path).split("-")
index.to_i
end

result = Vips::Image.thumbnail(files.first, ICON_SIZE)
result = result.add_alpha unless result.has_alpha?
Expand Down
4 changes: 0 additions & 4 deletions app/logical/sites/simple_definition.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,6 @@ def handles_image_domain?(domain)
image_domains.include? domain
end

def icon_class
"site-icon-#{site_type}"
end

def gallery_url(identifier)
"https://#{gallery_templates.first.expand(site_artist_identifier: identifier)}"
end
Expand Down
79 changes: 10 additions & 69 deletions app/stylesheet/base/mixins.scss
Original file line number Diff line number Diff line change
@@ -1,57 +1,3 @@
$icons: (
"afterdark"
"artconomy"
"artfight"
"artfol"
"artstation"
"baraag"
"bluesky"
"boosty"
"buzzly"
"carrd"
"cohost"
"commishes"
"deviantart"
"discord"
"facebook"
"fanbox"
"furaffinity"
"furrynetwork"
"furrystation"
"gumroad"
"hentai_foundry"
"inkblot"
"inkbunny"
"instagram"
"itaku"
"kofi"
"linktree"
"manual"
"newgrounds"
"patreon"
"pawoo"
"picarto"
"piczel"
"pillowfort"
"pixiv"
"reddit"
"skeb"
"sofurry"
"subscribestar"
"telegram"
"toyhouse"
"trello"
"tumblr"
"twitch"
"twitter"
"vkontakte"
"weasyl"
"ychart"
"youtube_channel"
"youtube_legacy"
"youtube_vanity"
);

@mixin site_icon($icon_size) {
font-size: $icon_size;
white-space: nowrap;
Expand All @@ -60,21 +6,16 @@ $icons: (
padding-left: 0.5rem;
}

// Arrays start at 1!?
@for $i from 0 through length($icons) - 1 {
$icon: nth($icons, $i + 1);

.site-icon-#{$icon} {
vertical-align: middle;
&::before {
content: "";
width: $icon_size;
height: $icon_size;
display: inline-block;
background: url("/icons.png");
background-size: $icon_size;
background-position: 0px calc(-#{$i} * #{$icon_size});
}
.site-icon {
vertical-align: middle;
&::before {
content: "";
width: $icon_size;
height: $icon_size;
display: inline-block;
background: url("/icons.png");
background-size: $icon_size;
background-position: 0px calc(var(--icon-index) * #{$icon_size} * -1);
}
}
}
Binary file modified public/icons.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
7 changes: 7 additions & 0 deletions test/logical/icon_generator_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,11 @@ class IconGeneratorTest < ActiveSupport::TestCase
end
assert(FileUtils.compare_file(target_file, IconGenerator::TARGET_FILE))
end

test "all files are named correctly" do
ArtistUrl.site_types.each do |key, index|
file_name = "#{index}-#{key}.png"
assert_path_exists(IconGenerator::ICON_FOLDER.join(file_name))
end
end
end

0 comments on commit 1e9ccb1

Please sign in to comment.