Skip to content

Commit

Permalink
Merge pull request #769 from naher94/development
Browse files Browse the repository at this point in the history
Resources Surprise Me Tag Added
  • Loading branch information
naher94 authored Dec 1, 2024
2 parents bddf113 + eae336d commit 8a988e1
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 2 deletions.
2 changes: 1 addition & 1 deletion _config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ description: > # this means to ignore newlines until "baseurl:"
baseurl: "" # the subpath of your site, e.g. /blog
url: "https://rehanbutt.com" # the base hostname & protocol for your site
version: 8.31.0
version: 8.32.0
version-naming: [Apricot, Blackcurrent, Coconut, Dragonfruit, Elderberry, Fig, Guava, Honeydew]

# Build settings
Expand Down
4 changes: 4 additions & 0 deletions _includes/foot.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@
<script src="/js/easter-egg-achievements.js" type="text/javascript"></script>
{% endif %}

{% if page.url == '/resources' %}
<script src="/js/resources.js" type="text/javascript"></script>
{% endif %}

<!-- Global site tag (gtag.js) - Google Analytics -->
<script async src="https://www.googletagmanager.com/gtag/js?id=G-XQEN9JC89E"></script>
<script>
Expand Down
10 changes: 10 additions & 0 deletions _sass/resources.scss
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,16 @@ h1{
&:hover{
background-color: semantic-color(actionable-pill-hover);
}
&.surprise-me{
i{
margin-inline-end: 0.25em;
}
&:hover{
background-image: linear-gradient(90deg, #00a2e2 0%, #1bad6b 20%, #fec609 40%, #e92687 60%, #6d358d 80%, #00a2e2 100%);
background-size: 200% auto;
animation: rainbow 3s linear infinite;
}
}
}
}
}
Expand Down
34 changes: 34 additions & 0 deletions js/resources.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
let hrefs; // Declare in the outer scope
let randomHref;

document.addEventListener('DOMContentLoaded', () => {
const tagsContainer = document.querySelector('.tags-container');

// Populate hrefs when the page loads
if (tagsContainer) {
const links = tagsContainer.querySelectorAll('a');
hrefs = Array.from(links).map(link => link.href);
}

const linkElement = document.querySelector('.resource-surprise-me-button');

if (linkElement) {
// Define the function to update the link
const updateRandomLink = () => {
const randomIndex = Math.floor(Math.random() * hrefs.length);
randomHref = hrefs[randomIndex];
randomHref = randomHref.split('#')[1] ? `#${randomHref.split('#')[1]}` : '';
linkElement.href = randomHref; // Update the link's href
};

// Run the function once on page load to populate the link
updateRandomLink();

// Listen for click events on the link
linkElement.addEventListener('click', (event) => {
setTimeout(() => {
updateRandomLink(); // Update the link after the delay
}, 1000);
});
}
});
7 changes: 6 additions & 1 deletion resources.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ <h1>Resources</h1>
{%- comment -%}collect all the unique tags from the resources and articles{%- endcomment -%}
{% assign allresources = site.resources | concat: site.articles %}
{% assign alltags = allresources | map: "tags" | uniq | sort %}

<section class="cell tag-section">
<h2 class="visually-hidden">Categories</h2>
<div class="tags-container cell">
Expand All @@ -24,6 +23,12 @@ <h2 class="visually-hidden">Categories</h2>
</div>
</a>
{% endfor %}
<a href="#" class="resource-surprise-me-button">
<div class="tag surprise-me">
<i class="fa-solid fa-wand-magic-sparkles"></i>
surprise me
</div>
</a>
</div>
</section>

Expand Down

0 comments on commit 8a988e1

Please sign in to comment.