跳过正文
  1. Teches/
  2. 前端/
  3. Hugo/

词云实践流程

·130 字·1 分钟
目录

1. 通过deepseek生成词云html、js、css代码
#

</> prompt参考
1我在做hugo页面,帮我生成标签词云的代码,我会在首页index.html中导入,词云内容为tag,点击跳转对应url,每个tag样式为圆形,大小只和tag字符关联,无旋转,排序权值使用tag文章数量,权值越高越靠中间,分成html css js三个文件实现,tag在html中使用.Site.Taxonomies.tags生成
2让词云标签贴合,至少行对齐(居中、等分对齐),有一定的对齐的美感
</> 生成
1tag-cloud.html
2tag-cloud.css
3tag-cloud.js

2. tag-cloud绑定在baseURL/tags/url上
#

原理:

</> 路由机制
1Hugo 会自动将 layouts/taxonomy/tag.terms.html 映射到 /tags/ URL
2这是 Hugo 分类系统(Taxonomy)的标准行为

流程:

- 1. 创建layouts/taxonomy/tag.terms.html
#
- 2. 在tag.terms.html中直接调用tag-cloud.html
#
</> tag.terms.html
1{{ define "main" }}
2{{ partial "tag-cloud.html"  . }}
3{{ end }}
- 3. 导入css、js文件
#

为了方便,直接在tag-cloud.html中嵌入了css、js的导入(缺点,页面会动态加载js)

</> tag-cloud.html
1{{ $tagscss := resources.Get "css/tag-cloud.css" }} 
2<link rel="stylesheet" href="{{ $tagscss.RelPermalink }}"> 
3
4<!-- 原tag-cloud.html代码 -->
5
6{{ $jsProcess := resources.Get "js/tag-cloud.js" }} 
7<script type="text/javascript" src="{{ $jsProcess.RelPermalink }}" integrity="{{ $jsProcess.Data.Integrity }}"></script>

3. 在首页index.html中加入url链接按钮
#

由于Blowfish主页使用了partials/home/profile.html等代码嵌套,所以把主题代码拷贝到自定义layouts下,做自定义修改
在profile.html中的合适位置插入按钮代码

</> html
1{{ $css1 := resources.Get "css/TagCloudbtn.css" }}
2<link type="text/css" rel="stylesheet" href="{{ $css1.RelPermalink }}">
3{{ with .Site.GetPage "tags/" }}
4<a href="{{ .RelPermalink }}" class="go-tag-cloud-button">Tag Cloud</a>
5{{ end }}

同样为了方便,直接在html中嵌入了css/TagCloudbtn.css导入
css/TagCloudbtn.css定义了按钮go-tag-cloud-button样式