Skip to content

Commit afdae01

Browse files
committed
feat: add mobile word wrap functionality and improve image responsiveness
1 parent ec792c7 commit afdae01

File tree

3 files changed

+122
-15
lines changed

3 files changed

+122
-15
lines changed

docusaurus.config.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,11 @@ const config = {
2828
onBrokenLinks: "throw",
2929
onBrokenMarkdownLinks: "warn",
3030

31+
// Client modules - scripts that run on the client side
32+
clientModules: [
33+
require.resolve('./src/js/mobileWordWrap.js'),
34+
],
35+
3136
// Even if you don't use internationalization, you can use this field to set
3237
// useful metadata like html lang. For example, if your site is Chinese, you
3338
// may want to replace "en" with "zh-Hans".

src/css/custom.css

Lines changed: 34 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -144,23 +144,12 @@ html[data-theme='dark'] .docusaurus-highlight-code-line {
144144

145145
/* Image Responsiveness */
146146
@media (max-width: 996px) {
147-
/* Make all images responsive */
148-
img {
149-
max-width: 100%;
150-
height: auto;
151-
display: block;
152-
}
153-
154-
/* Ensure markdown images are responsive */
155-
.markdown img {
156-
max-width: 100%;
157-
height: auto;
158-
}
159-
160-
/* Handle images in content */
147+
/* Make content images responsive */
148+
.markdown img,
161149
.theme-doc-markdown img {
162150
max-width: 100%;
163151
height: auto;
152+
display: block;
164153
}
165154

166155
/* Responsive image containers */
@@ -171,6 +160,16 @@ html[data-theme='dark'] .docusaurus-highlight-code-line {
171160
}
172161
}
173162

163+
/* Footer logo sizing on mobile – prevent oversized logo */
164+
@media (max-width: 996px) {
165+
.footer .footer__logo img,
166+
.footer .footer__logo {
167+
max-width: 72px;
168+
width: 72px;
169+
height: auto;
170+
}
171+
}
172+
174173
/* Navigation Menu Improvements for Mobile */
175174
@media (max-width: 996px) {
176175
/* Improve mobile menu button visibility */
@@ -199,6 +198,27 @@ html[data-theme='dark'] .docusaurus-highlight-code-line {
199198
}
200199
}
201200

201+
/* Pagination (Prev/Next) – prevent cut off on mobile */
202+
@media (max-width: 996px) {
203+
/* Add small horizontal padding to the whole block to keep cards inside viewport */
204+
.pagination-nav {
205+
padding-left: 0.75rem;
206+
padding-right: 0.75rem;
207+
}
208+
209+
/* Remove extra margins that cause overflow when each item is 50% width */
210+
.pagination-nav__link {
211+
margin: 0;
212+
}
213+
214+
/* Ensure box sizing doesn't overflow and keep a tiny gap */
215+
.pagination-nav__item {
216+
box-sizing: border-box;
217+
padding-left: 0.25rem;
218+
padding-right: 0.25rem;
219+
}
220+
}
221+
202222
/* Table Responsiveness */
203223
@media (max-width: 996px) {
204224
/* Make tables scrollable horizontally on mobile */
@@ -271,7 +291,6 @@ html[data-theme='dark'] .docusaurus-highlight-code-line {
271291
a.button {
272292
min-height: 40px;
273293
min-width: 40px;
274-
padding: 0.75rem 1.25rem;
275294
}
276295

277296
/* Add flex display to clean-btn for better layout */

src/js/mobileWordWrap.js

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
/**
2+
* Automatically enable word wrap in code blocks on mobile devices
3+
* This script clicks the word wrap button when the page loads on mobile screens
4+
*/
5+
6+
function enableWordWrapOnMobile() {
7+
// Check if we're on a mobile device (screen width <= 996px)
8+
if (window.innerWidth <= 996) {
9+
// Wait for the DOM to be fully loaded and code blocks to render
10+
setTimeout(() => {
11+
// Find all word wrap buttons
12+
// The button has class 'clean-btn' and when enabled also has 'wordWrapButtonEnabled_*'
13+
const wordWrapButtons = document.querySelectorAll('.clean-btn[aria-label*="word wrap"], .clean-btn[aria-label*="Word wrap"], .clean-btn[title*="word wrap"], .clean-btn[title*="Word wrap"]');
14+
15+
wordWrapButtons.forEach(button => {
16+
// Check if the button is NOT already enabled
17+
// When enabled, it has a class containing 'wordWrapButtonEnabled'
18+
const isEnabled = Array.from(button.classList).some(className =>
19+
className.includes('wordWrapButtonEnabled')
20+
);
21+
22+
if (!isEnabled) {
23+
// Click the button to enable word wrap
24+
button.click();
25+
}
26+
});
27+
}, 500); // Wait 500ms for code blocks to render
28+
}
29+
}
30+
31+
// Run on initial page load
32+
if (typeof window !== 'undefined') {
33+
// Execute when DOM is ready
34+
if (document.readyState === 'loading') {
35+
document.addEventListener('DOMContentLoaded', enableWordWrapOnMobile);
36+
} else {
37+
enableWordWrapOnMobile();
38+
}
39+
40+
// Also run when navigating between pages (Docusaurus uses client-side routing)
41+
window.addEventListener('popstate', enableWordWrapOnMobile);
42+
43+
// Listen for route changes in Docusaurus
44+
if (window.docusaurus) {
45+
window.docusaurus.prefetch = function() {
46+
// Hook into Docusaurus navigation
47+
enableWordWrapOnMobile();
48+
};
49+
}
50+
51+
// Use MutationObserver to detect when new code blocks are added to the page
52+
const observer = new MutationObserver((mutations) => {
53+
let shouldCheck = false;
54+
55+
mutations.forEach((mutation) => {
56+
if (mutation.addedNodes.length > 0) {
57+
mutation.addedNodes.forEach((node) => {
58+
// Check if a code block or button was added
59+
if (node.nodeType === 1) { // Element node
60+
if (node.matches && (
61+
node.matches('.theme-code-block') ||
62+
node.matches('.clean-btn') ||
63+
node.querySelector('.theme-code-block') ||
64+
node.querySelector('.clean-btn')
65+
)) {
66+
shouldCheck = true;
67+
}
68+
}
69+
});
70+
}
71+
});
72+
73+
if (shouldCheck) {
74+
enableWordWrapOnMobile();
75+
}
76+
});
77+
78+
// Start observing the document body for changes
79+
observer.observe(document.body, {
80+
childList: true,
81+
subtree: true
82+
});
83+
}

0 commit comments

Comments
 (0)