Skip to content

Commit d56c718

Browse files
committed
Add alternating grayscale sections for markdown breaks in posts
1 parent e5c39b5 commit d56c718

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed

_layouts/post.html

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,21 @@
6767
.prose td:last-child {
6868
padding-right: 1.5rem;
6969
}
70+
71+
/* Alternating sections for markdown --- breaks */
72+
.alternating-section:nth-child(odd) {
73+
background-color: var(--bg-secondary);
74+
padding: 1rem;
75+
margin: 1rem 0;
76+
border-radius: var(--border-radius);
77+
}
78+
79+
.alternating-section:nth-child(even) {
80+
background-color: var(--bg-tertiary);
81+
padding: 1rem;
82+
margin: 1rem 0;
83+
border-radius: var(--border-radius);
84+
}
7085
</style>
7186

7287
<div class="container mx-auto px-4 py-8 max-w-4xl">
@@ -113,6 +128,31 @@ <h3 class="text-lg font-semibold text-gray-900 mb-4">Tags</h3>
113128
{% endif %}
114129
</article>
115130

131+
<script>
132+
document.addEventListener('DOMContentLoaded', function() {
133+
const contentDiv = document.querySelector('.prose.prose-lg.max-w-none');
134+
if (!contentDiv) return;
135+
136+
const html = contentDiv.innerHTML;
137+
// Split by hr tags, keeping the hr
138+
const parts = html.split(/(<hr[^>]*>)/);
139+
let newHtml = '<section class="alternating-section">';
140+
let inSection = true;
141+
142+
for (let part of parts) {
143+
if (part.match(/<hr[^>]*>/)) {
144+
// Close current section and start new one
145+
newHtml += '</section><section class="alternating-section">';
146+
} else {
147+
newHtml += part;
148+
}
149+
}
150+
newHtml += '</section>';
151+
152+
contentDiv.innerHTML = newHtml;
153+
});
154+
</script>
155+
116156
<!-- Navigation -->
117157
<div class="mt-12 pt-8 border-t border-gray-200">
118158
<div class="flex justify-between items-center">

0 commit comments

Comments
 (0)