The original theme uses a single-column layout for archive pages on large screens, resulting in excessive blank space and making it hard to browse articles. Changing to a two-column layout makes better use of screen real estate on large displays.
Create the file ~\assets\scss\custom.scss and add the following content:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
/* Two-column layout for archives page */@media(min-width:1024px){.article-list--compact{display:grid;grid-template-columns:1fr1fr;background:none;box-shadow:none;gap:1rem;article{background:var(--card-background);border:none;box-shadow:var(--shadow-l2);margin-bottom:8px;border-radius:16px;}}}
Code Blocks
Custom Height for Code Blocks with Global Scrollbar
By default, code blocks display as many lines as there are in the code, making articles with long code blocks difficult to browse in a browser. Also, you can’t simply adjust the height, otherwise the line numbers on the left and the code on the right will each have their own scrollbars. After much research, here’s the solution:
Create a new file at ~\assets\scss\custom.scss and add the following at the end of the file:
//=============================//CodeBlocks//=============================/* Custom variable, modify the height here as needed */$codeblock-max-height:25em;/* ① Set the outermost .highlight as the “only” scrollable container */.highlight{max-height:$codeblock-max-height;overflow:auto;/* Controls both X and Y directions */-webkit-overflow-scrolling:touch;/* Inertia scrolling on mobile */}/* ② Disable internal pre/code scrollbars (to avoid double scrollbars) */.highlightpre,.highlightcode,.highlight.chroma{overflow:visible!important;/* Override Stack’s overflow-x:auto on pre */}/* ③ Make the line number table auto-expand with content width to enable X scroll on wide blocks */.lntable{display:inline-table;/* Keeps table property, allows content-dependent width */min-width:max-content;border-spacing:0;}/* ④ Disable auto-wrapping, long lines are handled by horizontal scrolling */.lntd:last-childcode,.highlightcode{white-space:pre;/* No line breaks */}.lntd:first-child{user-select:none;//Preventselectinglinenumbers}
Reduce Code Block Font Size
The default font size looks too large on mobile UA 😨 — a smaller size looks better 😋
Add the following at the end of your ~\assets\scss\custom.scss file:
1
2
3
4
5
6
7
8
9
10
/* Left column (line numbers) */.chroma.lntd,.chroma.lntdpre,.chroma.ln{font-size:14px;font-family:var(--code-font-family);}/* Right column (code) */.chromacode,.chromapre{font-size:14px;font-family:var(--code-font-family);}
MacOS-style Code Blocks
Find the .highlight section in ~/themes/hugo-theme-stack/assets/scss/partials/layout/article.scss and modify it as follows:
They used the Lato font, which doesn’t support Chinese. As a result, it defaults to Microsoft YaHei (which is set as the fallback). There are several ways to change the font:
Use web fonts;
Download the CSS for the font and import it;
Use default system fonts (like Microsoft YaHei, FangSong, KaiTi, etc.).
I chose to use a web font because there is a wider selection and the CSS can be hard to find otherwise…
Use a VPN to visit Google Fonts and find a font you like.
Click Get font
Select the font(s) you want and then click Get embeded code.
Modify properties like Weight on the left, then click Copy Code on the right.
Create ~\layouts\partials\head\custom.html, and paste the code you just copied. Font import is done.
<!-- Add back to top button --><script>functionbackToTop(){document.documentElement.scrollIntoView({behavior:'smooth',})}window.onload=function(){letscrollTop=this.document.documentElement.scrollTop||this.document.body.scrollToplettotopBtn=this.document.getElementById('back-to-top')if(scrollTop>0){totopBtn.style.display='inline'}else{totopBtn.style.display='none'}}window.onscroll=function(){letscrollTop=this.document.documentElement.scrollTop||this.document.body.scrollToplettotopBtn=this.document.getElementById('back-to-top')if(scrollTop<200){totopBtn.style.display='none'}else{totopBtn.style.display='inline'totopBtn.addEventListener('click',backToTop,false)}}</script>
In ~/layouts/partials/footer/custom.html, add the following code. The button color (background-color and border-color) has been tweaked to match the theme.
<!-- Add back to top button --><ahref="#"id="back-to-top"title="Back to top"></a><!-- Back to top button CSS --><style>#back-to-top{display:none;position:fixed;bottom:5px;right:15px;width:40px;/* Reduced size */height:40px;/* Reduced size */border-radius:50%;/* Circular button for modern look */background-color:var(--body-background);box-shadow:var(--shadow-l2);font-size:20px;/* Adjusted for smaller button */text-align:center;line-height:38px;/* Center align arrow */cursor:pointer;transition:transform0.3sease,background-color0.3sease;/* Added smooth interaction */}#back-to-top:before{content:"";display:inline-block;position:relative;transform:rotate(135deg);height:8px;/* Reduced size */width:8px;/* Reduced size */border-width:002px2px;border-color:var(--back-to-top-color);border-style:solid;}#back-to-top:hover{transform:scale(1.1);/* Slightly larger on hover */background-color:var(--accent-background);/* Optional hover effect */}#back-to-top:hover:before{border-color:var(--accent-color);/* Change arrow color on hover */}/* Responsive styles */@mediascreenand(max-width:768px){#back-to-top{bottom:5px;right:var(--container-padding);width:30px;/* Slightly smaller for mobile */height:30px;font-size:16px;line-height:32px;}}@mediascreenand(min-width:1024px){#back-to-top{bottom:10px;right:20px;}}@mediascreenand(min-width:1280px){#back-to-top{bottom:15px;right:25px;}}@mediascreenand(min-width:1536px){#back-to-top{bottom:15px;right:25px;/* visibility: hidden; */}}</style>
Add Colored Stripes and Item Counts to Home Page Category Cards
Preview:
First, you need to define the background color for each category in its respective _index.md file. We’ll use this later. For nice color palettes, I usually get inspiration from Color Hunt
and fine-tune as needed with Color Hex
.
Format example:
Finally, in ~/themes/hugo-theme-stack/layouts/partials/widget/categories.html, replace the Section content with the following. I’ve added {{ .Count }} to show the number of items in each category.
Since the background colors I set are relatively grayish, but I want the stripe to be more vibrant, I added filter:saturate(1.7); to bump up the color saturation. You can remove it if you don’t need it.
Homepage Welcome Banner
Effect:
Add the following code before <section class="article-list"> in ~/themes/hugo-theme-stack/layouts/index.html: