Repository navigation
Darkmode assets #38
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Darkmode assets #38
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
fe95a9b
Update graphics
cb341 9778eea
Theming for base
cb341 5f53653
Inline svg
cb341 f3c9a1d
css fixes
cb341 6f64719
webp->svg
cb341 4ac0e3f
Add image captions
cb341 e1cbf9d
Svg themes
cb341 fe87bae
Flip
cb341 5f375c8
Simplify svg handling
cb341 40f2561
Stuff
cb341 366f55e
SVG
cb341 ae26da6
Fix
cb341 bc4c632
I
cb341 141a7a6
EE
cb341 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,79 @@ | ||
| require "cgi" | ||
|
|
||
| module InlineSvg | ||
| LOCAL_SVG_IMAGE = /<img\b(?<attributes>[^>]*\bsrc=(?<quote>["'])(?<src>[^"']+\.svg(?:[?#][^"']*)?)\k<quote>[^>]*)\/?\s*>/i | ||
|
|
||
| module_function | ||
|
|
||
| def apply(document) | ||
| return unless document.output | ||
|
|
||
| document.output = document.output.gsub(LOCAL_SVG_IMAGE) do |image| | ||
| source = Regexp.last_match[:src] | ||
| image_attributes = Regexp.last_match[:attributes] | ||
| path = local_svg_path(document.site, source) | ||
| next image unless path && File.file?(path) | ||
|
|
||
| inline(File.read(path), image_attributes) || image | ||
| end | ||
| end | ||
|
|
||
| def local_svg_path(site, source) | ||
| path = source.split(/[?#]/, 2).first | ||
| return unless path.start_with?("/") | ||
|
|
||
| candidate = File.expand_path(path.delete_prefix("/"), site.source) | ||
| return unless candidate.start_with?("#{File.expand_path(site.source)}/") | ||
|
|
||
| candidate | ||
| end | ||
|
|
||
| def inline(svg, image_attributes) | ||
| alt = image_attributes[/\balt=(['"])(.*?)\1/i, 2] | ||
| svg.sub(/\A\s*<svg\b(?<attributes>[^>]*)>/i) do | ||
| attributes = Regexp.last_match[:attributes] | ||
| attributes = add_class(attributes, "inline-svg") | ||
| attributes = add_print_size(attributes) | ||
| attributes = add_accessible_name(attributes, alt) if alt && !alt.empty? | ||
| "<svg#{attributes}>" | ||
| end | ||
| end | ||
|
|
||
| def add_class(attributes, class_name) | ||
| if attributes =~ /\bclass=(['"])(.*?)\1/i | ||
| attributes.sub(/\bclass=(['"])(.*?)\1/i) { %(class="#{$2} #{class_name}") } | ||
| else | ||
| %(#{attributes} class="#{class_name}") | ||
| end | ||
| end | ||
|
|
||
| def add_accessible_name(attributes, alt) | ||
| return attributes if attributes.match?(/\baria-(?:label|labelledby)=/i) | ||
|
|
||
| %(#{attributes} role="img" aria-label="#{CGI.escapeHTML(alt)}") | ||
| end | ||
|
|
||
| def add_print_size(attributes) | ||
| width = attributes[/\bwidth=(['"])([\d.]+)(?:px)?\1/i, 2] | ||
| height = attributes[/\bheight=(['"])([\d.]+)(?:px)?\1/i, 2] | ||
| view_box = attributes.match(/\bviewBox=(['"])[\d.]+\s+[\d.]+\s+([\d.]+)\s+([\d.]+)\1/i) | ||
| width ||= view_box && view_box[2] | ||
| height ||= view_box && view_box[3] | ||
| return attributes unless width && height | ||
|
|
||
| properties = "--inline-svg-print-width: #{width}px; --inline-svg-print-height: #{height}px;" | ||
| if attributes =~ /\bstyle=(['"])(.*?)\1/i | ||
| attributes.sub(/\bstyle=(['"])(.*?)\1/i) { %(style="#{$2}; #{properties}") } | ||
| else | ||
| %(#{attributes} style="#{properties}") | ||
| end | ||
| end | ||
| end | ||
|
|
||
| Jekyll::Hooks.register :documents, :post_render do |document| | ||
| InlineSvg.apply(document) | ||
| end | ||
|
|
||
| Jekyll::Hooks.register :pages, :post_render do |page| | ||
| InlineSvg.apply(page) | ||
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Regenerated from existing webp