惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Simon Willison's Weblog
Simon Willison's Weblog
P
Privacy International News Feed
www.infosecurity-magazine.com
www.infosecurity-magazine.com
T
Troy Hunt's Blog
Hacker News - Newest:
Hacker News - Newest: "LLM"
Attack and Defense Labs
Attack and Defense Labs
S
Secure Thoughts
V2EX - 技术
V2EX - 技术
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
O
OpenAI News
Cloudbric
Cloudbric
Google Online Security Blog
Google Online Security Blog
Schneier on Security
Schneier on Security
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
Help Net Security
Help Net Security
Cyberwarzone
Cyberwarzone
G
GRAHAM CLULEY
L
Lohrmann on Cybersecurity
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
Spread Privacy
Spread Privacy
NISL@THU
NISL@THU
N
News and Events Feed by Topic
T
Tenable Blog
S
Security @ Cisco Blogs
N
News and Events Feed by Topic
The Hacker News
The Hacker News
C
CXSECURITY Database RSS Feed - CXSecurity.com
宝玉的分享
宝玉的分享
月光博客
月光博客
酷 壳 – CoolShell
酷 壳 – CoolShell
美团技术团队
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
Google DeepMind News
Google DeepMind News
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
T
Tailwind CSS Blog
V
Visual Studio Blog
P
Proofpoint News Feed
Webroot Blog
Webroot Blog
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
博客园 - 三生石上(FineUI控件)
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
Jina AI
Jina AI
雷峰网
雷峰网
T
The Blog of Author Tim Ferriss
Hugging Face - Blog
Hugging Face - Blog
腾讯CDC
L
LangChain Blog
The Register - Security
The Register - Security
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
博客园 - 聂微东

Papermod on 老刘博客

暂无文章

给Hugo PaperMod主题添加一个漂亮又简洁的友情链接页面
老刘 · 2025-10-13 · via Papermod on 老刘博客

PaperMod 默认是极简风格,没有自带“友情链接(Friends / Links)”页,但是我们博主也不是互联网的孤岛,总有一些自己喜欢的左邻右舍,最简单的方法是用生成一个页面来作为友情链接页面,但是太丑了。老刘结合chatgpt,自己添加一个漂亮的友情链接页面,下面是 详细教程(以 Hugo + PaperMod 为例):

一、创建友情链接页面

在你的 Hugo 项目根目录执行:

1
hugo new friends/_index.md

这会在 content/friends/_index.md 生成文件。 打开该文件,修改为:

1
2
3
4
5
---
title: "友情链接"
layout: "friends"
summary: "那些值得一去的好地方"
---

( 注意: layout 是我们下一步要创建的模板文件名。)

二、创建页面模板

PaperMod 的页面模板位于:

1
themes/PaperMod/layouts/

但我们不直接改主题文件(避免主题升级覆盖),而是复制到你的项目中:

1
mkdir -p layouts/_default

然后创建一个新模板文件:

1
nano layouts/_default/friends.html

写入以下示例模板(简洁、与 PaperMod 风格一致):

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
{{ define "main" }}
<main class="main-content" id="main-content">
  <article class="post-single">
    <header class="post-header">
     

      <h1 class="post-title">{{ .Title }}</h1>
      {{ with .Params.summary }}
        <p class="post-description">{{ . }}</p>
      {{ end }}
    </header>
<style>
.friend-links {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 1.2rem;
  margin-top: 1.5rem;
}
.friend-card {
  display: flex;
  align-items: center;
  padding: 1rem;
  border-radius: 0.75rem;
  background: var(--entry);
  box-shadow: 0 1px 3px rgba(0,0,0,0.1);
  transition: all 0.25s ease;
}
.friend-card:hover {
  transform: translateY(-4px);
  box-shadow: 0 4px 10px rgba(0,0,0,0.15);
}
.friend-card img {
  width: 3rem;
  height: 3rem;
  border-radius: 9999px;
  margin-right: 1rem;
}
.friend-card .text-gray-600 {
  color: var(--secondary);
}
</style>

    <div class="post-content">
      {{ .Content }}

      <div class="friend-links grid grid-cols-1 sm:grid-cols-2 md:grid-cols-3 gap-4 mt-6">
        {{ range .Site.Data.friends }}
          <a href="{{ .url }}" target="_blank" rel="noopener" class="friend-card flex items-center p-4 rounded-xl shadow-sm hover:shadow-md transition">
            <img src="{{ .avatar }}" alt="{{ .name }}" class="w-12 h-12 rounded-full mr-4">
            <div>
              <div class="font-semibold">{{ .name }}</div>
              <div class="text-sm text-gray-600">{{ .desc }}</div>
            </div>
          </a>
        {{ end }}
      </div>
    </div>
  </article>
</main>
{{ end }}

三、创建数据文件(友情链接信息)

在项目根目录新建:

添加如下内容(你可以随意扩展):

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
- name: "PaperMod 官方"
  url: "https://github.com/adityatelange/hugo-PaperMod"
  avatar: "https://avatars.githubusercontent.com/u/21258296?v=4"
  desc: "简洁优雅的 Hugo 主题"

- name: "Hugo 官网"
  url: "https://gohugo.io/"
  avatar: "https://gohugo.io/images/hugo-logo-wide.svg"
  desc: "世界上最快的静态网站生成器"

- name: "老刘博客"
  url: "https://iliu.org/"
  avatar: "https://iliu.org/img/apple-touch-icon.png/"
  desc: "分享我的思考与生活"

四、将“友情链接”加入导航栏

打开 config.yml 或 config.toml(根据你使用的格式),找到菜单配置部分:

1
2
3
4
5
6
menu:
  main:
    - identifier: friends
      name: 友情链接
      url: /friends/
      weight: 30

五、重新生成并预览

打开浏览器访问:

1
http://localhost:1313/friends/

即可看到一个简洁、卡片式的友情链接页面,与 PaperMod 风格一致。 具体风格可以参考: 老刘博客

通过以上步骤,你就成功地为 Hugo PaperMod 主题添加了一个既美观又简洁的友情链接页面。这个页面不仅能增强你的站点互通性,还能提升用户体验。如果你喜欢,也可以根据自己的需求对样式和布局进行进一步的调整和优化。希望这篇文章对你有所帮助!