大装修就像买新房
毛坯房之王——变身!
折腾了一个礼拜装修,昨天终于上传全新外观,弄好之后已经自我欣赏一整天了,还是写一个装修笔记把这件事告一段落。
咱这个 hugo 网站五年来第一次换主题,感觉像换了个新房。新换的主题是 no style please ,这一切的起源都要从看到 小鱼的装修博客,觉得真可爱啊,赛博手账本我也要拥有,而且小鱼提到了这个主题:
是在No Style Please这个主题上修改的,它非常好的一点是,给出了博客所必需的每一个部件,但没有任何冗余的样式或者动画,响应起来非常快。
我心想那感情好,我也来搞一搞。
简要流程是这样:
- 先新建一个hugo网站来测试一下新主题。
- 修理 css 和 shortcode,把需要的功能和样式都加上。
- 我因为好几年没有装修过,hugo 都更新多少版本了,旧的
config.toml
一团乱麻,所以没有把新的主题加入原来的./themes/
,而是等css收拾完了再把原来的./content/
一把子搬到新文件夹里。静态网站的优势就在这里啊!随便搬!不行就炸了原地再重新起一个网站。 - 然后把新网站文件夹传到一个新的 GitHub 仓库。
- 我用的是 vercel 部署 hugo, 所以再从 vercel 上把连接的 git 地址换了,就好了。需要在 vercel 项目的环境变量里设置 HUGO_VERSION 到和本地的 hugo 版本一样,然后设置 output 路径为
./public
我一打开这个 no style please 的主题就发现我这是上了网友的当了!人家叫这个名字,主打的就是一个 no style, 这个作者宣传的自己 css file 只有 3 kb, 那是因为打开一看根本没几行啊!人家 no style, 意思就是我得自己攒个 style 出来啊!
好的,直接复制一遍这个主题文件夹,就重命名叫 mystyleplease,然后开始操作。
亮色背景用上了这个练习册一样的花纹背景,既然打算做手账本,那就把配色都安排成笔记本的样式。我想要一个干干脆脆的好学生笔记本的样子,所以做了蓝黑色的边框、蓝色的超链接、蓝绿色的荧光笔,和我平常用的文具真的差不多,就是黑水笔、蓝水笔、蓝黑墨水和荧光笔。夜间模式本来想做水族馆配色,主打一个白天好好学习,天一黑就狂摸鱼,但是懒得搞了,只用上了霓虹灯,现在就是夜里蹦迪的灯效。
文章字体是霞鹭新晰黑,主页题目字体是 stardos stencil from google fonts,贴纸字体是悠哉。题目字体因为只需要这几个字母,所以可以把整个字体文件削减一下,只要留英文字母就好了,Font Subsetter在线就可以完成转换,裁剪完的字体文件小一些,会让网页加载更快。
这个题目字体也挺有复古气质的,如果再加一个模糊,就会看起来像洇开了的旧蓝黑墨水。但是我不想!我就要干干净净漂漂亮亮一个笔记本!而且这个衬线字体在全网站的非衬线字体里很显眼,用来做题目正好。
这个主题自带了详情展开功能,就是这样:
我要剧透了!
凶手不是我。这好像也是比较新版的 hugo 和 markdown 编辑器(比如说 obsidian )都有的,不错,用上。做一个乖乖的方框用来放这个好了。
在首页做了一个状态更新的小窗口,用来放状态更新。这个功能我之前就想要,也是因为看到别的网友有,是的,别的小朋友有的东西我也要有。这个设计还挺实用的,我也觉得确实需要一个 section 放一些比较简短,不太正式的内容,所以做了。
代码是 chatGPT 写的:
代码详情
<section class="status-list">
<ul>
{{ with .Site.GetPage "section" "status" }}
{{ $sortedPages := sort .Pages "Date" "desc" }}
{{ $pinned := slice }}
{{ $regular := slice }}
{{ range $sortedPages }}
{{ if .Params.pinned }}
{{ $pinned = $pinned | append . }}
{{ else }}
{{ $regular = $regular | append . }}
{{ end }}
{{ end }}
{{ range $pinned | append $regular }}
<li class="sticker">
<div>
<a href="{{ .RelPermalink }}"> {{ if .Params.pinned }}<i class="fa-solid fa-thumbtack"></i> {{ end }} {{ .Title }}</a>
<span class="post-meta">
{{ .Date.Format "2006/01/02" }}
</span>
</div>
<p> {{ .Content }} </p>
</li>
{{ end }}
{{ else }}
<li>No status updates yet.</li>
{{ end }}
</ul>
</section>
// homepage status window
.homepage-status {
width: 80%; /* Adjust the width as needed */
max-width: 800px; /* Maximum width */
min-height: 400px; /* Minimum height for the window */
margin: 30px auto; /* Center the window */
background-color: $--bg-color; /* Light gray background for the window */
border: 3px solid $--primary-text-color; /* Border for the window */
border-radius: 5px; /* Rounded corners */
position: relative; /* Needed for the header positioning */
box-shadow: -4px 4px 0 $--secondary-text-color;
overflow: hidden;
max-height: 580px;
padding: 0;
}
.window-header {
border-bottom: solid 5px $--primary-text-color;
padding: 10px 15px; /* Padding around the header */
display: flex; /* Flexbox to align header contents */
justify-content: space-between; /* Space between title and close button */
align-items: center; /* Vertically center the contents */
}
.close-btn:hover {
color: $--highlight; /* Change color when hovering */
}
/* Content area with scroll */
.homepage-status > .status-content {
max-height: 500px;
@media (max-width: $--mobile-breakpoint) {
max-height: 300px; /* Limit the height of the content area */
}
overflow-y: auto; /* Enable vertical scroll if content overflows */
}
/* Scrollbar Styling */
.homepage-status > .status-content::-webkit-scrollbar {
width: 15px; /* Width of the vertical scrollbar */
}
.homepage-status > .status-content::-webkit-scrollbar-thumb {
background: $--highlight; /* Darker color for the scrollbar thumb */
border-radius: 5px; /* Rounded corners for the thumb */
}
.homepage-status > .status-content::-webkit-scrollbar-track {
border: 3px solid $--secondary-text-color; /* Light background for the scrollbar track */
border-radius: 5px; /* Rounded corners for the track */
}
function closeWindow() {
document.querySelector('.homepage-status').style.display = 'none';
}
但是怎么用这个短状态栏目我还没有想好。既然这是微博类似的,那就应该可以随时随地发,不需要大张旗鼓地打开好几个窗口。既然如此……那好像最方便的就是在命令行里写微博啊?
没有做导航栏,哈哈,一方面header感觉放不下了,另一方面懒得搞了,hugo这个 dictionary 我还不太会写,所以这个状态更新窗口一旦关上了就打不开——真是绝妙的 ui 设计呢!
短 po 和头像在亮色模式做成了贴纸样式。有题图的文章,比如说这个《带全自动胶卷相机去旅游》把题图做成了胶带贴明信片的样子,从 Suzanne Aitchison 这里抄的,怪麻烦的,偶尔用用。
我已经发现了,要从我之前那个毛坯房装修到比较像一个当代网页,最主要就是要多加一些阴影和动画。所以又在贴纸部件上肆意添加了一些 hover 动画,都是很简单的阴影 transition, 写起来不麻烦,加载也挺快。
在 hugo 方面,新写了一个显示 tag 的 partial,按照最近文章用到的 tag 从新到旧排列,然后每个 tag 计数有几篇文章。
代码是这样
<ul>
<li><span>
<i class="fa-solid fa-hashtag"></i>
{{ $tagData := dict }} <!-- Store tag counts and latest update dates -->
<!-- Iterate through all pages to collect tag information -->
{{ range site.RegularPages }}
{{ $pageDate := .Date }} <!-- Get the page's date -->
{{ with .Params.tags }}
{{ range . }}
{{ if not (index $tagData .) }}
{{ $tagData = merge $tagData (dict . (dict "count" 1 "latest" $pageDate)) }}
{{ else }}
{{ $existing := index $tagData . }}
{{ $newCount := add (index $existing "count") 1 }}
{{ $newLatest := cond (gt $pageDate (index $existing "latest")) $pageDate (index $existing "latest") }}
{{ $tagData = merge $tagData (dict . (dict "count" $newCount "latest" $newLatest)) }}
{{ end }}
{{ end }}
{{ end }}
{{ end }}
<!-- Convert dictionary to a slice for sorting -->
{{ $sortedTags := slice }}
{{ range $tag, $info := $tagData }}
{{ $sortedTags = $sortedTags | append (dict "tag" $tag "count" (index $info "count") "latest" (index $info "latest")) }}
{{ end }}
<!-- Sort by latest post date in descending order -->
{{ $sortedTags = sort $sortedTags "latest" "desc" }}
{{ $limit_num := .limit }}
{{ $limit_exceeded := false }}
<!-- Limit the number of displayed tags -->
{{ if and $limit_num (gt (len $sortedTags) $limit_num) }}
{{ $limit_exceeded = true }}
{{ $sortedTags = first $limit_num $sortedTags }}
{{ end }}
<!-- Display the sorted tags -->
{{ range $sortedTags }}
<span class="post-tag">
<a href="/tags/{{ .tag | urlize }}">{{ .tag }}</a> ({{ .count }})/
</span>
{{ end }}
{{ if $limit_exceeded }}
...
</span></li>
<li>
<a href="{{ .show_more_url }}">{{ .show_more_text }}</a>
</li>
{{ end }}
</ul>
加了一个 if 条件来限制展示的 tag 个数,因为我发现我打 tag 太随便了!这都是什么跟什么!搞得一共有几十个 tag,没法全都放在首页 index。
别的就是一些小事情,比如说为返回顶端按钮做了进度条,这也是我以前看别人的摩登网站都有的,以前不会写 js, 现在都让 chatGPT 写,所以也加上了。
做了一小点手机小屏幕适配,在小屏幕上把背景这根红的竖线去掉了,还把抬头上的站点简介去掉了,因为占地方。
还挑选了一个 favicon, 以前也有的,但是以前的文件路径和 vercel 用的不一样,所以一直显示不出来,我也就算了。这次挑选了一个新的,是这个 Origami icons created by juicy_fish,一个小纸船,和这个纸制品主题也相衬。
最后贴一下装修过程的 todo list,有几项懒得做了,包括把改好的样式再封装成一个主题放上 GitHub。可能以后会做,也可能继续拖着,等五年之后我们再换主题!
website todo
- back to top button,
- card layout for photo category,
- make a scotch tape like picture frame
- list page for status section
- Choose a handwriting font for the status section
- Port related articles shortcode from old theme
- Debug the related filter. should only show post section and only 3 related posts
- But not related though. It’s always showing the latest posts. Why?
- Make a window like frame for the status list on homepage
- Make the status section on the left of the homepage recent post
- Recent posts limit number
- Nav bar
- Use dictionary
- Port about me section from old theme
- Taxonomy. Tag display recently updated first
- Tag cloud
- Port friend blogroll shortcode
- Make a flex grid layout to space double or triple column content
- Port neodb shortcode
- Is loading all js and font and css making it slow? Minify?
- Package the theme
- Add a Button to Unhide the status
- Transfer content from old site
- Add the new site to GitHub repo
- Configure vercel after content transfer
- Sort tags from latest updated. Limit the number of tags displayed in homepage
- Change title font. can I crop only title letters to make .ttf file smaller? - checkout train one, bungee shade, allerta stencil, saira stencil one
- Subsetting font file
- Heiti bold not working (okay on safari)
- Dark mode background
- Polaroid grid layout
- Paginator for lists
- Twikoo comment component port from old theme
- obsidian front matter handles — —
- email to post to publish status
Continue Reading
- 2025 电子手帐设计 - 2024-12-06
- 一百篇博客了终于能插入图片 - 2024-12-03
- 游泳锻炼从咸鱼到泡发咸鱼 - 2024-11-04
Comments
This work is licensed under CC BY-NC-ND 4.0
Powered by hugo. Theme adapted from no style please.