Skip to content

Commit 382725a

Browse files
authored
Feat improve mobile ux (#99)
* [feat] better mobile exp + better table of contents * [chore] hidding manual tocs * [chore] updating makefile
1 parent d0469dc commit 382725a

File tree

62 files changed

+396
-147
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

62 files changed

+396
-147
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ build-img:
1010

1111
# build js
1212
build-js:
13-
node gulp_js.js
13+
node build_js.js --no-serve
1414

1515
# the whole kit and kabootle
1616
jekyll:

_includes/toc.html

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{% if page.toc != false %}
2+
<aside class="toc" aria-label="Table of Contents">
3+
<button class="toc__toggle" type="button" aria-expanded="false" aria-controls="toc-content">
4+
<svg class="toc__icon" width="16" height="16" viewBox="0 0 16 16" fill="currentColor">
5+
<path d="M2 4h12v1H2V4zm0 3.5h12v1H2v-1zm0 3.5h8v1H2V11z"/>
6+
</svg>
7+
<span class="toc__title">Contents</span>
8+
<svg class="toc__chevron" width="12" height="12" viewBox="0 0 12 12" fill="none" stroke="currentColor" stroke-width="2">
9+
<path d="M2 4l4 4 4-4"/>
10+
</svg>
11+
</button>
12+
<nav id="toc-content" class="toc__nav"></nav>
13+
</aside>
14+
{% endif %}

_js/scripts.js

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ $(document).ready(function () {
2323
initPinnedCarousel();
2424
initContactHub();
2525
initSearch();
26+
initTableOfContents();
2627

2728
// Initialize Python runners if present
2829
if ($(".interactive-python").length > 0) {
@@ -940,6 +941,98 @@ function initScrollIndicator() {
940941
});
941942
}
942943

944+
/*-------------------------------------------------------------------------*/
945+
/* TABLE OF CONTENTS */
946+
/* -----------------------------------------------------------------------*/
947+
948+
function initTableOfContents() {
949+
var $toc = $('.toc');
950+
if ($toc.length === 0) return;
951+
952+
var $toggle = $toc.find('.toc__toggle');
953+
var $nav = $toc.find('.toc__nav');
954+
955+
// Generate TOC from headers (h1, h2, h3, h4) - skip "Table of Contents" header
956+
var $headers = $('.post-content').find('h1, h2, h3, h4').filter(function() {
957+
var text = $(this).text().trim();
958+
// For comparison, strip emojis/special chars but check original text isn't empty
959+
var textForComparison = text.toLowerCase().replace(/[^\w\s]/g, '').trim();
960+
return textForComparison !== 'table of contents' && text.length > 0;
961+
});
962+
963+
if ($headers.length === 0) {
964+
$toc.hide();
965+
return;
966+
}
967+
968+
var $list = $('<ul class="toc__list"></ul>');
969+
$headers.each(function () {
970+
var $h = $(this);
971+
// Get the full text content including emojis
972+
var text = $h.text().trim();
973+
var level = this.tagName.toLowerCase();
974+
var id = $h.attr('id');
975+
if (!id) {
976+
// Generate ID from text, removing emojis and special chars for valid ID
977+
id = 'toc-' + text.toLowerCase()
978+
.replace(/[\u{1F300}-\u{1FAF8}]/gu, '') // Remove emojis from ID
979+
.replace(/[^\w\s-]/g, '')
980+
.trim()
981+
.replace(/\s+/g, '-')
982+
.substring(0, 50);
983+
$h.attr('id', id);
984+
}
985+
986+
var $item = $('<li class="toc__item toc__item--' + level + '"></li>');
987+
var $link = $('<a class="toc__link" href="#' + id + '"></a>');
988+
$link.text(text); // Preserves emojis
989+
$item.append($link);
990+
$list.append($item);
991+
});
992+
$nav.append($list);
993+
994+
// Toggle functionality - starts collapsed on all devices
995+
$toggle.on('click', function () {
996+
var expanded = $(this).attr('aria-expanded') === 'true';
997+
$(this).attr('aria-expanded', !expanded);
998+
$nav.toggleClass('is-open');
999+
});
1000+
1001+
// Scroll spy
1002+
var $links = $toc.find('.toc__link');
1003+
var scrollTimer;
1004+
$(window).on('scroll.toc', function () {
1005+
clearTimeout(scrollTimer);
1006+
scrollTimer = setTimeout(function () {
1007+
var scrollPos = $(window).scrollTop() + 100;
1008+
var activeId = null;
1009+
$headers.each(function () {
1010+
if (scrollPos >= $(this).offset().top) {
1011+
activeId = $(this).attr('id');
1012+
}
1013+
});
1014+
$links.removeClass('is-active');
1015+
if (activeId) {
1016+
$links.filter('[href="#' + activeId + '"]').addClass('is-active');
1017+
}
1018+
}, 50);
1019+
});
1020+
1021+
// Smooth scroll on click
1022+
$links.on('click', function (e) {
1023+
e.preventDefault();
1024+
var $target = $($(this).attr('href'));
1025+
if ($target.length) {
1026+
$('html, body').animate({ scrollTop: $target.offset().top - 80 }, 400);
1027+
// Close on mobile after click
1028+
if ($(window).width() < 992) {
1029+
$toggle.attr('aria-expanded', 'false');
1030+
$nav.removeClass('is-open');
1031+
}
1032+
}
1033+
});
1034+
}
1035+
9431036
/*-------------------------------------------------------------------------*/
9441037
/* CODE TOGGLE FUNCTIONALITY */
9451038
/* -----------------------------------------------------------------------*/

_layouts/post.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ <h1 class="hero__title">{{ page.title }}</h1>
6464
<main class="site__content">
6565
<div class="container">
6666
<article class="post-content" itemprop="articleBody" data-pagefind-body>
67+
{% include toc.html %}
6768
{% if page.encrypted %}
6869
<body>
6970
<div class="protected">

_posts/2022-03-27-porvata-spar.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ As an aside, and this is more biased obviously, but I've seen how hard both Nick
2525

2626
So let's dive in.
2727

28+
<!--
2829
# Table of Contents
2930
3031
- [Background](#background)
@@ -54,6 +55,7 @@ So let's dive in.
5455
- [Logging](#logging)
5556
- [Linting and GitHooks](#linting-and-githooks)
5657
- [Conclusion](#conclusion)
58+
-->
5759

5860
# Introduction
5961

_posts/2022-06-05-message-parser.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ However, a pretty simple workaround is utilizing the sqlite3 database that's pop
1717

1818
<span style="color:blue">Note, if you're just interested in code, you can skip all this and check out <a href="https://github.com/johnlarkin1/imessage-cli">this repo</a>.</span>
1919

20+
<!--
2021
# Table of Contents
2122
2223
- [Background](#background)
@@ -46,6 +47,7 @@ However, a pretty simple workaround is utilizing the sqlite3 database that's pop
4647
- [Total Number of Distinct Convos](#total-number-of-distinct-convos)
4748
- [Examples](#examples-4)
4849
- [Conclusion](#conclusion)
50+
-->
4951

5052
# Introduction
5153

_posts/2023-03-03-chrome-betting-kelly.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ favorite: true
1010

1111
Much to the knowledge of my friends (and to the chagrin of my mother), I do fancy a good tennis bet every now and then. And this blog is going to unpack some of that.
1212

13+
<!--
1314
# Table of Contents
1415
1516
First, a quick overview of what we'll be covering.
@@ -35,6 +36,7 @@ First, a quick overview of what we'll be covering.
3536
- [An Example](#an-example)
3637
- [Analysis Results](#analysis-results)
3738
- [Conclusion](#conclusion)
39+
-->
3840

3941
# Introduction
4042

_posts/2024-02-20-into-the-arena.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ favorite: true
99
pinned: 6
1010
---
1111

12+
<!--
1213
# Table of Contents
1314
1415
- [Table of Contents](#table-of-contents)
@@ -52,6 +53,7 @@ pinned: 6
5253
- [Deeper Understanding and New Technical Skills](#deeper-understanding-and-new-technical-skills)
5354
- [Next Steps 🪜](#next-steps-)
5455
- [Dendrogram Visualization](#dendrogram-visualization)
56+
-->
5557

5658
# Motivation
5759

_posts/2024-11-19-book-brain.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ summary: Automating book reports. An exploration into chunking, qdrant, and embe
77
favorite: true
88
---
99

10+
<!--
1011
# Table of Contents
1112
1213
- [Table of Contents](#table-of-contents)
@@ -40,6 +41,7 @@ favorite: true
4041
- [Outside of the LLMs themselves, what other tools should you use in this process? Vector DBs, indexers, RAG tooling, etc?](#outside-of-the-llms-themselves-what-other-tools-should-you-use-in-this-process-vector-dbs-indexers-rag-tooling-etc)
4142
- [Conclusion](#conclusion)
4243
- [Next Steps](#next-steps)
44+
-->
4345

4446
# Motivation
4547

_posts/2024-12-31-advent-of-code.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ categories: [Advent of Code, Dev]
88
summary: Slogging through Advent of Code 2024
99
---
1010

11+
<!--
1112
# Table of Contents
1213
1314
- [Table of Contents](#table-of-contents)
@@ -32,6 +33,7 @@ summary: Slogging through Advent of Code 2024
3233
- [Code](#code)
3334
- [Solutions](#solutions)
3435
- [Closing Thoughts](#closing-thoughts)
36+
-->
3537

3638
# Introduction
3739

0 commit comments

Comments
 (0)