Skip to content

Commit

Permalink
[feature] Add the jekyll-code-tabs plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
nickhuangcyh committed Feb 13, 2022
1 parent 7e64487 commit 32871af
Show file tree
Hide file tree
Showing 5 changed files with 136 additions and 0 deletions.
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ group :jekyll_plugins do
gem "jekyll-sitemap"
gem "jekyll-feed", "~> 0.12"
gem "jekyll-archives"
gem "jekyll-code-tabs", git: "https://github.com/nickhuang9527/jekyll-code-tabs"
end

# Windows and JRuby does not include zoneinfo files, so bundle the tzinfo-data gem
Expand Down
8 changes: 8 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
GIT
remote: https://github.com/nickhuang9527/jekyll-code-tabs
revision: 79e527ff0aa9b877cb454680ae5b49e0af489a30
specs:
jekyll-code-tabs (1.2.0)
jekyll (>= 3.0, < 5.0)

GEM
remote: https://rubygems.org/
specs:
Expand Down Expand Up @@ -278,6 +285,7 @@ PLATFORMS
DEPENDENCIES
github-pages (~> 219)
jekyll-archives
jekyll-code-tabs!
jekyll-feed (~> 0.12)
jekyll-include-cache
jekyll-sitemap
Expand Down
2 changes: 2 additions & 0 deletions _config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,7 @@ plugins:
- jekyll-gist
- jekyll-feed
- jekyll-include-cache
- jekyll-code-tabs

# mimic GitHub Pages with --safe
whitelist:
Expand All @@ -236,6 +237,7 @@ whitelist:
- jekyll-gist
- jekyll-feed
- jekyll-include-cache
- jekyll-code-tabs

# Archives
# Type
Expand Down
63 changes: 63 additions & 0 deletions _includes/head.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
<meta charset="utf-8" />

{% include seo.html %} {% unless site.atom_feed.hide %}
<link
href="{% if site.atom_feed.path %}{{ site.atom_feed.path }}{% else %}{{ '/feed.xml' | relative_url }}{% endif %}"
type="application/atom+xml"
rel="alternate"
title="{{ site.title }} Feed"
/>
{% endunless %}

<!-- https://t.co/dKP3o1e -->
<meta name="viewport" content="width=device-width, initial-scale=1.0" />

<script>
document.documentElement.className =
document.documentElement.className.replace(/\bno-js\b/g, "") + " js ";
</script>

<!-- For all browsers -->
<link rel="stylesheet" href="{{ '/assets/css/main.css' | relative_url }}" />
<link
rel="preload"
href="https://cdn.jsdelivr.net/npm/@fortawesome/fontawesome-free@5/css/all.min.css"
as="style"
onload="this.onload=null;this.rel='stylesheet'"
/>
<noscript
><link
rel="stylesheet"
href="https://cdn.jsdelivr.net/npm/@fortawesome/fontawesome-free@5/css/all.min.css"
/></noscript>

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

<script>
document.addEventListener("DOMContentLoaded", function () {
document.getElementById("default").click();
});

function showTab(evt, tabId) {
// Declare all variables
var i, tabcontent, tablinks;

// Get all elements with class="tabcontent" and hide them
tabcontent = document.getElementsByClassName("tabcontent");
for (i = 0; i < tabcontent.length; i++) {
tabcontent[i].style.display = "none";
}

// Get all elements with class="tablinks" and remove the class "active"
tablinks = document.getElementsByClassName("tablinks");
for (i = 0; i < tablinks.length; i++) {
tablinks[i].className = tablinks[i].className.replace(" active", "");
}

// Show the current tab, and add an "active" class to the button that opened the tab
document.getElementById(tabId).style.display = "block";
evt.currentTarget.className += " active";
}
</script>
62 changes: 62 additions & 0 deletions assets/css/main.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
---
# Only the main Sass file needs front matter (the dashes are enough)
---

@charset "utf-8";

@import "minimal-mistakes/skins/{{ site.minimal_mistakes_skin | default: 'default' }}"; // skin
@import "minimal-mistakes"; // main partials

/* TABS */

/* Style the tab */
.tab {
overflow: hidden;
border: 1px solid #ccc;
background-color: #f1f1f1;
}

/* Style the buttons that are used to open the tab content */
.tab button {
background-color: inherit;
float: left;
border: none;
outline: none;
cursor: pointer;
padding: 14px 16px;
transition: 0.3s;
}

/* Change background color of buttons on hover */
.tab button:hover {
background-color: #ddd;
}

/* Create an active/current tablink class */
.tab button.active {
background-color: #ccc;
}

/* Style the tab content */
.tabcontent {
display: none;
padding: 6px 12px;
border: 1px solid #ccc;
border-top: none;
}

.tabcontent {
animation: fadeEffect 0.5s; /* Fading effect takes 1 second */
}

/* Go from zero to full opacity */
@keyframes fadeEffect {
from {
opacity: 0.5;
}
to {
opacity: 1;
}
}

/* END TABS */

0 comments on commit 32871af

Please sign in to comment.