Skip to content

Commit

Permalink
Add skin_manager plugins
Browse files Browse the repository at this point in the history
  • Loading branch information
attajak committed Dec 16, 2024
1 parent 971aac9 commit 48cffab
Show file tree
Hide file tree
Showing 4 changed files with 93 additions and 1 deletion.
2 changes: 1 addition & 1 deletion _includes/footer/custom.html
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
<!-- start custom footer snippets -->

<!-- end custom footer snippets -->
<!-- end custom footer snippets -->
55 changes: 55 additions & 0 deletions _includes/scripts.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
{% if site.footer_scripts %}
{% for script in site.footer_scripts %}
<script src="{{ script | relative_url }}"></script>
{% endfor %}
{% else %}
<script src="{{ '/assets/js/main.min.js' | relative_url }}"></script>
{% endif %}

{% if site.search == true or page.layout == "search" %}
{%- assign search_provider = site.search_provider | default: "lunr" -%}
{%- case search_provider -%}
{%- when "lunr" -%}
{% include_cached search/lunr-search-scripts.html %}
{%- when "google" -%}
{% include_cached search/google-search-scripts.html %}
{%- when "algolia" -%}
{% include_cached search/algolia-search-scripts.html %}
{%- endcase -%}
{% endif %}

{% include analytics.html %}
{% include /comments-providers/scripts.html %}

{% if site.after_footer_scripts %}
{% for script in site.after_footer_scripts %}
<script src="{{ script | relative_url }}"></script>
{% endfor %}
{% endif %}

<div class="sub-footer">
<div id="skin-switch-container">
Page rendered with the <select id="skin-switch" onchange="changeSkin()">
{%- for skin in page.available_skins %}
{% if skin == 'default' -%}
<option value="_default.css">default</option>
{%- else -%}
<option value="{{ skin }}.css">{{ skin }}</option>
{%- endif %}
{%- endfor %}
</select> skin of Minimal-Mistakes theme.
</div>
</div>

<script>
document.getElementById("skin-switch-container").style.display = "block";
var metaTag = document.getElementById("stylesheet");
var SSHref = metaTag.href;
var SSName = (SSHref.substring(SSHref.lastIndexOf('/') + 1));

document.getElementById("skin-switch").value = SSName;

function changeSkin() {
metaTag.href = SSHref.replace(SSName, event.target.value);
}
</script>
37 changes: 37 additions & 0 deletions _plugins/skin_manager.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# frozen_string_literal: true

module SkinManager
class << self
attr_accessor :available_skins
end

Jekyll::Hooks.register :site, :post_read do |site|
skins_dir = site.in_theme_dir("_sass", "minimal-mistakes", "skins")
SkinManager.available_skins = Dir["#{skins_dir}/*.scss"].map { |i| File.basename(i, ".scss") }
end

Jekyll::Hooks.register [:pages, :documents], :pre_render do |doc, payload|
payload["page"]["available_skins"] = SkinManager.available_skins
end

class SkinPage < Jekyll::PageWithoutAFile
def initialize(site, skin_name)
super(site, site.source, "assets/css", "#{skin_name}.scss")
end
end

class StyleSheetGenerator < Jekyll::Generator
def generate(site)
SkinManager.available_skins.each do |skin_name|
site.pages << SkinPage.new(site, skin_name).tap do |page|
page.data["skin_name"] = skin_name
page.content = <<~SCSS
@import
"minimal-mistakes/skins/{{ page.skin_name }}",
"minimal-mistakes";
SCSS
end
end
end
end
end
Binary file added assets/images/attajak.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 48cffab

Please sign in to comment.