-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpatch_brag.rb
More file actions
133 lines (116 loc) · 3.81 KB
/
patch_brag.rb
File metadata and controls
133 lines (116 loc) · 3.81 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
require 'fileutils'
content = File.read("brag.md")
# Ensure CSS is added to <style>
css = <<~CSS
.brag-filters {
background: var(--glass-bg);
border: 1px solid var(--glass-border);
padding: 0.8rem 1.2rem;
border-radius: 8px;
display: flex;
gap: 1rem;
align-items: center;
margin-bottom: 2rem;
flex-wrap: wrap;
}
.filter-btn {
background: transparent;
color: var(--color-dimmed);
border: 1px solid var(--color-dimmed);
padding: 0.4rem 1rem;
border-radius: 20px;
cursor: pointer;
transition: all var(--motion-fast);
font-weight: 600;
font-size: 0.9rem;
}
.filter-btn.active, .filter-btn:hover {
background: var(--color-primary);
color: var(--color-dark);
border-color: var(--color-primary);
}
.project-card {
transition: opacity 300ms ease, filter 300ms ease;
}
.filtered-out {
opacity: 0.15;
filter: grayscale(100%);
pointer-events: none;
}
.year-separator {
width: 100%;
font-size: 2rem;
color: var(--color-primary);
font-weight: 900;
margin: 3rem 0 1.5rem 0;
padding-left: 1rem;
border-left: 4px solid var(--color-primary);
opacity: 0.8;
}
CSS
content.sub!("</style>", css + "</style>")
# Add filter buttons above <main> or inside
filters_html = <<~HTML
<!-- FILTRES D'IMPACT -->
<div class="brag-filters">
<span style="color: var(--color-foreground)"><i class="fa-solid fa-filter"></i> Filtrer par niveau d'impact :</span>
<button class="filter-btn active" data-filter="all">Tous</button>
<button class="filter-btn" data-filter="principal">Principal</button>
<button class="filter-btn" data-filter="staff">Staff</button>
</div>
HTML
content.sub!("<main>", "<main>\n\n" + filters_html)
# Add year separators and data attr to projects
projects_loop = <<~LIQUID
{% assign projects_sorted = site.data.brag.projects | sort: "sort_key" | reverse %}
{% assign current_year = '' %}
{% for project in projects_sorted %}
{% assign project_year = project.sort_key | divided_by: 10000 %}
{% if project_year != current_year %}
<h3 class="year-separator">{{ project_year }}</h3>
{% assign current_year = project_year %}
{% endif %}
<div class="project-card" data-impact-text="{{ project.impact.text | downcase | escape }}">
LIQUID
content.sub!(/\{% assign projects_sorted = .*?reverse %\}\\n\{% for project in projects_sorted %\}\\n<div class="project-card">/, projects_loop)
# Add year separators and data attr to opensource
opensource_loop = <<~LIQUID
{% assign opensource_sorted = site.data.brag.opensource | sort: "sort_key" | reverse %}
{% assign current_year = '' %}
{% for item in opensource_sorted %}
{% assign item_year = item.sort_key | divided_by: 10000 %}
{% if item_year != current_year %}
<h3 class="year-separator">{{ item_year }}</h3>
{% assign current_year = item_year %}
{% endif %}
<div class="project-card" data-impact-text="{{ item.impact.text | downcase | escape }}">
LIQUID
content.sub!(/\{% assign opensource_sorted = .*?reverse %\}\\n\{% for item in opensource_sorted %\}\\n<div class="project-card">/, opensource_loop)
# Append JavaScript at the end of the file
scripts = <<~JS
<script>
document.addEventListener("DOMContentLoaded", () => {
const buttons = document.querySelectorAll(".filter-btn");
const cards = document.querySelectorAll(".project-card");
buttons.forEach(btn => {
btn.addEventListener("click", () => {
buttons.forEach(b => b.classList.remove("active"));
btn.classList.add("active");
const filter = btn.dataset.filter;
cards.forEach(card => {
const impactText = card.dataset.impactText || "";
if (filter === "all") {
card.classList.remove("filtered-out");
} else if (impactText.includes(filter)) {
card.classList.remove("filtered-out");
} else {
card.classList.add("filtered-out");
}
});
});
});
});
</script>
JS
content += scripts
File.write("brag.md", content)